By Sourav Singh
-Michio Kaku
Outer Level Data Flow in NeuroImaging
Too many options to choose from....
Taken from Making data sharing work: The FCP/INDI experience by Marten Mennes,Bharat P Biswal,F. Xavier Castellanos and Michael P. Milham
Neuroscientist-
Developer-
How do we:
Plugins:Component that describes how the workflow should be executed.
Installing Nipype:
Running Nipype:
Input of the Workflow will be a fMRI scan done and output will be the final fMRI scan after processing.
Step 1:Import Necessary Modules
from os.path import join as opj
from nipype.interfaces.afni import Despike
from nipype.interfaces.freesurfer import (BBRegister, ApplyVolTransform,
Binarize, MRIConvert, FSCommand)
from nipype.interfaces.spm import (SliceTiming, Realign, Smooth, Level1Design,
EstimateModel, EstimateContrast)
from nipype.interfaces.utility import Function, IdentityInterface
from nipype.interfaces.io import FreeSurferSource, SelectFiles, DataSink
from nipype.algorithms.rapidart import ArtifactDetect
from nipype.algorithms.misc import TSNR
from nipype.algorithms.modelgen import SpecifySPMModel
from nipype.pipeline.engine import Workflow, Node, MapNode
Import locations to your MATLAB and Freesurfer
from nipype.interfaces.matlab import MatlabCommand
MatlabCommand.set_default_paths('/usr/local/MATLAB/R2015b/toolbox/spm12')
MatlabCommand.set_default_matlab_cmd("matlab -nodesktop -nosplash")
fs_dir = '~/nipype_tutorial/freesurfer'
FSCommand.set_default_subjects_dir(fs_dir)
Define parameters-
experiment_dir = '~/nipype_tutorial' # location of experiment folder
output_dir = 'output_fMRI_example_1st' # name of 1st-level output folder
working_dir = 'workingdir_fMRI_example_1st' # name of 1st-level working directory
number_of_slices = 40 # number of slices in volume
TR = 2.0 # time repetition of volume
fwhm_size = 6 # size
# Slicetiming - correct for slice wise acquisition
interleaved_order = range(1,number_of_slices+1,2) + range(2,number_of_slices+1,2)
sliceTiming = Node(SliceTiming(num_slices=number_of_slices,
time_repetition=TR,
time_acquisition=TR-TR/number_of_slices,
slice_order=interleaved_order,
ref_slice=2),name="sliceTiming")
# Realign - correct for motion and other head bobs
realign = Node(Realign(register_to_mean=True),name="realign")
# Smooth - to smooth the images with a given kernel
smooth=pe.Node(interface=fs.smooth(),name="Smooth")
smooth.inputs.surface_fwhm=4
#smooth.inputs.surface_fwhm=8
#smooth.iterables('surface_fwhm',[4,6,8]) to run a subgraph several times.In this case,3 times for different attributes
#BBRegister - coregister a volume to the Freesurfer anatomical surface
bbregister = Node(BBRegister(init='header',contrast_type='t2',out_fsl_file=True),name='bbregister')
#Seed and connect two nodes together
extract_timeseries=pe.Node(afni.Maskave(),name="extract_timeseries")
correlation_map=pe.Node(afni.Fim(),name="correlation_map")
wf_connect(extract_timeseries,"out_file",correlation_map,"in_file")
#Normalize
normalize=pe.Node(interface=spm.Normalize(),name="Normalize")
#Create a workflow
workflow=pe.Workflow(name="first_level_analysis")
#Connect the different nodes in a single workflow together
workflow.connect(realign,"mean_image",coregister,"source")
workflow.connect(smooth,"source",BBregister,"register")
# Level1Design - Generate a design matrix
level1design = Node(Level1Design(bases={'hrf': {'derivs': [0, 0]}},timing_units='secs',interscan_interval=LA,model_serial_correlations='AR(1)'),name="lLevel1design")
# EstimateContrast - estimates contrasts based on general linear model
conestimate = Node(EstimateContrast(), name="conestimate")
# Volume Transformation - transform contrasts into anatomical space
applyVolReg = MapNode(ApplyVolTransform(fs_target=True),name='applyvolReg',iterfield=['source_file'])
# MRIConvert - to generate and zip the output files
mriconvert = MapNode(MRIConvert(out_type='nii.gz'),name='mriconvert',iterfield=['in_file'])
Taken from Beginner's Tutorial by Michael Notter
Satrajit Ghosh
Chris Filo Gorgolewski
Russel Poldrack
Michael Notter
Luke Chang
Blake Davey
Michael Waskom
Julia Huntenburg
Stephen H Koslow
Adriana Di Martino
Dr Cameron Craddock
Dr Ivan J Roijals Miras
Tim Leslie
Juergen Dukart
Marten Mennes
Bharat P Biswal
F.Xavier Castellanos
Michael P.Milham
Alexandre Gramfort
Josh Carp
Michael F.Huerta