예제 #1
0
def create_alff(wf_name='alff_workflow'):
    """
    Calculate Amplitude of low frequency oscillations(ALFF) and fractional ALFF maps

    Parameters
    ----------
    wf_name : string
        Workflow name

    Returns
    -------
    alff_workflow : workflow object
        ALFF workflow

    Notes
    -----
    `Source <https://github.com/FCP-INDI/C-PAC/blob/master/CPAC/alff/alff.py>`_

    Workflow Inputs::

        hp_input.hp : list (float) 
            high pass frequencies

        lp_input.lp : list (float) 
            low pass frequencies

        inputspec.rest_res : string (existing nifti file)
            Nuisance signal regressed functional image

        inputspec.rest_mask : string (existing nifti file)
            A mask volume(derived by dilating the motion corrected functional volume) in native space


    Workflow Outputs::

        outputspec.alff_img : string (nifti file)
            outputs image containing the sum of the amplitudes in the low frequency band

        outputspec.falff_img : string (nifti file)
            outputs image containing the sum of the amplitudes in the low frequency band divided by the amplitude of the total frequency

        outputspec.alff_Z_img : string (nifti file)
            outputs image containing Normalized ALFF Z scores across full brain in native space

        outputspec.falff_Z_img : string (nifti file)
            outputs image containing Normalized fALFF Z scores across full brain in native space


    Order of Commands:

    - Filter the input file rest file( slice-time, motion corrected and nuisance regressed) ::
        3dBandpass -prefix residual_filtered.nii.gz 
                    0.009 0.08 residual.nii.gz
                    
    - Calculate ALFF by taking the standard deviation of the filtered file ::
        3dTstat -stdev 
                -mask rest_mask.nii.gz 
                -prefix residual_filtered_3dT.nii.gz
                residual_filtered.nii.gz
                  
    - Calculate the standard deviation of the unfiltered file ::
        3dTstat -stdev 
                -mask rest_mask.nii.gz 
                -prefix residual_3dT.nii.gz
                residual.nii.gz
  
    - Calculate fALFF ::
        3dcalc -a rest_mask.nii.gz 
               -b residual_filtered_3dT.nii.gz
               -c residual_3dT.nii.gz  
               -expr '(1.0*bool(a))*((1.0*b)/(1.0*c))' -float

    - Normalize ALFF/fALFF to Z-score across full brain ::

        fslstats
        ALFF.nii.gz
        -k rest_mask.nii.gz
        -m > mean_ALFF.txt ; mean=$( cat mean_ALFF.txt )

        fslstats
        ALFF.nii.gz
        -k rest_mask.nii.gz
        -s > std_ALFF.txt ; std=$( cat std_ALFF.txt )

        fslmaths
        ALFF.nii.gz
        -sub ${mean}
        -div ${std}
        -mas rest_mask.nii.gz ALFF_Z.nii.gz

        fslstats
        fALFF.nii.gz
        -k rest_mask.nii.gz
        -m > mean_fALFF.txt ; mean=$( cat mean_fALFF.txt )

        fslstats
        fALFF.nii.gz
        -k rest_mask.nii.gz 
        -s > std_fALFF.txt
        std=$( cat std_fALFF.txt )

        fslmaths
        fALFF.nii.gz
        -sub ${mean}
        -div ${std}
        -mas rest_mask.nii.gz
        fALFF_Z.nii.gz

    High Level Workflow Graph:
    
    .. image:: ../images/alff.dot.png
        :width: 500

    Detailed Workflow Graph:

    .. image:: ../images/alff_detailed.dot.png
        :width: 500

    
    References
    ----------

    .. [1] Zou, Q.-H., Zhu, C.-Z., Yang, Y., Zuo, X.-N., Long, X.-Y., Cao, Q.-J., Wang, Y.-F., et al. (2008). An improved approach to detection of amplitude of low-frequency fluctuation (ALFF) for resting-state fMRI: fractional ALFF. Journal of neuroscience methods, 172(1), 137-41. doi:10.10

    Examples
    --------

    >>> alff_w = create_alff()
    >>> alff_w.inputs.hp_input.hp = [0.01]
    >>> alff_w.inputs.lp_input.lp = [0.1]
    >>> alff_w.get_node('hp_input').iterables = ('hp',[0.01])
    >>> alff_w.get_node('lp_input').iterables = ('lp',[0.1])
    >>> alff_w.inputs.inputspec.rest_res = '/home/data/subject/func/rest_bandpassed.nii.gz'
    >>> alff_w.inputs.inputspec.rest_mask= '/home/data/subject/func/rest_mask.nii.gz' 
    >>> alff_w.run() # doctest: +SKIP


    """

    wf = pe.Workflow(name=wf_name)
    inputNode = pe.Node(
        util.IdentityInterface(fields=['rest_res', 'rest_mask']),
        name='inputspec')

    inputnode_hp = pe.Node(util.IdentityInterface(fields=['hp']),
                           name='hp_input')

    inputnode_lp = pe.Node(util.IdentityInterface(fields=['lp']),
                           name='lp_input')

    outputNode = pe.Node(util.IdentityInterface(
        fields=['alff_img', 'falff_img', 'alff_Z_img', 'falff_Z_img']),
                         name='outputspec')

    #filtering
    bandpass = pe.Node(interface=preprocess.ThreedBandpass(),
                       name='bandpass_filtering')
    bandpass.inputs.outputtype = 'NIFTI_GZ'
    bandpass.inputs.out_file = os.path.join(os.path.curdir,
                                            'residual_filtered.nii.gz')
    wf.connect(inputnode_hp, 'hp', bandpass, 'fbot')
    wf.connect(inputnode_lp, 'lp', bandpass, 'ftop')
    wf.connect(inputNode, 'rest_res', bandpass, 'in_file')

    get_option_string = pe.Node(util.Function(input_names=['mask'],
                                              output_names=['option_string'],
                                              function=get_opt_string),
                                name='get_option_string')
    wf.connect(inputNode, 'rest_mask', get_option_string, 'mask')

    #standard deviation over frequency
    stddev_fltrd = pe.Node(interface=preprocess.ThreedTstat(),
                           name='stddev_fltrd')
    stddev_fltrd.inputs.outputtype = 'NIFTI_GZ'
    stddev_fltrd.inputs.out_file = os.path.join(
        os.path.curdir, 'residual_filtered_3dT.nii.gz')
    wf.connect(bandpass, 'out_file', stddev_fltrd, 'in_file')
    wf.connect(get_option_string, 'option_string', stddev_fltrd, 'options')

    wf.connect(stddev_fltrd, 'out_file', outputNode, 'alff_img')

    #standard deviation of the unfiltered nuisance corrected image
    stddev_unfltrd = pe.Node(interface=preprocess.ThreedTstat(),
                             name='stddev_unfltrd')
    stddev_unfltrd.inputs.outputtype = 'NIFTI_GZ'
    stddev_unfltrd.inputs.out_file = os.path.join(os.path.curdir,
                                                  'residual_3dT.nii.gz')
    wf.connect(inputNode, 'rest_res', stddev_unfltrd, 'in_file')
    wf.connect(get_option_string, 'option_string', stddev_unfltrd, 'options')

    #falff calculations
    falff = pe.Node(interface=preprocess.Threedcalc(), name='falff')
    falff.inputs.expr = '\'(1.0*bool(a))*((1.0*b)/(1.0*c))\' -float'
    falff.inputs.outputtype = 'NIFTI_GZ'
    wf.connect(inputNode, 'rest_mask', falff, 'infile_a')
    wf.connect(stddev_fltrd, 'out_file', falff, 'infile_b')
    wf.connect(stddev_unfltrd, 'out_file', falff, 'infile_c')

    wf.connect(falff, 'out_file', outputNode, 'falff_img')

    #alff zscore
    alff_zscore = get_zscore("alff_zscore")
    wf.connect(stddev_fltrd, 'out_file', alff_zscore, 'inputspec.input_file')
    wf.connect(inputNode, 'rest_mask', alff_zscore, 'inputspec.mask_file')

    wf.connect(alff_zscore, 'outputspec.z_score_img', outputNode, 'alff_Z_img')

    #falff score
    falf_zscore = get_zscore("falf_zscore")
    wf.connect(falff, 'out_file', falf_zscore, 'inputspec.input_file')
    wf.connect(inputNode, 'rest_mask', falf_zscore, 'inputspec.mask_file')

    wf.connect(falf_zscore, 'outputspec.z_score_img', outputNode,
               'falff_Z_img')

    return wf
예제 #2
0
파일: vmhc.py 프로젝트: haipan/C-PAC
def create_vmhc():
    """
    Compute the map of brain functional homotopy, the high degree of synchrony in spontaneous activity between geometrically corresponding interhemispheric (i.e., homotopic) regions.



    Parameters
    ----------

    None

    Returns
    -------

    vmhc_workflow : workflow

        Voxel Mirrored Homotopic Connectivity Analysis Workflow



    Notes
    -----

    `Source <https://github.com/FCP-INDI/C-PAC/blob/master/CPAC/vmhc/vmhc.py>`_ 

    Workflow Inputs::

        inputspec.brain : string (existing nifti file)
            Anatomical image(without skull)

        inputspec.brain_symmetric : string (existing nifti file)
            MNI152_T1_2mm_brain_symmetric.nii.gz
 
        inputspec.rest_res_filt : string (existing nifti file)
            Band passed Image with nuisance signal regressed out(and optionally scrubbed). Recommended bandpass filter (0.001,0.1) )

        inputspec.reorient : string (existing nifti file)
            RPI oriented anatomical data

        inputspec.example_func2highres_mat : string (existing affine transformation .mat file)
            Specifies an affine transform that should be applied to the example_func before non linear warping

        inputspec.standard : string (existing nifti file)
            MNI152_T1_standard_resolution_brain.nii.gz

        inputspec.symm_standard : string (existing nifti file)
            MNI152_T1_2mm_symmetric.nii.gz

        inputspec.twomm_brain_mask_dil : string (existing nifti file)
            MNI152_T1_2mm_brain_mask_symmetric_dil.nii.gz

        inputspec.config_file_twomm_symmetric : string (existing .cnf file)
            T1_2_MNI152_2mm_symmetric.cnf

        inputspec.rest_mask : string (existing nifti file)
            A mask functional volume(derived by dilation from motion corrected functional volume)

        fwhm_input.fwhm : list (float) 
            For spatial smoothing the Z-transformed correlations in MNI space.
            Generally the value of this parameter is 1.5 or 2 times the voxel size of the input Image.

        
    Workflow Outputs::

        outputspec.highres2symmstandard : string (nifti file)
            Linear registration of T1 image to symmetric standard image

        outputspec.highres2symmstandard_mat : string (affine transformation .mat file)
            An affine transformation .mat file from linear registration and used in non linear registration

        outputspec.highres2symmstandard_warp : string (nifti file)
            warp file from Non Linear registration of T1 to symmetrical standard brain

        outputspec.fnirt_highres2symmstandard : string (nifti file)
            Non Linear registration of T1 to symmetrical standard brain

        outputspec.highres2symmstandard_jac : string (nifti file)
            jacobian determinant image from Non Linear registration of T1 to symmetrical standard brain

        outputspec.rest_res_2symmstandard : string (nifti file)
            nonlinear registration (func to standard) image

        outputspec.VMHC_FWHM_img : string (nifti file)
            pearson correlation between res2standard and flipped res2standard

        outputspec.VMHC_Z_FWHM_img : string (nifti file)
            Fisher Z transform map

        outputspec.VMHC_Z_stat_FWHM_img : string (nifti file)
            Z statistic map

    Order of commands:

    - Perform linear registration of Anatomical brain in T1 space to symmetric standard space. For details see `flirt <http://www.fmrib.ox.ac.uk/fsl/flirt/index.html>`_::

        flirt
        -ref MNI152_T1_2mm_brain_symmetric.nii.gz
        -in mprage_brain.nii.gz
        -out highres2symmstandard.nii.gz
        -omat highres2symmstandard.mat
        -cost corratio
        -searchcost corratio
        -dof 12
        -interp trilinear    
        
    - Perform nonlinear registration (higres to standard) to symmetric standard brain. For details see `fnirt <http://fsl.fmrib.ox.ac.uk/fsl/fnirt/>`_::
    
        fnirt
        --in=head.nii.gz
        --aff=highres2symmstandard.mat
        --cout=highres2symmstandard_warp.nii.gz
        --iout=fnirt_highres2symmstandard.nii.gz
        --jout=highres2symmstandard_jac.nii.gz
        --config=T1_2_MNI152_2mm_symmetric.cnf
        --ref=MNI152_T1_2mm_symmetric.nii.gz
        --refmask=MNI152_T1_2mm_brain_mask_symmetric_dil.nii.gz
        --warpres=10,10,10 

    - Perform spatial smoothing on the input functional image(inputspec.rest_res_filt).  For details see `PrinciplesSmoothing <http://imaging.mrc-cbu.cam.ac.uk/imaging/PrinciplesSmoothing>`_ `fslmaths <http://www.fmrib.ox.ac.uk/fslcourse/lectures/practicals/intro/index.htm>`_::

        fslmaths rest_res_filt.nii.gz
        -kernel gauss FWHM/ sqrt(8-ln(2))
        -fmean -mas rest_mask.nii.gz
        rest_res_filt_FWHM.nii.gz
        
    - Apply nonlinear registration (func to standard). For details see  `applywarp <http://www.fmrib.ox.ac.uk/fsl/fnirt/warp_utils.html#applywarp>`_::
        
        applywarp
        --ref=MNI152_T1_2mm_symmetric.nii.gz
        --in=rest_res_filt_FWHM.nii.gz
        --out=rest_res_2symmstandard.nii.gz
        --warp=highres2symmstandard_warp.nii.gz
        --premat=example_func2highres.mat
        
        
    - Copy and L/R swap the output of applywarp command (rest_res_2symmstandard.nii.gz). For details see  `fslswapdim <http://fsl.fmrib.ox.ac.uk/fsl/fsl4.0/avwutils/index.html>`_::

        fslswapdim
        rest_res_2symmstandard.nii.gz
        -x y z
        tmp_LRflipped.nii.gz


    - Calculate pearson correlation between rest_res_2symmstandard.nii.gz and flipped rest_res_2symmstandard.nii.gz(tmp_LRflipped.nii.gz). For details see  `3dTcorrelate <http://afni.nimh.nih.gov/pub/dist/doc/program_help/3dTcorrelate.html>`_::
        
        3dTcorrelate
        -pearson
        -polort -1
        -prefix VMHC_FWHM.nii.gz
        rest_res_2symmstandard.nii.gz
        tmp_LRflipped.nii.gz
    
    
    - Fisher Z Transform the correlation. For details see `3dcalc <http://afni.nimh.nih.gov/pub/dist/doc/program_help/3dcalc.html>`_::
        
        3dcalc
        -a VMHC_FWHM.nii.gz
        -expr 'log((a+1)/(1-a))/2'
        -prefix VMHC_FWHM_Z.nii.gz
    
        
    - Calculate the number of volumes(nvols) in flipped rest_res_2symmstandard.nii.gz(tmp_LRflipped.nii.gz) ::
        
        -Use Nibabel to do this
        
        
    - Compute the Z statistic map ::
        
        3dcalc
        -a VMHC_FWHM_Z.nii.gz
        -expr 'a*sqrt('${nvols}'-3)'
        -prefix VMHC_FWHM_Z_stat.nii.gz
    
    
    Workflow:
    
    .. image:: ../images/vmhc_graph.dot.png
        :width: 500 
    
    Workflow Detailed:
    
    .. image:: ../images/vmhc_detailed_graph.dot.png
        :width: 500 
    

    References
    ----------
    
    .. [1] Zuo, X.-N., Kelly, C., Di Martino, A., Mennes, M., Margulies, D. S., Bangaru, S., Grzadzinski, R., et al. (2010). Growing together and growing apart: regional and sex differences in the lifespan developmental trajectories of functional homotopy. The Journal of neuroscience : the official journal of the Society for Neuroscience, 30(45), 15034-43. doi:10.1523/JNEUROSCI.2612-10.2010


    Examples
    --------
    
    >>> vmhc_w = create_vmhc()
    >>> vmhc_w.inputs.inputspec.brain_symmetric = 'MNI152_T1_2mm_brain_symmetric.nii.gz'
    >>> vmhc_w.inputs.inputspec.symm_standard = 'MNI152_T1_2mm_symmetric.nii.gz'
    >>> vmhc_w.inputs.inputspec.twomm_brain_mask_dil = 'MNI152_T1_2mm_brain_mask_symmetric_dil.nii.gz'
    >>> vmhc_w.inputs.inputspec.config_file_twomm = 'T1_2_MNI152_2mm_symmetric.cnf'
    >>> vmhc_w.inputs.inputspec.standard = 'MNI152_T1_2mm.nii.gz'
    >>> vmhc_w.inputs.fwhm_input.fwhm = [4.5, 6]
    >>> vmhc_w.get_node('fwhm_input').iterables = ('fwhm', [4.5, 6])
    >>> vmhc_w.inputs.inputspec.rest_res = os.path.abspath('/home/data/Projects/Pipelines_testing/Dickstein/subjects/s1001/func/original/rest_res_filt.nii.gz')
    >>> vmhc_w.inputs.inputspec.reorient = os.path.abspath('/home/data/Projects/Pipelines_testing/Dickstein/subjects/s1001/anat/mprage_RPI.nii.gz')
    >>> vmhc_w.inputs.inputspec.brain = os.path.abspath('/home/data/Projects/Pipelines_testing/Dickstein/subjects/s1001/anat/mprage_brain.nii.gz')
    >>> vmhc_w.inputs.inputspec.example_func2highres_mat = os.path.abspath('/home/data/Projects/Pipelines_testing/Dickstein/subjects/s1001/func/original/reg/example_func2highres.mat')
    >>> vmhc_w.inputs.inputspec.rest_mask = os.path.abspath('/home/data/Projects/Pipelines_testing/Dickstein/subjects/s1001/func/original/rest_mask.nii.gz')
    >>> vmhc_w.run() # doctest: +SKIP

    """

    vmhc = pe.Workflow(name='vmhc_workflow')
    inputNode = pe.Node(util.IdentityInterface(fields=[
        'brain', 'brain_symmetric', 'rest_res', 'reorient',
        'example_func2highres_mat', 'symm_standard', 'twomm_brain_mask_dil',
        'config_file_twomm', 'rest_mask', 'standard'
    ]),
                        name='inputspec')

    outputNode = pe.Node(util.IdentityInterface(fields=[
        'highres2symmstandard', 'highres2symmstandard_mat',
        'highres2symmstandard_warp', 'fnirt_highres2symmstandard',
        'highres2symmstandard_jac', 'rest_res_2symmstandard', 'VMHC_FWHM_img',
        'VMHC_Z_FWHM_img', 'VMHC_Z_stat_FWHM_img'
    ]),
                         name='outputspec')

    inputnode_fwhm = pe.Node(util.IdentityInterface(fields=['fwhm']),
                             name='fwhm_input')

    ## Linear registration of T1 --> symmetric standard
    linear_T1_to_symmetric_standard = pe.Node(
        interface=fsl.FLIRT(), name='linear_T1_to_symmetric_standard')
    linear_T1_to_symmetric_standard.inputs.cost = 'corratio'
    linear_T1_to_symmetric_standard.inputs.cost_func = 'corratio'
    linear_T1_to_symmetric_standard.inputs.dof = 12
    linear_T1_to_symmetric_standard.inputs.interp = 'trilinear'

    ## Perform nonlinear registration
    ##(higres to standard) to symmetric standard brain
    nonlinear_highres_to_symmetric_standard = pe.Node(
        interface=fsl.FNIRT(), name='nonlinear_highres_to_symmetric_standard')
    nonlinear_highres_to_symmetric_standard.inputs.fieldcoeff_file = True
    nonlinear_highres_to_symmetric_standard.inputs.jacobian_file = True
    nonlinear_highres_to_symmetric_standard.inputs.warp_resolution = (10, 10,
                                                                      10)

    ## Apply nonlinear registration (func to standard)
    nonlinear_func_to_standard = pe.Node(interface=fsl.ApplyWarp(),
                                         name='nonlinear_func_to_standard')

    ## copy and L/R swap file
    copy_and_L_R_swap = pe.Node(interface=fsl.SwapDimensions(),
                                name='copy_and_L_R_swap')
    copy_and_L_R_swap.inputs.new_dims = ('-x', 'y', 'z')

    ## caculate vmhc
    pearson_correlation = pe.Node(interface=preprocess.ThreedTcorrelate(),
                                  name='pearson_correlation')
    pearson_correlation.inputs.pearson = True
    pearson_correlation.inputs.polort = -1
    pearson_correlation.inputs.outputtype = 'NIFTI_GZ'

    z_trans = pe.Node(interface=preprocess.Threedcalc(), name='z_trans')
    z_trans.inputs.expr = '\'log((1+a)/(1-a))/2\''
    z_trans.inputs.outputtype = 'NIFTI_GZ'
    z_stat = pe.Node(interface=preprocess.Threedcalc(), name='z_stat')
    z_stat.inputs.outputtype = 'NIFTI_GZ'

    NVOLS = pe.Node(util.Function(input_names=['in_files'],
                                  output_names=['nvols'],
                                  function=get_img_nvols),
                    name='NVOLS')

    generateEXP = pe.Node(util.Function(input_names=['nvols'],
                                        output_names=['expr'],
                                        function=get_operand_expression),
                          name='generateEXP')

    smooth = pe.Node(interface=fsl.MultiImageMaths(), name='smooth')

    vmhc.connect(inputNode, 'brain', linear_T1_to_symmetric_standard,
                 'in_file')
    vmhc.connect(inputNode, 'brain_symmetric', linear_T1_to_symmetric_standard,
                 'reference')
    vmhc.connect(inputNode, 'reorient',
                 nonlinear_highres_to_symmetric_standard, 'in_file')
    vmhc.connect(linear_T1_to_symmetric_standard, 'out_matrix_file',
                 nonlinear_highres_to_symmetric_standard, 'affine_file')
    vmhc.connect(inputNode, 'symm_standard',
                 nonlinear_highres_to_symmetric_standard, 'ref_file')
    vmhc.connect(inputNode, 'twomm_brain_mask_dil',
                 nonlinear_highres_to_symmetric_standard, 'refmask_file')
    vmhc.connect(inputNode, 'config_file_twomm',
                 nonlinear_highres_to_symmetric_standard, 'config_file')
    vmhc.connect(inputNode, 'rest_res', smooth, 'in_file')
    vmhc.connect(inputnode_fwhm, ('fwhm', set_gauss), smooth, 'op_string')
    vmhc.connect(inputNode, 'rest_mask', smooth, 'operand_files')
    vmhc.connect(smooth, 'out_file', nonlinear_func_to_standard, 'in_file')
    vmhc.connect(inputNode, 'symm_standard', nonlinear_func_to_standard,
                 'ref_file')
    vmhc.connect(nonlinear_highres_to_symmetric_standard, 'fieldcoeff_file',
                 nonlinear_func_to_standard, 'field_file')
    vmhc.connect(inputNode, 'example_func2highres_mat',
                 nonlinear_func_to_standard, 'premat')

    vmhc.connect(nonlinear_func_to_standard, 'out_file', copy_and_L_R_swap,
                 'in_file')
    vmhc.connect(nonlinear_func_to_standard, 'out_file', pearson_correlation,
                 'xset')
    vmhc.connect(copy_and_L_R_swap, 'out_file', pearson_correlation, 'yset')
    vmhc.connect(pearson_correlation, 'out_file', z_trans, 'infile_a')
    vmhc.connect(copy_and_L_R_swap, 'out_file', NVOLS, 'in_files')
    vmhc.connect(NVOLS, 'nvols', generateEXP, 'nvols')
    vmhc.connect(z_trans, 'out_file', z_stat, 'infile_a')
    vmhc.connect(generateEXP, 'expr', z_stat, 'expr')

    vmhc.connect(linear_T1_to_symmetric_standard, 'out_file', outputNode,
                 'highres2symmstandard')
    vmhc.connect(linear_T1_to_symmetric_standard, 'out_matrix_file',
                 outputNode, 'highres2symmstandard_mat')
    vmhc.connect(nonlinear_highres_to_symmetric_standard, 'jacobian_file',
                 outputNode, 'highres2symmstandard_jac')
    vmhc.connect(nonlinear_highres_to_symmetric_standard, 'fieldcoeff_file',
                 outputNode, 'highres2symmstandard_warp')
    vmhc.connect(nonlinear_highres_to_symmetric_standard, 'warped_file',
                 outputNode, 'fnirt_highres2symmstandard')
    vmhc.connect(nonlinear_func_to_standard, 'out_file', outputNode,
                 'rest_res_2symmstandard')
    vmhc.connect(pearson_correlation, 'out_file', outputNode, 'VMHC_FWHM_img')
    vmhc.connect(z_trans, 'out_file', outputNode, 'VMHC_Z_FWHM_img')
    vmhc.connect(z_stat, 'out_file', outputNode, 'VMHC_Z_stat_FWHM_img')

    return vmhc
예제 #3
0
def create_func_preproc(slice_timing_correction = False, wf_name = 'func_preproc'):
    """
    
    The main purpose of this workflow is to process functional data. Raw rest file is deobliqued and reoriented 
    into RPI. Then take the mean intensity values over all time points for each voxel and use this image 
    to calculate motion parameters. The image is then skullstripped, normalized and a processed mask is 
    obtained to use it further in Image analysis.
    
    Parameters
    ----------
    
    slice_timing_correction : boolean
        Slice timing Correction option
    wf_name : string
        Workflow name
    
    Returns 
    -------
    func_preproc : workflow object
        Functional Preprocessing workflow object
    
    Notes
    -----
    
    `Source <https://github.com/FCP-INDI/C-PAC/blob/master/CPAC/func_preproc/func_preproc.py>`_
    
    Workflow Inputs::
    
        inputspec.rest : func/rest file or a list of func/rest nifti file 
            User input functional(T2) Image, in any of the 8 orientations
            
        inputspec.start_idx : string 
            Starting volume/slice of the functional image (optional)
            
        inputspec.stop_idx : string
            Last volume/slice of the functional image (optional)
            
        scan_params.tr : string
            Subject TR
        
        scan_params.acquistion : string
            Acquisition pattern (interleaved/sequential, ascending/descending)
    
        scan_params.ref_slice : integer
            Reference slice for slice timing correction
            
    Workflow Outputs::
    
        outputspec.drop_tr : string (nifti file)
            Path to Output image with the initial few slices dropped
          
        outputspec.slice_time_corrected : string (nifti file)
            Path to Slice time corrected image
          
        outputspec.refit : string (nifti file)
            Path to deobliqued anatomical data 
        
        outputspec.reorient : string (nifti file)
            Path to RPI oriented anatomical data 
        
        outputspec.motion_correct_ref : string (nifti file)
             Path to Mean intensity Motion corrected image 
             (base reference image for the second motion correction run)
        
        outputspec.motion_correct : string (nifti file)
            Path to motion corrected output file
        
        outputspec.max_displacement : string (Mat file)
            Path to maximum displacement (in mm) for brain voxels in each volume
        
        outputspec.movement_parameters : string (Mat file)
            Path to 1D file containing six movement/motion parameters(3 Translation, 3 Rotations) 
            in different columns (roll pitch yaw dS  dL  dP)
        
        outputspec.skullstrip : string (nifti file)
            Path to skull stripped Motion Corrected Image 
        
        outputspec.mask : string (nifti file)
            Path to brain-only mask
            
        outputspec.example_func : string (nifti file)
            Mean, Skull Stripped, Motion Corrected output T2 Image path
            (Image with mean intensity values across voxels) 
        
        outputpsec.preprocessed : string (nifti file)
            output skull stripped, motion corrected T2 image 
            with normalized intensity values 

        outputspec.preprocessed_mask : string (nifti file)
           Mask obtained from normalized preprocessed image
           
    
    Order of commands:
    
    - Get the start and the end volume index of the functional run. If not defined by the user, return the first and last volume.
    
        get_idx(in_files, stop_idx, start_idx)
        
    - Dropping the initial TRs. For details see `3dcalc <http://afni.nimh.nih.gov/pub/dist/doc/program_help/3dcalc.html>`_::
        
        3dcalc -a rest.nii.gz[4..299] 
               -expr 'a' 
               -prefix rest_3dc.nii.gz
               
    - Slice timing correction. For details see `3dshift <http://afni.nimh.nih.gov/pub/dist/doc/program_help/3dTshift.html>`_::
    
        3dTshift -TR 2.1s 
                 -slice 18 
                 -tpattern alt+z 
                 -prefix rest_3dc_shift.nii.gz rest_3dc.nii.gz

    - Deobliqing the scans.  For details see `3drefit <http://afni.nimh.nih.gov/pub/dist/doc/program_help/3drefit.html>`_::
    
        3drefit -deoblique rest_3dc.nii.gz
        
    - Re-orienting the Image into Right-to-Left Posterior-to-Anterior Inferior-to-Superior (RPI) orientation. For details see `3dresample <http://afni.nimh.nih.gov/pub/dist/doc/program_help/3dresample.html>`_::
    
        3dresample -orient RPI 
                   -prefix rest_3dc_RPI.nii.gz 
                   -inset rest_3dc.nii.gz
        
    - Calculate voxel wise statistics. Get the RPI Image with mean intensity values over all timepoints for each voxel. For details see `3dTstat <http://afni.nimh.nih.gov/pub/dist/doc/program_help/3dTstat.html>`_::
    
        3dTstat -mean 
                -prefix rest_3dc_RPI_3dT.nii.gz 
                rest_3dc_RPI.nii.gz
    
    - Motion Correction. For details see `3dvolreg <http://afni.nimh.nih.gov/pub/dist/doc/program_help/3dvolreg.html>`_::  
       
        3dvolreg -Fourier 
                 -twopass 
                 -base rest_3dc_RPI_3dT.nii.gz/
                 -zpad 4 
                 -maxdisp1D rest_3dc_RPI_3dvmd1D.1D 
                 -1Dfile rest_3dc_RPI_3dv1D.1D 
                 -prefix rest_3dc_RPI_3dv.nii.gz 
                 rest_3dc_RPI.nii.gz
                 
      The base image or the reference image is the mean intensity RPI image obtained in the above the step.For each volume 
      in RPI-oriented T2 image, the command, aligns the image with the base mean image and calculates the motion, displacement 
      and movement parameters. It also outputs the aligned 4D volume and movement and displacement parameters for each volume.
                 
    - Calculate voxel wise statistics. Get the motion corrected output Image from the above step, with mean intensity values over all timepoints for each voxel. 
      For details see `3dTstat <http://afni.nimh.nih.gov/pub/dist/doc/program_help/3dTstat.html>`_::
    
        3dTstat -mean 
                -prefix rest_3dc_RPI_3dv_3dT.nii.gz 
                rest_3dc_RPI_3dv.nii.gz
    
    - Motion Correction and get motion, movement and displacement parameters. For details see `3dvolreg <http://afni.nimh.nih.gov/pub/dist/doc/program_help/3dvolreg.html>`_::   

        3dvolreg -Fourier 
                 -twopass 
                 -base rest_3dc_RPI_3dv_3dT.nii.gz 
                 -zpad 4 
                 -maxdisp1D rest_3dc_RPI_3dvmd1D.1D 
                 -1Dfile rest_3dc_RPI_3dv1D.1D 
                 -prefix rest_3dc_RPI_3dv.nii.gz 
                 rest_3dc_RPI.nii.gz
        
      The base image or the reference image is the mean intensity motion corrected image obtained from the above the step (first 3dvolreg run). 
      For each volume in RPI-oriented T2 image, the command, aligns the image with the base mean image and calculates the motion, displacement 
      and movement parameters. It also outputs the aligned 4D volume and movement and displacement parameters for each volume.
    
    - Create a  brain-only mask. For details see `3dautomask <http://afni.nimh.nih.gov/pub/dist/doc/program_help/3dAutomask.html>`_::
    
        3dAutomask  
                   -prefix rest_3dc_RPI_3dv_automask.nii.gz 
                   rest_3dc_RPI_3dv.nii.gz

    - Edge Detect(remove skull) and get the brain only. For details see `3dcalc <http://afni.nimh.nih.gov/pub/dist/doc/program_help/3dcalc.html>`_::
    
        3dcalc -a rest_3dc_RPI_3dv.nii.gz 
               -b rest_3dc_RPI_3dv_automask.nii.gz 
               -expr 'a*b' 
               -prefix rest_3dc_RPI_3dv_3dc.nii.gz
    
    - Normalizing the image intensity values. For details see `fslmaths <http://www.fmrib.ox.ac.uk/fsl/avwutils/index.html>`_::
      
        fslmaths rest_3dc_RPI_3dv_3dc.nii.gz 
                 -ing 10000 rest_3dc_RPI_3dv_3dc_maths.nii.gz 
                 -odt float
                 
      Normalized intensity = (TrueValue*10000)/global4Dmean
                 
    - Calculate mean of skull stripped image. For details see `3dTstat <http://afni.nimh.nih.gov/pub/dist/doc/program_help/3dTstat.html>`_::
        
        3dTstat -mean -prefix rest_3dc_RPI_3dv_3dc_3dT.nii.gz rest_3dc_RPI_3dv_3dc.nii.gz
        
    - Create Mask (Generate mask from Normalized data). For details see `fslmaths <http://www.fmrib.ox.ac.uk/fsl/avwutils/index.html>`_::
        
        fslmaths rest_3dc_RPI_3dv_3dc_maths.nii.gz 
               -Tmin -bin rest_3dc_RPI_3dv_3dc_maths_maths.nii.gz 
               -odt char

    High Level Workflow Graph:
    
    .. image:: ../images/func_preproc.dot.png
       :width: 1000
    
    
    Detailed Workflow Graph:
    
    .. image:: ../images/func_preproc_detailed.dot.png
       :width: 1000

    Examples
    --------
    
    >>> import func_preproc
    >>> preproc = create_func_preproc(slice_timing_correction=True)
    >>> preproc.inputs.inputspec.func='sub1/func/rest.nii.gz'
    >>> preproc.inputs.scan_params.TR = '2.0'
    >>> preproc.inputs.scan_params.ref_slice = 19
    >>> preproc.inputs.scan_params.acquisition = 'alt+z2'
    >>> preproc.run() #doctest: +SKIP


    >>> import func_preproc
    >>> preproc = create_func_preproc(slice_timing_correction=False)
    >>> preproc.inputs.inputspec.func='sub1/func/rest.nii.gz'
    >>> preproc.inputs.inputspec.start_idx = 4
    >>> preproc.inputs.inputspec.stop_idx = 250
    >>> preproc.run() #doctest: +SKIP
    
    """

    preproc = pe.Workflow(name=wf_name)
    inputNode = pe.Node(util.IdentityInterface(fields=['rest',
                                                       'start_idx',
                                                       'stop_idx']),
                        name='inputspec')
    
    scan_params = pe.Node(util.IdentityInterface(fields=['tr',
                                                         'acquisition',
                                                         'ref_slice']),
                          name = 'scan_params')

    outputNode = pe.Node(util.IdentityInterface(fields=['drop_tr',
                                                        'refit',
                                                        'reorient',
                                                        'reorient_mean',
                                                        'motion_correct',
                                                        'motion_correct_ref',
                                                        'movement_parameters',
                                                        'max_displacement',
                                                        'xform_matrix',
                                                        'mask',
                                                        'skullstrip',
                                                        'example_func',
                                                        'preprocessed',
                                                        'preprocessed_mask',
                                                        'slice_time_corrected']),

                          name='outputspec')

    func_get_idx = pe.Node(util.Function(input_names=['in_files', 
                                                      'stop_idx', 
                                                      'start_idx'],
                               output_names=['stopidx', 
                                             'startidx'],
                 function=get_idx), name='func_get_idx')
    
    preproc.connect(inputNode, 'rest',
                    func_get_idx, 'in_files')
    preproc.connect(inputNode, 'start_idx',
                    func_get_idx, 'start_idx')
    preproc.connect(inputNode, 'stop_idx',
                    func_get_idx, 'stop_idx')
    
    
    func_drop_trs = pe.Node(interface=preprocess.Threedcalc(),
                           name='func_drop_trs')
    func_drop_trs.inputs.expr = '\'a\''
    func_drop_trs.inputs.outputtype = 'NIFTI_GZ'
    
    preproc.connect(inputNode, 'rest',
                    func_drop_trs, 'infile_a')
    preproc.connect(func_get_idx, 'startidx',
                    func_drop_trs, 'start_idx')
    preproc.connect(func_get_idx, 'stopidx',
                    func_drop_trs, 'stop_idx')
    
    preproc.connect(func_drop_trs, 'out_file',
                    outputNode, 'drop_tr')
    
    
    func_slice_timing_correction = pe.Node(interface=preprocess.ThreedTshift(),
                                           name = 'func_slice_timing_correction')
    func_slice_timing_correction.inputs.outputtype = 'NIFTI_GZ'
    
    func_deoblique = pe.Node(interface=preprocess.Threedrefit(),
                            name='func_deoblique')
    func_deoblique.inputs.deoblique = True
    func_deoblique.inputs.outputtype = 'NIFTI_GZ'
    
    
    if slice_timing_correction:
        preproc.connect(func_drop_trs, 'out_file',
                        func_slice_timing_correction,'in_file')
        preproc.connect(scan_params, 'tr',
                        func_slice_timing_correction, 'tr')
        preproc.connect(scan_params, 'acquisition',
                        func_slice_timing_correction, 'tpattern')
        preproc.connect(scan_params, 'ref_slice',
                        func_slice_timing_correction, 'tslice')
        
        preproc.connect(func_slice_timing_correction, 'out_file',
                        func_deoblique, 'in_file')
        
        preproc.connect(func_slice_timing_correction, 'out_file',
                        outputNode, 'slice_time_corrected')
    else:
        preproc.connect(func_drop_trs, 'out_file',
                        func_deoblique, 'in_file')
    
    preproc.connect(func_deoblique, 'out_file',
                    outputNode, 'refit')

    func_reorient = pe.Node(interface=preprocess.Threedresample(),
                               name='func_reorient')
    func_reorient.inputs.orientation = 'RPI'
    func_reorient.inputs.outputtype = 'NIFTI_GZ'

    preproc.connect(func_deoblique, 'out_file',
                    func_reorient, 'in_file')
    
    preproc.connect(func_reorient, 'out_file',
                    outputNode, 'reorient')
    
    func_get_mean_RPI = pe.Node(interface=preprocess.ThreedTstat(),
                            name='func_get_mean_RPI')
    func_get_mean_RPI.inputs.options = '-mean'
    func_get_mean_RPI.inputs.outputtype = 'NIFTI_GZ'
    
    preproc.connect(func_reorient, 'out_file',
                    func_get_mean_RPI, 'in_file')
        
    #calculate motion parameters
    func_motion_correct = pe.Node(interface=preprocess.Threedvolreg(),
                             name='func_motion_correct')
    func_motion_correct.inputs.other = '-Fourier -twopass'
    func_motion_correct.inputs.zpad = '4'
    func_motion_correct.inputs.outputtype = 'NIFTI_GZ'
    
    preproc.connect(func_reorient, 'out_file',
                    func_motion_correct, 'in_file')
    preproc.connect(func_get_mean_RPI, 'out_file',
                    func_motion_correct, 'basefile')


    func_get_mean_motion = func_get_mean_RPI.clone('func_get_mean_motion')
    preproc.connect(func_motion_correct, 'out_file',
                    func_get_mean_motion, 'in_file')
    
    preproc.connect(func_get_mean_motion, 'out_file',
                    outputNode, 'motion_correct_ref')
    
    
    func_motion_correct_A = func_motion_correct.clone('func_motion_correct_A')
    preproc.connect(func_reorient, 'out_file',
                    func_motion_correct_A, 'in_file')
    preproc.connect(func_get_mean_motion, 'out_file',
                    func_motion_correct_A, 'basefile')
    
    preproc.connect(func_motion_correct_A, 'out_file',
                    outputNode, 'motion_correct')
    preproc.connect(func_motion_correct_A, 'md1d_file',
                    outputNode, 'max_displacement')
    preproc.connect(func_motion_correct_A, 'oned_file',
                    outputNode, 'movement_parameters')
    preproc.connect(func_motion_correct_A, 'mat1d_file',
                    outputNode, 'xform_matrix')

    
    func_get_brain_mask = pe.Node(interface=preprocess.ThreedAutomask(),
                               name='func_get_brain_mask')
#    func_get_brain_mask.inputs.dilate = 1
    func_get_brain_mask.inputs.outputtype = 'NIFTI_GZ'

    preproc.connect(func_motion_correct_A, 'out_file',
                    func_get_brain_mask, 'in_file')
    
    preproc.connect(func_get_brain_mask, 'out_file',
                    outputNode, 'mask')
        
    
    func_edge_detect = pe.Node(interface=preprocess.Threedcalc(),
                            name='func_edge_detect')
    func_edge_detect.inputs.expr = '\'a*b\''
    func_edge_detect.inputs.outputtype = 'NIFTI_GZ'

    preproc.connect(func_motion_correct_A, 'out_file',
                    func_edge_detect, 'infile_a')
    preproc.connect(func_get_brain_mask, 'out_file',
                    func_edge_detect, 'infile_b')

    preproc.connect(func_edge_detect, 'out_file',
                    outputNode, 'skullstrip')

    
    func_mean_skullstrip = pe.Node(interface=preprocess.ThreedTstat(),
                           name='func_mean_skullstrip')
    func_mean_skullstrip.inputs.options = '-mean'
    func_mean_skullstrip.inputs.outputtype = 'NIFTI_GZ'

    preproc.connect(func_edge_detect, 'out_file',
                    func_mean_skullstrip, 'in_file')
    
    preproc.connect(func_mean_skullstrip, 'out_file',
                    outputNode, 'example_func')
    
    
    func_normalize = pe.Node(interface=fsl.ImageMaths(),
                            name='func_normalize')
    func_normalize.inputs.op_string = '-ing 10000'
    func_normalize.inputs.out_data_type = 'float'

    preproc.connect(func_edge_detect, 'out_file',
                    func_normalize, 'in_file')
    
    preproc.connect(func_normalize, 'out_file',
                    outputNode, 'preprocessed')
    
    
    func_mask_normalize = pe.Node(interface=fsl.ImageMaths(),
                           name='func_mask_normalize')
    func_mask_normalize.inputs.op_string = '-Tmin -bin'
    func_mask_normalize.inputs.out_data_type = 'char'

    preproc.connect(func_normalize, 'out_file',
                    func_mask_normalize, 'in_file')
    
    preproc.connect(func_mask_normalize, 'out_file',
                    outputNode, 'preprocessed_mask')

    return preproc
예제 #4
0
def create_anat_preproc():
    """ 
    
    The main purpose of this workflow is to process T1 scans. Raw mprage file is deobliqued, reoriented 
    into RPI and skullstripped. Also, a whole brain only mask is generated from the skull stripped image 
    for later use in registration.
    
    Returns 
    -------
    anat_preproc : workflow
        Anatomical Preprocessing Workflow
    
    Notes
    -----
    
    `Source <https://github.com/FCP-INDI/C-PAC/blob/master/CPAC/anat_preproc/anat_preproc.py>`_
    
    Workflow Inputs::
    
        inputspec.anat : mprage file or a list of mprage nifti file 
            User input anatomical(T1) Image, in any of the 8 orientations
    
    Workflow Outputs::
    
        outputspec.refit : nifti file
            Deobliqued anatomical data 
        outputspec.reorient : nifti file
            RPI oriented anatomical data 
        outputspec.skullstrip : nifti file
            Skull Stripped RPI oriented mprage file with normalized intensities.
        outputspec.brain : nifti file
            Skull Stripped RPI Brain Image with original intensity values and not normalized or scaled.
    
    Order of commands:

    - Deobliqing the scans.  For details see `3drefit <http://afni.nimh.nih.gov/pub/dist/doc/program_help/3drefit.html>`_::
    
        3drefit -deoblique mprage.nii.gz
        
    - Re-orienting the Image into Right-to-Left Posterior-to-Anterior Inferior-to-Superior  (RPI) orientation.  For details see `3dresample <http://afni.nimh.nih.gov/pub/dist/doc/program_help/3dresample.html>`_::
    
        3dresample -orient RPI -prefix mprage_RPI.nii.gz -inset mprage.nii.gz 
    
    - SkullStripping the image.  For details see `3dSkullStrip <http://afni.nimh.nih.gov/pub/dist/doc/program_help/3dSkullStrip.html>`_::
    
        3dSkullStrip -input mprage_RPI.nii.gz -o_ply mprage_RPI_3dT.nii.gz
    
    - The skull stripping step modifies the intensity values. To get back the original intensity values, we do an element wise product of RPI data with step function of skull Stripped data.  For details see `3dcalc <http://afni.nimh.nih.gov/pub/dist/doc/program_help/3dcalc.html>`_::
    
        3dcalc -a mprage_RPI.nii.gz -b mprage_RPI_3dT.nii.gz -expr 'a*step(b)' -prefix mprage_RPI_3dc.nii.gz
    
    High Level Workflow Graph:
    
    .. image:: ../images/anatpreproc_graph.dot.png
       :width: 500
    
    
    Detailed Workflow Graph:
    
    .. image:: ../images/anatpreproc_graph_detailed.dot.png
       :width: 500

    Examples
    --------
    
    >>> import anat
    >>> prproc = create_anat_preproc()
    >>> preproc.inputs.inputspec.anat='sub1/anat/mprage.nii.gz'
    >>> preporc.run() #doctest: +SKIP
            
    """
    preproc = pe.Workflow(name='anat_preproc')

    inputNode = pe.Node(util.IdentityInterface(fields=['anat']),
                        name='inputspec')

    outputNode = pe.Node(util.IdentityInterface(
        fields=['refit', 'reorient', 'skullstrip', 'brain']),
                         name='outputspec')

    anat_deoblique = pe.Node(interface=preprocess.Threedrefit(),
                             name='anat_deoblique')
    anat_deoblique.inputs.deoblique = True
    anat_deoblique.inputs.outputtype = 'NIFTI_GZ'

    anat_reorient = pe.Node(interface=preprocess.Threedresample(),
                            name='anat_reorient')
    anat_reorient.inputs.orientation = 'RPI'
    anat_reorient.inputs.outputtype = 'NIFTI_GZ'

    anat_skullstrip = pe.Node(interface=preprocess.ThreedSkullStrip(),
                              name='anat_skullstrip')
    anat_skullstrip.inputs.options = '-o_ply'
    anat_skullstrip.inputs.outputtype = 'NIFTI_GZ'

    anat_brain_only = pe.Node(interface=preprocess.Threedcalc(),
                              name='anat_brain_only')
    anat_brain_only.inputs.expr = '\'a*step(b)\''
    anat_brain_only.inputs.outputtype = 'NIFTI_GZ'

    preproc.connect(inputNode, 'anat', anat_deoblique, 'in_file')
    preproc.connect(anat_deoblique, 'out_file', anat_reorient, 'in_file')
    preproc.connect(anat_reorient, 'out_file', anat_skullstrip, 'in_file')
    preproc.connect(anat_skullstrip, 'out_file', anat_brain_only, 'infile_b')
    preproc.connect(anat_reorient, 'out_file', anat_brain_only, 'infile_a')

    preproc.connect(anat_deoblique, 'out_file', outputNode, 'refit')
    preproc.connect(anat_reorient, 'out_file', outputNode, 'reorient')
    preproc.connect(anat_skullstrip, 'out_file', outputNode, 'skullstrip')
    preproc.connect(anat_brain_only, 'out_file', outputNode, 'brain')

    return preproc
예제 #5
0
파일: scrubbing.py 프로젝트: haipan/C-PAC
def create_scrubbing_preproc(wf_name = 'scrubbing'):
    """
    This workflow essentially takes the list of offending timepoints that are to be removed
    and removes it from the motion corrected input image. Also, it removes the information
    of discarded time points from the movement parameters file obtained during motion correction.
    
    Parameters
    ----------
    wf_name : string
        Name of the workflow
    
    Returns
    -------
    scrub : object
        Scrubbing workfow object
    
    Notes
    -----
    `Source <https://github.com/openconnectome/C-PAC/blob/master/CPAC/scrubbing/scrubbing.py>`_
    
    Workflow Inputs::
        
        inputspec.frames_in_ID : string (mat file)
            path to file containing list of time points for which FD > threshold
        inputspec.movement_parameters : string (mat file)
            path to file containing 1D file containing six movement/motion parameters
            (3 Translation, 3 Rotations) in different columns 
        inputspec.preprocessed : string (nifti file)
            preprocessed input image path
            
    Workflow Outputs::
        
        outputspec.preprocessed : string (nifti file)
            preprocessed scrubbed output image 
        outputspec.scrubbed_movement_parameters : string (mat file)
            path to 1D file containing six movement/motion parameters
            for the timepoints which are not discarded by scrubbing
        
    Order of Commands:
    
    - Remove all movement parameters for all the time frames other than those that are present
      in the frames_in_1D file
      
    - Remove the discarded timepoints from the input image. For details see `3dcalc <http://afni.nimh.nih.gov/pub/dist/doc/program_help/3dcalc.html>`_::
        
        3dcalc -a bandpassed_demeaned_filtered.nii.gz[0,1,5,6,7,8,9,10,15,16,17,18,19,20,24,25,287,288,289,290,291,292,293,294,295] 
               -expr 'a' -prefix bandpassed_demeaned_filtered_3dc.nii.gz
               
    High Level Workflow Graph:
    
    .. image:: ../images/scrubbing.dot.png
       :width: 500
    
    Detailed Workflow Graph:
    
    .. image:: ../images/scrubbing_detailed.dot.png
       :width: 500
       
    Example
    -------
    >>> import scrubbing
    >>> sc = scrubbing.create_scrubbing_preproc()
    >>> sc.inputs.inputspec.frames_in_ID = 'frames_in.1D'
    >>> sc.inputs.inputpsec.movement_parameters = 'rest_mc.1D'
    >>> sc.inputs.inputpsec.preprocessed = 'rest_pp.nii.gz'
    >>> sc.run()  -- SKIP doctest
    
    """

    scrub = pe.Workflow(name=wf_name)

    inputNode = pe.Node(util.IdentityInterface(fields=['frames_in_1D',
                                                       'movement_parameters',
                                                       'preprocessed'
                                                    ]),
                        name='inputspec')


    outputNode = pe.Node(util.IdentityInterface(fields=['preprocessed',
                                                         'scrubbed_movement_parameters']),
                        name='outputspec')


    scrubbed_movement_parameters = pe.Node(util.Function(input_names=['infile_a', 'infile_b'], 
                                                 output_names=['out_file'],
                                                 function=get_mov_parameters), 
                                   name='scrubbed_movement_parameters')

    scrubbed_preprocessed = pe.Node(interface=e_afni.Threedcalc(), 
                               name='scrubbed_preprocessed')
    scrubbed_preprocessed.inputs.expr = '\'a\''

    scrub.connect(inputNode, 'preprocessed', scrubbed_preprocessed, 'infile_a')
    scrub.connect(inputNode, ('frames_in_1D', get_indx), scrubbed_preprocessed, 'list_idx')

    scrub.connect(inputNode, 'movement_parameters', scrubbed_movement_parameters, 'infile_b')
    scrub.connect(inputNode, 'frames_in_1D', scrubbed_movement_parameters, 'infile_a' )

    scrub.connect(scrubbed_preprocessed, 'out_file', outputNode, 'preprocessed')
    scrub.connect(scrubbed_movement_parameters, 'out_file', outputNode, 'scrubbed_movement_parameters')

    return scrub