Dear Nina,
If you go ahead with Chris' suggestion of creating a configuration file,
you probably want to start with config/spm_cfg_realign.m as the
differences between spm_realign.m and inria_realign.m are minimal.
You might also be interested in this module in the batch interface:
BasicIO > Run > Call MATLAB function
It allows you to call any function and manually specify what the inputs
and outputs (dependencies) are. Here is for example a batch that calls
the image display:
clear matlabbatch
matlabbatch{1}.cfg_basicio.run_ops.call_matlab.inputs{1}.string = ...
'Display';
matlabbatch{1}.cfg_basicio.run_ops.call_matlab.inputs{2}.string = ...
fullfile(spm('Dir'),'canonical','single_subj_T1.nii');
matlabbatch{1}.cfg_basicio.run_ops.call_matlab.fun = @spm_image;
spm_jobman('run',matlabbatch);
(The second input should be of type nifti and not string but spm_image
is later confused if receiving a cellstr instead of a char array).
At last, all the BasicIO modules are defined in:
config/matlabbatch/cfg_basicio/
Best regards,
Guillaume.
On 06/10/16 09:03, Christophe Phillips wrote:
> Dear Nina,
>
> If you want to include your own tool into the batch system, you need to
> write a "config file" to call your processing routine, passing in and
> out the the required variables...
> This config file should
> - specify the input layout for the process: image file, parameters,
> options, etc.
> - include a 'run function' that will actually call your routine,
> extracting and passing the input from the 'jobs' structure created in
> the config part. Think of it as an interface.
> - include an 'output function' that collects (or builds) the output from
> your routine and make it visible to the batch system, i.e. allows
> dependencies.
> The the 'run function' (spm_run_*.m) sometimes appear as a separate file
> from the config file (spm_cfg_*.m). Best is to copy what already within
> SPM for "simple" spatial processing functions.
> I've done the exercise for a home-made tool, you can check it all here
> <https://github.com/CyclotronResearchCentre/spm_auto_reorient>. Note
> that my routine batch config is included in the main spm_cfg.m file on
> line 24. That's the only change made spm original code.
>
> HTH,
> Chris
>
> ===================================================
> Christophe Phillips, Ir, PhD
> FRS-FNRS. Senior Research Associate
> Adjunct assistant professor in applied sciences
>
> GIGA in silico medicine
> Cyclotron Research Centre, B30
> University of Liege, Sart Tilman
> 4000 Liege, Belgium
> Tel: +32 4 366 2316 (secr.)
> +32 4 366 2366
> Fax: +32 4 366 2946
> email: [log in to unmask]
> web: http://www.giga.ulg.ac.be/
> ===================================================
>
> Le 5/10/2016 à 18:56, Nina de Lacy a écrit :
>> Hi Guillaume:
>>
>> On a related note, I'm currently in the process of building automated
>> preprocessing scripts including a control script, data structure and
>> then a number of matlabbatch modules (e.g. temporal, realignment etc).
>> Like Bianca, my aim is to loop over many subjects with (mostly) a
>> single session of fMRI, not many sessions.
>>
>> I have spent a great deal of time wading through the documentation and
>> also the actual code for jobman and the batch system. I like the
>> ability to generate a single job from the Batch Editor to call with
>> control script and embed vars thru data structure, but I can't quite
>> get to grips with some of its features. I was wondering if you knew
>> the following:
>>
>> 1. Can I add a custom function to the Batch Editor? Specifically, I
>> have SPM12-compatible code for INRIAlign I would like to use as my
>> realignment module. The code is set up as a .m function file. Is there
>> a way to import it so I can use it within the Batch? I see a button
>> called "Add Application" but can't get it to 'see' my file...Other
>> ways to do this?
>>
>> This would really help me as then I could add dependencies via the
>> editor and not have to try and code up the substruct etc myself
>>
>> 2. Do you know what the various file/dir options in the Batch Editor
>> correspond to in terms of spm functions or where I can get their code
>> to look at them? I've done a bunch of trial and error but it would be
>> great to have a solid idea what these are built with.
>>
>> Example: I found (I think) that I needed Named File Selector in order
>> to be able to create a dependency for the Util Image Expansion to feed
>> 4D files into the slice time correction module --> couldn't seem to do
>> this with File Selector (Batch Mode) which seems to be more oriented
>> to pulling multiple sessions.
>>
>> Example: Does one of the file selectors in the batch editor actually
>> correspond to spm_select?
>>
>> Thanks very much
>>
>> Nina
>>
>>
>>
>> On Wed, 5 Oct 2016, Guillaume Flandin wrote:
>>
>>> Dear Bianca,
>>>
>>> What about something like this?
>>>
>>>
>>> data_path = 'C:\exp';
>>>
>>> mask = fullfile(data_path,'Maskl.nii');
>>> files = cellstr(spm_select('FPList',...
>>> fullfile(data_path,'Data'),'.*\.nii$'));
>>>
>>> clear matlabbatch
>>> for i=1:numel(files)
>>> matlabbatch{i}.spm.util.imcalc.input = {files{i};mask};
>>> matlabbatch{i}.spm.util.imcalc.outdir = ...
>>> {fullfile(data_path,'Masked')};
>>> matlabbatch{i}.spm.util.imcalc.output = ...
>>> spm_file(spm_file(files{i},'filename'),'prefix','Masked_');
>>> matlabbatch{i}.spm.util.imcalc.expression = 'i1.*i2';
>>> matlabbatch{i}.spm.util.imcalc.options.interp = 0;
>>> matlabbatch{i}.spm.util.imcalc.options.dtype = 16; % to adjust
>>> end
>>> spm_jobman('run',matlabbatch);
>>>
>>>
>>> It is very slow for what it's doing - a direct call to spm_mask should
>>> also get you there.
>>>
>>> Best regards,
>>> Guillaume.
>>>
>>>
>>> On 05/10/16 15:42, De Blasi, Bianca wrote:
>>>> Dear all,
>>>>
>>>>
>>>> I am trying to run some preprocessing steps for a set of PET images
>>>> (from different subjects) by developing a batch script from the SPM
>>>> gui.
>>>> I would like to confirm with you that what I am doing is correct.
>>>>
>>>>
>>>> Say I want to mask out every image by the same brain mask. I have done
>>>> the following:
>>>>
>>>> 1) Load SPM and the ImCalc gui. Fill all the fields with the
>>>> appropriate
>>>> options
>>>>
>>>> 2) Click File -> Save batch and scripts (which generates a .m file
>>>> and a
>>>> _job.m file)
>>>>
>>>> 3) *In the .m file I have set the number of runs to 1 and I have left
>>>> all the rest the same. In the _job.m file I have added a for loop which
>>>> selects one subject at a time (ie. the image to be masked changes at
>>>> each iteration and is selected from a folder). For each subject the
>>>> ImCalc processing is run (at least this is what I would like to
>>>> obtain).*
>>>>
>>>> *
>>>> *
>>>>
>>>> *here is how the _job.m file appears (note this is from SPM8):*
>>>>
>>>> "
>>>>
>>>> files2Mask = dir('Data\*.nii');
>>>>
>>>> for i = 1:length(files2Mask)
>>>> matlabbatch{i}.spm.util.imcalc.input = {
>>>> strcat('Data\',files2Mask(i).name,',1')
>>>> 'Maskl.nii,1'
>>>> };
>>>> matlabbatch{i}.spm.util.imcalc.output =
>>>> strcat('Masked_',files2Mask(i).name);
>>>> matlabbatch{i}.spm.util.imcalc.outdir = {'Masked'};
>>>> matlabbatch{i}.spm.util.imcalc.expression = 'i1.*i2';
>>>> matlabbatch{i}.spm.util.imcalc.options.dmtx = 0;
>>>> matlabbatch{i}.spm.util.imcalc.options.mask = 0;
>>>> matlabbatch{i}.spm.util.imcalc.options.interp = 1;
>>>> matlabbatch{i}.spm.util.imcalc.options.dtype = 4;
>>>>
>>>> end
>>>> "
>>>>
>>>> _
>>>> _
>>>>
>>>> Is this correct? My concern is that there is a for loop in the .m file
>>>> but I am not quite sure on how to use it and by reading the manual, it
>>>> seems that it is for a multisession analysis of the same subject, while
>>>> in my case I want to repeate the same processing (ie. masking or
>>>> normalisation..) for a set of subject stored in a folder.
>>>>
>>>>
>>>> Hope all this makes some sense,
>>>>
>>>> Could you please give some advice on whether this is correct?
>>>>
>>>>
>>>> Thank you very much in advanced,
>>>>
>>>> Bianca
>>>>
>>>
>>> --
>>> Guillaume Flandin, PhD
>>> Wellcome Trust Centre for Neuroimaging
>>> University College London
>>> 12 Queen Square
>>> London WC1N 3BG
>>>
>>
>> This message and any attached files might contain confidential
>> information protected by federal and state law. The information is
>> intended only for the use of the individual(s) or entities originally
>> named as addressees. The improper disclosure of such information may
>> be subject to civil or criminal penalties. If this message reached you
>> in error, please contact the sender and destroy this message.
>> Disclosing, copying, forwarding, or distributing the information by
>> unauthorized individuals or entities is strictly prohibited by law.
>>
>
--
Guillaume Flandin, PhD
Wellcome Trust Centre for Neuroimaging
University College London
12 Queen Square
London WC1N 3BG
|