help > Running denoising with already preprocessed files
Jul 14, 2021  08:07 AM | Andreas Voldstad - University of Oslo and LMU of Munich
Running denoising with already preprocessed files
Dear experts,

I am trying to script a CONN batch with files I have already preprocessed in SPM. I have searched the forum and batch guide for similar issues and have so far found it helpful.

I have an issue with running denoising and running the batch from MATLAB.

1) I have one session per subject containing three conditions and an implicit rest condition.
Do I need to explicitly specify the rest periods, and may that account for the difficulty I am describing below?


2) I used the batch script for Setup, and I then try to run denosing in the GUI. However, I encounter the error:

Not ready to start Denoising step
Please complete the Setup step first
(fill any required information and press "Done" in the Setup tab)

The only thing I can see not filled out in Setup is the "Condition Definition" field for each condition.
Can this be the issue, and how do I script this to be "Specificed blocks/events within the selected sessions?
I cannot find this in the batch guide.

Otherwise, Setup looks complete with all files accounted for.

3) I tried running the batch from MATLAB, and encountered some issues:
First the preprocessing GUI pops up and CONN prompts me to select a pipeline or an individual preprocessing step.
I click "cancel" because I am not running preprocessing, and "cancel" again on the empty pipeline.

Then CONN prints this error:

CONN: RUNNING ANALYSIS STEP (seed-to-voxel and roi-to-roi analyses)

Step 1/4: Checking/Updating S2V/R2R Analysis variables
Error using conn_process (line 2019)
Some conditions have not been processed yet. Re-run previous step
Error in conn_process (line 41)
case 'analyses_seedandroi', conn_disp(['CONN: RUNNING ANALYSIS STEP (seed-to-voxel and
roi-to-roi analyses)']); conn_process([9.1,10,11,15],varargin{:});
Error in conn_batch (line 1427)
else conn_process('Analyses_seedandroi',batch.Analysis.analysis_number);
Error in connscript (line 172)
conn_batch(batch);


4) My script:
%% Set up basics
%% Group_01: four of 21 subs excluded
conndir = '\\lagringshotell\sv-psi\Nevro\Prosjekt\Tor\Polyrythm\andreas\conn_project';
jobdir = '\\lagringshotell\sv-psi\Nevro\Prosjekt\Tor\Polyrythm\andreas\jobs';
Group01onsetdir = '\\lagringshotell\sv-psi\Nevro\Prosjekt\Tor\Polyrythm\andreas\behave\Group_01';
onsetdir= Group01onsetdir;
Group01fmridir = '\\lagringshotell\sv-psi\Nevro\Prosjekt\Tor\Polyrythm\andreas\fmri\fresh\Group_01';
fmridir = Group01fmridir;

cd(fmridir)
NSUBJECTS = 17;
nsessions= 1;
TR = 2;
% Func files, struct files and segmentations:
ORIGINALS_FILE = cellstr(spm_select('FPListRec',Group01fmridir,'^sub.*task-poly_bold.nii'));
FUNCTIONAL_FILE = cellstr(spm_select('FPListRec',Group01fmridir,'^wusub.*task-poly_bold.nii'));
SMOOTHED_FILE = cellstr(spm_select('FPListRec',Group01fmridir,'^s08wusub.*task-poly_bold.nii'));
STRUCTURAL_FILE = cellstr(spm_select('FPListRec',Group01fmridir,'^wm.*_T1w.nii'));
GREY_FILE = cellstr(spm_select('FPListRec',Group01fmridir,'^m0wp1.*_T1w.nii'));
WHITE_FILE = cellstr(spm_select('FPListRec',Group01fmridir,'^m0wp2.*_T1w.nii'));
CSF_FILE = cellstr(spm_select('FPListRec',Group01fmridir,'^m0wp3.*_T1w.nii'));
%
% if rem(length(FUNCTIONAL_FILE),NSUBJECTS),error('mismatch number of functional files %n', length(FUNCTIONAL_FILE));end
% if rem(length(ORIGINALS_FILE),NSUBJECTS),error('mismatch number of original functional files %n', length(ORIGINALS_FILE));end
% if rem(length(STRUCTURAL_FILE),NSUBJECTS),error('mismatch number of anatomical files %n', length(STRUCTURAL_FILE));end
% if rem(length(GREY_FILE),NSUBJECTS),error('mismatch number of greymatter files %n', length(GREY_FILE));end
% if rem(length(WHITE_FILE),NSUBJECTS),error('mismatch number of whitematter files %n', length(WHITE_FILE));end
% if rem(length(CSF_FILE),NSUBJECTS),error('mismatch number of csf files %n', length(CSF_FILE));end
%
% disp([num2str(size(FUNCTIONAL_FILE,1)),' subjects']);
% disp([num2str(size(FUNCTIONAL_FILE,2)),' sessions per subject']);
% disp([num2str(TR),' seconds TR']);
%% CONN-SPECIFIC SECTION: RUNS PREPROCESSING/SETUP/DENOISING/ANALYSIS STEPS
%% Prepares batch structure
clear batch;
batch.filename= fullfile(conndir, 'Conn_Poly1_project.mat'); % New conn_*.mat experiment name
%% SETUP & PREPROCESSING step (using default values for most parameters, see help conn_batch to define non-default values)
batch.Setup.isnew=1; % new project
batch.Setup.nsubjects=NSUBJECTS;
batch.Setup.RT=TR; % TR (seconds)
%% Point to functional and structural volumes for each subject/session:
batch.Setup.structurals=STRUCTURAL_FILE; % Point to anatomical volumes for each subject
% batch.Setup.functionals = FUNCTIONAL_FILE; % only one session, so could this work?
batch.Setup.covariates.names{1} = ('Movement');
batch.Setup.secondarydatasets{1}.functionals_label = 'Unsmoothed volumes';
batch.Setup.secondarydatasets{1}.functionals_type = 4; % otjher, explicit
batch.Setup.secondarydatasets{2}.functionals_label = 'Smoothed volumes';
batch.Setup.secondarydatasets{2}.functionals_type = 4; % otjher, explicit
%% Preprocessing
batch.Setup.preprocessing.label = 'functional_label_as_smoothed';
batch.Setup.preprocessing.steps = [];
batch.Setup.done=0; % 0 defines fields, 1 runs preprocessing
batch.Setup.overwrite = 0; % skips preprocessing?
for nsub=1:NSUBJECTS
%% functionals
% nsub, nses
%% Primary dataset: not preprocessed:
batch.Setup.functionals{nsub}{1}=ORIGINALS_FILE{nsub};
%% Secondary dataset 1: normalized, unsmoothed:
batch.Setup.secondarydatasets{1}.functionals_explicit{nsub}{1}=FUNCTIONAL_FILE{nsub};
%% Secondary dataset 2: smoothed volumes
batch.Setup.secondarydatasets{2}.functionals_explicit{nsub}{1} = SMOOTHED_FILE{nsub};
%% path to motion params
[funcpathdir,~,~] = fileparts(batch.Setup.functionals{nsub}{1});
%% Covariates: motion params
% ncov, nsub, nses
batch.Setup.covariates.files{1}{nsub}{1} = spm_select('FPListRec',funcpathdir,'^rp.*.txt');
%% segments
batch.Setup.masks.Grey{nsub} = GREY_FILE{nsub};
batch.Setup.masks.White{nsub} = WHITE_FILE{nsub};
batch.Setup.masks.CSF{nsub} = CSF_FILE{nsub};
end
%% Conditions
nconditions = 4;
batch.Setup.conditions.names={'Count_in';'Stable';'Poly';'Trans'}';
% order in Complex .mat single subject files: Count, Stable, Poly, trans, eventchange.
cd(onsetdir)
behavdirs = dir('Poly*');
for nsub=1:NSUBJECTS % 17 subs
nses=1; % only one session
cd(fullfile(onsetdir, behavdirs(nsub).name))
complex = dir('Complex*'); % dir function supports wildcards
load(complex.name)
% Count in: 1
batch.Setup.conditions.onsets{1}{nsub}{nses} = onsets{1};
batch.Setup.conditions.durations{1}{nsub}{nses} = durations{1};
% Stable: 2
batch.Setup.conditions.onsets{2}{nsub}{nses} = onsets{2};
batch.Setup.conditions.durations{2}{nsub}{nses} = durations{2};
% Poly: 3
batch.Setup.conditions.onsets{3}{nsub}{nses} = onsets{3};
batch.Setup.conditions.durations{3}{nsub}{nses} = durations{3};
% Trans: 4
batch.Setup.conditions.onsets{4}{nsub}{nses} = onsets{4};
batch.Setup.conditions.durations{4}{nsub}{nses} = durations{4};
end % subs
%% DENOISING step
batch.Denoising.filter=[0.01, 0.1];
batch.Denoising.done=0;
batch.Denoising.overwrite=1;
%% FIRST-LEVEL ANALYSIS step
batch.Analysis.done=1;
batch.Analysis.type = 1; % select only roi to roi
batch.Analysis.overwrite='Yes';
%% Save updated conn batch
cd(conndir)
save('conn_Poly1_project.mat', 'batch')
%% run batch
conn_batch(batch);


Best,

Andreas

Threaded View

TitleAuthorDate
Running denoising with already preprocessed files
Andreas Voldstad Jul 14, 2021
Andreas Voldstad Jul 14, 2021