CONN Programming Notes

Batch setup (forum)


Here is my conn batch script.

function batch = me2ConnSetup

topDir = '/PACS-PI0/PACS-PI0/lindquist/me2/data/bkraft/'
me2Index = [35, 37, 38, 39, 40];
nSubjects = length(me2Index);
nSessions = 2;
nConditions = 2;
%
% Define the name of the conn.mat file.
%
outputDir = fullfile(topDir, 'group');
batch.filename = fullfile(outputDir, 'conn_me2.mat');
%
% Preprocessing Data sets
%
batch.Setup.nsubjects = nSubjects; % Number of Subjects
batch.Setup.RT = 2; % Repitition Time
% Functional and structural data for Sessions 1 and 2
%
batch.Setup.conditions.names{1} = 'restec';
batch.Setup.conditions.names{2} = 'neutral';
for iiSubject=1:nSubjects
for iiConditions=1:nConditions
for iiSessions=1:nSessions
batch.Setup.conditions.onsets{iiConditions}{iiSubject}{iiSessions} = []; % Condition{nCondition}{nSubject}{nSessions}
batch.Setup.conditions.durations{iiConditions}{iiSubject}{iiSessions} = [];
end
end
end
% For resting state fMRI onset is 0 and duration is inf
for ii=1:nSessions
for iiSubject=1:nSubjects
batch.Setup.conditions.onsets{ii}{iiSubject}{ii} = 0; % Condition{nCondition}{nSubject}{nSessions}
batch.Setup.conditions.durations{ii}{iiSubject}{ii} = inf;
end
end
%
%
batch.Setup.subjects.effect_names{1} = 'subjectID';
batch.Setup.covariates.names{1} = 'motion';

% batch.Setup.covariates.names{2} = 'scrubbing';

for iiSubject=1:length(me2Index)
iiSubject

subjectDir = fullfile(topDir, sprintf('me%03d', me2Index(iiSubject)))
batch.Setup.structurals{iiSubject}{1} = fullfile(subjectDir, 'wcrT1w.nii');
batch.Setup.masks.Grey{iiSubject} = fullfile(subjectDir, 'wc1crT1w.nii');
batch.Setup.masks.White{iiSubject} = fullfile(subjectDir, 'wc2crT1w.nii');
batch.Setup.masks.CSF{iiSubject} = fullfile(subjectDir, 'wc3crT1w.nii');
batch.Setup.functionals{iiSubject}{1} = fullfile(subjectDir, 'swaurestec.nii');
batch.Setup.functionals{iiSubject}{2} = fullfile(subjectDir, 'swauneutral.nii');

batch.Setup.covariates.files{1}{iiSubject}{1} = fullfile(subjectDir, 'rp_restec.txt');
% batch.Setup.covariates.files{2}{iiSubject}{1} = fullfile(subjectDir, 'art_regression_outliers_waurestec.mat');

batch.Setup.covariates.files{1}{iiSubject}{2} = fullfile(subjectDir, 'rp_neutral.txt');
% batch.Setup.covariates.files{2}{iiSubject}{2} = fullfile(subjectDir, 'art_regression_outliers_wauneutral.mat');

batch.Setup.subjects.effects{1}(iiSubject) = me2Index(ii);
end

Batch and GUI (thread)

RE: Interaction between batch mode and the GUIHi Lline,

Yes, the CONN gui simply reflects the status of your current CONN project, so any changes that you affect in the GUI, or any batch commands that you run, will modify your project and those changes will be visible in the GUI (perhaps after refreshing the screen if you just run a batch command).

Unfortunately, there is no way to have CONN track your changes in the GUI and convert that to a script. The closest functionality is the 'save as script' option when running any of the Preprocessing/Setup/Denoising/first-level steps (this option appears in the window that pops up when you click on the 'Preprocessing' button or in any of the 'Done' buttons for the Setup/Denoising/first-level steps. This option creates a script (or several scripts if you want to run these on different machines in parallel) that will run the selected Preprocessing/Setup/Denoising/first-level steps with the options that you have chosen there in those GUIs, but these scripts are not easily readable/modifiable and they do not use standard conn_batch functionality.

Hope this helps
Alfonso 
Originally posted by Lline Cours:
Hello,

I am a new user of Conn. I'd like to use both the batch and GUI modes.
I'd like to know if there is a way to convert a selection of parameters made in the GUI into batch commands. From what I understand the opposite is possible: if I have the GUI open and run batch commands in matlab the changes will be made to the GUI, right ?
Thanks a lot !
Lline


reply reply with quote

Batch add ROI's (thread)

RE: preprocessing and adding ROIs in batchHi Ely,

If you only want to add new ROIs to an existing CONN project using batch commands you would do that using ONLY the following lines from your script:

clear batch;
batch.filename=fullfile(TARGETpath,'conn_DBSRew_ICAFIX_s3mm.mat');
batch.Setup.rois.names={'Hb_seg_bilat','Hb_seg_left','Hb_vol_right'}; % note: names of new ROIs ONLY here
batch.Setup.rois.add=1; 
for nsub=1:NSUBJECTS
 for nroi=1:3 
  batch.Setup.rois.files{nroi}{nsub}=ROI_FILE(nroi,nsub); % note: locations of new ROI files ONLY here
 end
end
conn_batch(batch);

That will simply add a new set of ROIs to your CONN project (just the same as if you had manually added those ROIs in the Setup.ROIs tab). You could then go to the GUI to double-check that the new ROIs are defined correctly if you want. If, in addition, you want CONN to re-run the Setup and Denoising steps now processing only the newly defined ROIs, then you would also add the following (added to the lines above, right before the conn_batch(batch) line):

batch.Setup.overwrite='No';
batch.Setup.done=1;
batch.Denoising.overwrite='No';
batch.Denoising.done=1;

That will also run the Setup/Denoising steps, just the same as if you had pressed 'Done' in the corresponding tabs and selected the "no-overwrite" option there. That is everything that is needed. Re-running everything else in your original script is not only no longer necessary but also harmful, because some of those lines are re-defining things in a way that is no longer appropriate. For example, the batch.Setup.structurals and batch.Setup.functionals lines are asking CONN to revert your functional/structural data to their raw/unprocessed versions, the batch.Setup.Preprocessing lines are asking CONN to repeat the entire preprocessing steps, the batch.Setup.covariates lines are asking CONN to re-define your first-level covariates disregarding any newly created ones (e.g. the ones created automatically during ART or realignment steps), etc.

Let me know if this makes sense and/or if you would like me to further clarify.
Best
Alfonso

Originally posted by Benjamin Ely:
Hi Alfonso,

I have a batch script (attached, adapted from your HCP example script) that ran well in my initial tests, and now I'd like to add some additional ROIs. I see from a previous thread (https://www.nitrc.org/forum/forum.php?th...) that there is an option for adding new ROIs in batch. However, when I added new ROIs to my list, set the flag batch.Setup.rois.add=1, and run the batch script, it begins rerunning some of my preprocessing steps (segmentation and ART-repair, though not smoothing). Preprocessing is fairly time/resource intensive and I plan to periodically add new ROIs and re-run this model, so I'd like to avoid this if possible. Commenting out the preprocessing options allows Setup to run to completion but causes other issues (the loaded functional images revert to the unsmoothed versions and the scrubbing first-level regressor disappears, causing the Denoising step to crash; the segmentation data still loads correctly). Is there a simple way to tell CONN to skip preprocessing but still load the preprocessing outputs when re-running (akin to setting the overwrite option to "No" for other steps)? I'm using version 17a.

Thank you!
-Ely



conn_batch(batch)