Hi Guillaume
I'm working on following your and Chris's hints here to embed the INRIAlign function in the batch system. I am using Chris's approach of creating a config file.
If I could tax your patience, I have a few more questions:
1. How should I best handle the function itself? Thinking the thing to do here is save my function as a separate run file in the spm12/config subdirectory as something like this:
spm_run_inria_align.m
Standing alongside my cfg file in the same subdirectory
spm_cfg_inria_realign.m
2. Could you help clarify for me the difference between cfg_entry and cfg_menu items? It looks like they pass data into the 'class' subroutines of jobman. It looks like cfg_entry is intended for numbers like integer entries whereas cfg_menu is intended for grabbing things like character strings. Correct?
I have to add two new flags:
Rho-func, which is a structure specifying the cost function with 7 options like quadratic and tukey
Cutoff, which is an extra parameter to Rho-func and is a number, with a default of 2.5
I'm thinking Rho-func needs a cfg_menu structure with rho_func.labels and rho_func.values from 1 to 7
Whereas cutoff is suited to a cfg_entry structure with cutoff_strtype = 'r' and cutoff.num = [1,1]
3. Remaining modification would be changing other code to make sure rest of spm_cfg_inria_realign.m picks up spm_run_inria_align.m and not spm_run_realign to do estimate, write etc?
Thanks so very much -- you've really been such a huge help with this
Nina
On Thu, 6 Oct 2016, Guillaume Flandin wrote:
> 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
>
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.
|