help > RE: conn_batch how to do all 1st-level analyses
Apr 25, 2016  07:04 PM | Alfonso Nieto-Castanon - Boston University
RE: conn_batch how to do all 1st-level analyses
Hi Stephen,

Your script looks perfectly fine (and you are right that DynamicFC analyses are not yet available through batch commands, so calling conn_process directly might be your best choice for batch processing those as well currently; I will try to have conn_batch functionality for DynamicFC added before the next CONN release). Regarding defining and running multiple first-level analyses using conn_batch functionality (seed-to-voxel, ROI-to-ROI, and/or voxel-to-voxel analyses), one alternative would be to simply define different CONN_x structures (one per analysis). For example (after you have run your initial conn_batch command, defining your experiment file and running Setup&Denoising steps) you could use something like:

clear batch;

batch{1}.filename = 'myconn_project.mat'; 
batch{1}.Analysis.analysis_number = 'MyFirstAnalysis'; 
batch{1}.Analysis.type = 3;               % ROI-to-ROI and seed-to-voxel measures
batch{1}.Analysis.sources = ...        % for seed-to-voxel or ROI-to-ROI analyses
... etc. ...
batch{1}.Analysis.done=1;
batch{1}.Analysis.overwrite=1;

batch{2}.filename = 'myconn_project.mat';
batch{2}.Analysis.analysis_number = 'MySecondAnalysis';
batch{2}.Analysis.type = 2;                 % only ROI-to-ROI measures
batch{2}.Analysis.sources = ...          % for seed-to-voxel or ROI-to-ROI analyses
... etc. ...
batch{2}.Analysis.done=1;
batch{2}.Analysis.overwrite=1;


batch{3}.filename = 'myconn_project.mat';
batch{3}.Analysis.measures = ...      % for voxel-to-voxel analyses
batch{3}.Analysis.done=1;
batch{3}.Analysis.overwrite=1;


conn_batch(batch);   % defines/runs the three analyses above

There are several advantages to using conn_batch functionality (when possible) vs. calling conn_process directly. Mainly conn_batch syntax is always going to be backwards compatible in future releases (so batch scripts created for the current version are expected to work without any modification in future releases; the same cannot be said of scripts that call conn_process directly or any of the other internal conn functions, where the specifics of the syntax and structure of these functions may change in future releases). Also you get the added benefit of all the additional conn_batch framework, such as being able to parallelize your processing pipeline simply by adding a couple of lines to your batch structure, running your analyses on a subset of subjects only, etc.

Hope this helps
Alfonso
Originally posted by Stephen L.:
I fixed both of my issues (not running all analyses + no way to conn_batch Dynamic FC analysis) by directly using conn_process.m, which is the script that is called to do all the heavy job.

So indeed, it seems that conn_batch can only run one type of 1st-level analysis: either Seed-to-Voxel/ROI-to-ROI or Voxel-to-Voxel. Not both, and no way to run Dynamic FC even if conn_batch should support it because of BATCH.Setup.analyses = 4.

So, what I do to workaround this limitation is basically to:

1. first run conn_batch like before, so that I get all the setup, denoising and one analysis steps done for me (and it's easier to fill BATCH-like struct than the CONN_x internal struct, conn_batch fills the gaps for me)
2. then I simply load CONN_x into the workspace and call conn_process() on it. Since I already filled CONN_x with everything needed to perform all analyses, I just have to run the missing analyses, thus I just need to call conn_process().

Practical example: before I had something like that:

% SETUP
conn_file = 'my_conn_project.mat';
CONN_x.filename = conn_file;
CONN_x.Setup.isnew = 1;
CONN_x.Analysis.measures = conn_v2v('measurenames'); % load all available kind of measures and force Voxel-to-Voxel analysis
% ... lots of other CONN_x assignments...
% Automatic batch processing of all steps
CONN_x.Setup.done = 1;
CONN_x.Denoising.done = 1;
CONN_x.Analysis.done = 1;
CONN_x.Results.done = 1;
% Running the batch
conn_batch(CONN_x);
% Open batch in GUI
clear CONN_x data;
conn;
conn('load', conn_file); % Load the parameters/results
conn gui_setup; % refresh the GUI after loading the file


Now, I have the same thing, but before opening the batch in GUI I run additional analyses:

% ... all the code above ...

% Running the batch
conn_batch(CONN_x);

% Running missing analyses
% First: load the CONN_x batch struct, conn_process will access it as a global.
clear CONN_x;
load(conn_file); % will load var CONN_x into workspace
global CONN_x;
CONN_x.gui.overwrite = 'Yes' % avoid CONN GUI asking us what to do, overwrite files directly
% Compute Seed-to-Voxel 1st-level analysis
conn_process('analyses_seed');
% Compute ROI-to-ROI 1st-level analysis
conn_process('analyses_seedandroi');
% Compute Dynamic FC (functional connectivity) 1st-level analysis
if inter_or_intra == 1 % CONN v16a cannot yet do inter subjects (across independent conditions/groups) dynamic FC, it can only work on intra-subject project over multiple sessions
conn_process('analyses_dyn');
elseif inter_or_intra == 0
fprintf('Skipping Dynamic FC: CONN does not yet support inter-subjects project (works on multiple sessions but not multiple independent subjects groups/conditions).\n');
end
% Save the new struct and results!
if isfield(CONN_x,'filename'), conn save; end;

% Open batch in GUI
clear CONN_x data;
conn;
conn('load', conn_file); % Load the parameters/results
conn gui_setup; % refresh the GUI after loading the file

The full script I use can be found on my github (under MIT license, feel free to use/remix it):
github dot com/lrq3000/neuro_experiments_tools/blob/master/matlab/conn_subjects_loader/conn_subjects_loader.m

Threaded View

TitleAuthorDate
Stephen L. Apr 22, 2016
Stephen L. Apr 22, 2016
RE: conn_batch how to do all 1st-level analyses
Alfonso Nieto-Castanon Apr 25, 2016
Stephen L. Apr 26, 2016
Stephen L. Apr 22, 2016
Stephen L. Apr 22, 2016