What could be the cause of my SPM CAT12 preprocessing errors?

I’m relatively new to SPM and related tools, and run into some issues running CAT12 segmentation in batches.

Individual subjects through the GUI works fine, but when we submit a script to process several subjects, several issues arise:

  1. issue 1:
    MATLAB:sizeDimensionsMustMatch
    Arrays have incompatible sizes for this operation.

Which arrays is it referring to here? How can I check and correct?

  1. issue 2:
    MATLAB:UndefinedFunction
    Unrecognized function or variable “VI”.

Which variable are they referring to?

  1. issue 3:
    Error reading header file

For some of these issues, some output is still produced, but we struggle to distinguish when a subject has run succesfully. For issue 3, the complete output is not produced.

We run a bash submission script on a slurm cluster that calls a matlab script for the CAT12 segmentation:

Bash script:

#!/bin/bash

#SBATCH --job-name=segmentations_ahead
#SBATCH --mem=4G
#SBATCH --partition=luna-cpu-short
#SBATCH --qos=anw-cpu
#SBATCH --cpus-per-task=4
#SBATCH --time=00-03:00:00
#SBATCH --nice=2000
#SBATCH --array=1-3%3
#SBATCH --output=slurm-%A.%a.out

# Load Matlab module
module load matlab/R2021b
export MATLABPATH=path/to/cat12

inputdir=path/to/input

cd ${inputdir}

ls -d sub-*/ | sed 's:/.*::' > subjects.txt

subjects=${inputdir}/subjects.txt
subj=$(sed -n "${SLURM_ARRAY_TASK_ID}p" ${subjects})
# random delay
duration=$((RANDOM % 20 + 2))
echo -e "${YELLOW}INITIALIZING...(wait a sec)${NC}"
echo
sleep ${duration}


matlab -nodisplay -batch "AHEAD_segmentation $inputdir $subj"

Matlab script:

function AHEAD_segmentation(inputdir,subj)

% Define paths
addpath('path/to/spm12');

% Get a list of all subject directories
%subjects = dir(fullfile(input_dir, 'sub-*'));

% Loop over each subject
%for i = 1:length(subjects)
    % Define the subject's anat directory within ses-1

    subj_dir = fullfile(inputdir, subj, 'ses-1', 'anat');
 %   t1_image_gz = fullfile(subj_dir, [subj '_ses-1_acq-wb_mod-t1w_orient-std_brain.nii.gz']);
      t1_image = fullfile(subj_dir, [subj '_ses-1_acq-wb_mod-t1w_orient-std_brain.nii']);

      % Show file path
    disp(['Checking: ', t1_image]);

    % Check if file exists
    if exist(t1_image, 'file') ~= 2
        fprintf('Warning: File %s not found!n', t1_image);
        error('no T1 file'); % Skip to next subject if T1 is missing
    end

    % Check if the gzipped T1 image exists
    if ~isfile(t1_image)
        fprintf('T1 image not found for subject %sn', subj);
    end

    % Print status
    fprintf('Processing subject %sn', subj);

    % Set up CAT12 batch job for segmentation
    matlabbatch{1}.spm.tools.cat.estwrite.data = {t1_image};
    matlabbatch{1}.spm.tools.cat.estwrite.nproc = 1;          
    %matlabbatch{1}.spm.tools.cat.estwrite.opts.tpm = {fullfile(spm('path/to/spm12'), 'tpm', 'TPM.nii')}; % Path to SPM's TPM file
    
    spm_dir = spm('dir');  

    % Path to TPM file
    tpm_file = fullfile(spm_dir, 'tpm', 'TPM.nii');

    % Check if the file exists
    if ~exist(tpm_file, 'file')
        error('TPM file not found: %s', tpm_file);
    end

    matlabbatch{1}.spm.tools.cat.estwrite.opts.tpm = {tpm_file};

    % select modality for SPM
    matlabbatch{1}.spm.tools.cat.estwrite.opts.modality = 'T1';  

    % Output options for volume-based analysis
    matlabbatch{1}.spm.tools.cat.estwrite.output.surface = 1; % Disable surface-based outputs
    matlabbatch{1}.spm.tools.cat.estwrite.output.GM.native = 1;   % Output native gray matter volume
    matlabbatch{1}.spm.tools.cat.estwrite.output.WM.native = 1;   % Output native white matter volume
    matlabbatch{1}.spm.tools.cat.estwrite.output.CSF.native = 1;  % Output native CSF volume
    matlabbatch{1}.spm.tools.cat.estwrite.output.GM.warped = 0;   % Output normalized gray matter volume (in MNI space)
    matlabbatch{1}.spm.tools.cat.estwrite.output.WM.warped = 0;   % Output normalized white matter volume (in MNI space)
    matlabbatch{1}.spm.tools.cat.estwrite.output.CSF.warped = 0;  % Output normalized CSF volume (in MNI space)
    matlabbatch{1}.spm.tools.cat.estwrite.output.GM.mod = 0;      % Output modulated gray matter volume (useful for VBM)
    matlabbatch{1}.spm.tools.cat.estwrite.output.WM.mod = 0;      % Output modulated white matter volume
    matlabbatch{1}.spm.tools.cat.estwrite.output.warps = [1 1];   % Save forward and inverse deformation fields

    % Run the CAT12 segmentation
  %  spm('defaults', 'FMRI');
  %  spm_jobman('initcfg');
    spm_jobman('run', matlabbatch);

Any thoughts on how to tackle any of these three issues (or links to similar issues/documentation/FAQ) would be greatly appreciated!

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật