JiscMail Logo
Email discussion lists for the UK Education and Research communities

Help for SPM Archives


SPM Archives

SPM Archives


SPM@JISCMAIL.AC.UK


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

SPM Home

SPM Home

SPM  October 2016

SPM October 2016

Options

Subscribe or Unsubscribe

Subscribe or Unsubscribe

Log In

Log In

Get Password

Get Password

Subject:

Re: followup questions on using the batch editor/matlabbatch

From:

Guillaume Flandin <[log in to unmask]>

Reply-To:

Guillaume Flandin <[log in to unmask]>

Date:

Thu, 6 Oct 2016 17:52:51 +0100

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (252 lines)

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

Top of Message | Previous Page | Permalink

JiscMail Tools


RSS Feeds and Sharing


Advanced Options


Archives

May 2024
April 2024
March 2024
February 2024
January 2024
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
2006
2005
2004
2003
2002
2001
2000
1999
1998


JiscMail is a Jisc service.

View our service policies at https://www.jiscmail.ac.uk/policyandsecurity/ and Jisc's privacy policy at https://www.jisc.ac.uk/website/privacy-notice

For help and support help@jisc.ac.uk

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager