help > Conn scripting preprocessing and denoising steps
Sep 27, 2024  09:09 PM | Mihir Walvekar
Conn scripting preprocessing and denoising steps

Hi,


I am working on a script for preprocessing and denoising. I had a few questions which I wanted to get checked before I ran it for all the subjects. 
Are the default ROI's that are present in the GUI already setup in the script when I do batch.Setup.rois.names? I need to add extra custom ROI's as well.
During Denoising how do I make sure to include GSR Global Signal Regression and not do Scrubbing in the script? I was not able to find any information about it online. 


Here is my script. 


'''


% Initialize CONN batch structure
clear batch;
baseDir = '/data/mgh-meditation/mihir/converted'; % Base directory for your project
batch.filename = fullfile(baseDir, 'conn_project.mat'); % Specify project file
% Subject info
batch.Setup.nsubjects = 1; % Set number of subjects (for now, 1)
batch.Setup.RT = 2.9; % Set repetition time
% Get a list of subject folders
subjectFolders = dir(fullfile(baseDir, 'sub-*'));
subjectFolders = subjectFolders([subjectFolders.isdir]); % Filter only directories
% Loop through each subject (in this case, only the first subject)
for sub = 1:1
    subjectDir = fullfile(baseDir, subjectFolders(sub).name);
    subjectID = subjectFolders(sub).name; % Extract the subject ID, e.g., sub-003
    % Initialize cell arrays for functional files
    funcFiles = {};
    
    % Locate the structural file (anatomical) in anat folder (no session folder here)
    structFile = fullfile(subjectDir, 'anat', [subjectID '_T1w.nii']); % Anatomical file
    
    % Get a list of session folders inside the afni-output folder
    afniOutputDir = fullfile(subjectDir, 'afni-output');
    sessionFolders = dir(fullfile(afniOutputDir, 'ses-*'));
    sessionFolders = sessionFolders([sessionFolders.isdir]); % Filter only directories
    
    for sess = 1:length(sessionFolders)
        sessionDir = fullfile(afniOutputDir, sessionFolders(sess).name);
        sessionID = sessionFolders(sess).name; % Extract session ID, e.g., ses-01
        
        % Get all 'jhana' runs in this session
        runFiles = dir(fullfile(sessionDir, ['pb01.' subjectID '_' sessionID '_task-jhana_run-*.despike.nii.gz']));
        
        for run = 1:length(runFiles)
            funcFile = fullfile(runFiles(run).folder, runFiles(run).name);
            
            % Add the functional file to the list
            funcFiles{end+1} = funcFile; % Append the run file for this session
        end
    end
    
    % Add functional and structural files to the batch
    batch.Setup.functionals{sub} = funcFiles; % All runs for this subject
    batch.Setup.structurals{sub} = structFile; % Structural file (no session folder)
end


% ROIS
batch.Setup.rois.names = {'default'};
batch.Setup.rois.files = {fullfile(conn('rois'),'atlas.nii'), ...    % Default atlas
                          fullfile(conn('rois'),'cerebellum.nii')};  % Default cerebellum ROI
%Custom roi's
batch.Setup.rois.names = [batch.Setup.rois.names, {'atlas_desikan_killiany', 'Desikan_space-MNI152NLin6_res-1x1x1', 'MDTB10-cerebellum', ...
                                                   'Schaefer2018_400Parcels_7Networks_order_FSLMNI152_2mm', 'Schaefer2018_400Parcels_17Networks_order_FSLMNI152_2mm', 'Tian_Subcortex_S4_7T'}];
batch.Setup.rois.files = [batch.Setup.rois.files, ...
                          {'/data/mgh-mediation/mihir/atlas/atlas_desikan_killiany.nii', ...
                           '/data/mgh-mediation/mihir/atlas/Desikan_space-MNI152NLin6_res-1x1x1.nii', ...
                           '/data/mgh-mediation/mihir/atlas/MDTB10-cerebellum.nii', ...
                           '/data/mgh-mediation/mihir/atlas/Schaefer2018_400Parcels_7Networks_order_FSLMNI152_2mm.nii', ...
                           '/data/mgh-mediation/mihir/atlas/Schaefer2018_400Parcels_17Networks_order_FSLMNI152_2mm.nii', ...
                           '/data/mgh-mediation/mihir/atlas/Tian_Subcortex_S4_7T'}];
% Preprocessing steps (custom pipeline)
batch.Preprocessing.steps = {'functional_label_as_original'...
                             'functional_centerruns'...
                             'functional_realign', ...
                             'functional_label_as_realigned', ...
                             'functional_art', ...
                             'functional_segment&normalize_direct'...
                             'functional_label_mnispace',...
                             'structural_label_as_original'...
                             'structural_center'...
                             'structural_segment&normalize'...
                             'structual_label_as_mnispace'...
                             'functional_smooth'...
                             'functional_label_as_smoothed'};
% Set smoothing kernel to 2mm
batch.Preprocessing.fwhm = 2;
%%%%% DENOISING
batch.Denoising.done = 1;
batch.Denoising.filter = [0.01 0.1];
batch.Denoising.despiking = 2;
batch.Denoising.regbp = 1;
% Now, run the batch processing
conn_batch(batch);
% Print success message
disp('Batch script executed successfully with custom ROI, preprocessing pipeline and denoising');


'''