help > Multiple functional files per subject on batch script
Showing 1-2 of 2 posts
Display:
Results per page:
Mar 21, 2019  04:03 AM | Emiliana Tonini
Multiple functional files per subject on batch script
Dear all, 

I'm trying to script a conn batch to preprocess data with the following characteristics :
214 subjects
134 functional files (.nii) per subject
1 structural file per subject
1 session per subject


I am wondering if it is possible to load all the functional files (134) via command line, or if only one functional file per subject is expected.


Here's a portion of my script for only 2 subjects:

DATApath=pwd;
nsubjects=2;
clear FUNCTIONAL_FILE* STRUCTURAL_FILE*;
subs=dir(regexprep(DATApath,'%s.*$','*'));
subs=subs([subs.isdir]>0);
subs={subs.name};
subs=subs(cellfun(@(s)all(s>='0'&s<='9'),subs));
if isempty(nsubjects), nsubjects=numel(subs);
else subs=subs(1:nsubjects);
end

for n=1:numel(subs)
fprintf('Locating subject %s files\n',subs{n});

% files=conn_dir(fullfile(cwd,SubjectFolder{nsub},SessionSubFolder{nses},'functional*.img')); <- this is the structure I'm following

t1=conn_dir(fullfile(DATApath,subs{n},'structural','structural*.nii'));
f1=conn_dir(fullfile(DATApath,subs{n},'emotion','emotion*.nii')); % here's where I get an error saying "Pathname is too long"
if isempty(dir(t1)), error('file %s not found',t1); end
if isempty(dir(f1)), error('file %s not found',f1); end

STRUCTURAL_FILE{n,1}=t1;
FUNCTIONAL_FILE{n,1}=f1;
end

nsessions=1;
fprintf('%d subjects, %d sessions\n', nsubjects, nsessions);

{...}

clear batch;
batch.filename=fullfile(TARGETpath, 'conn_emotion.mat');

batch.Setup.functionals=repmat({{}},[nsubjects,1]); % Point to functional volumes for each subject/session
for nsub=1:nsubjects,for nses=1:nsessions, batch.Setup.functionals{nsub}{nses}{1}=FUNCTIONAL_FILE{nsub,nses}; end; end;

batch.Setup.structurals=STRUCTURAL_FILE; % Point to anatomical volumes for each subject

{...}

Thank you very much!
Emiliana
Mar 21, 2019  05:03 PM | Alfonso Nieto-Castanon - Boston University
RE: Multiple functional files per subject on batch script
Hi Emiliana,

Your script looks perfectly fine and that is exactly how you enter multiple 3d volumes using batch commands, simply entering for each subject/session a char array with multiple lines, one line per file, like the one you are creating in your f1 variable. My impression is that the "pathname is too long" error message might be somewhat unrelated, perhaps caused by a closed loop of soft-linked directories within the target folder or something along those lines. If you could please copy/paste the entire error message perhaps that will help better figure out what might be the issue here.

Best
Alfonso
 
Originally posted by Emiliana Tonini:
Dear all, 

I'm trying to script a conn batch to preprocess data with the following characteristics :
214 subjects
134 functional files (.nii) per subject
1 structural file per subject
1 session per subject


I am wondering if it is possible to load all the functional files (134) via command line, or if only one functional file per subject is expected.


Here's a portion of my script for only 2 subjects:

DATApath=pwd;
nsubjects=2;
clear FUNCTIONAL_FILE* STRUCTURAL_FILE*;
subs=dir(regexprep(DATApath,'%s.*$','*'));
subs=subs([subs.isdir]>0);
subs={subs.name};
subs=subs(cellfun(@(s)all(s>='0'&s<='9'),subs));
if isempty(nsubjects), nsubjects=numel(subs);
else subs=subs(1:nsubjects);
end

for n=1:numel(subs)
fprintf('Locating subject %s files\n',subs{n});

% files=conn_dir(fullfile(cwd,SubjectFolder{nsub},SessionSubFolder{nses},'functional*.img')); <- this is the structure I'm following

t1=conn_dir(fullfile(DATApath,subs{n},'structural','structural*.nii'));
f1=conn_dir(fullfile(DATApath,subs{n},'emotion','emotion*.nii')); % here's where I get an error saying "Pathname is too long"
if isempty(dir(t1)), error('file %s not found',t1); end
if isempty(dir(f1)), error('file %s not found',f1); end

STRUCTURAL_FILE{n,1}=t1;
FUNCTIONAL_FILE{n,1}=f1;
end

nsessions=1;
fprintf('%d subjects, %d sessions\n', nsubjects, nsessions);

{...}

clear batch;
batch.filename=fullfile(TARGETpath, 'conn_emotion.mat');

batch.Setup.functionals=repmat({{}},[nsubjects,1]); % Point to functional volumes for each subject/session
for nsub=1:nsubjects,for nses=1:nsessions, batch.Setup.functionals{nsub}{nses}{1}=FUNCTIONAL_FILE{nsub,nses}; end; end;

batch.Setup.structurals=STRUCTURAL_FILE; % Point to anatomical volumes for each subject

{...}

Thank you very much!
Emiliana