Ejemplo n.º 1
0
def prep_workflow(c):
    import nipype.pipeline.engine as pe
    import nipype.interfaces.utility as util
    import nipype.interfaces.io as nio

    fieldmap = c.use_fieldmap
    infosource = pe.Node(util.IdentityInterface(fields=['subject_id']),
                         name='subject_names')
    if not c.test_mode:
        infosource.iterables = ('subject_id', c.subjects)
    else:
        infosource.iterables = ('subject_id', c.subjects[:1])

    modelflow = pe.Workflow(name='preproc')

    # make a data sink
    sinkd = get_datasink(c.sink_dir, c.fwhm)

    # generate preprocessing workflow
    #dataflow = c.create_dataflow()

    # create a node to obtain the functional images
    dataflow = get_dataflow(c)

    if fieldmap:
        preproc = create_prep_fieldmap()
        preproc.inputs.inputspec.FM_Echo_spacing = c.echospacing
        preproc.inputs.inputspec.FM_TEdiff = c.TE_diff
        preproc.inputs.inputspec.FM_sigma = c.sigma

        #datasource_fieldmap = c.create_fieldmap_dataflow()
        datasource_fieldmap = pe.Node(nio.DataGrabber(
            infields=['subject_id'], outfields=['mag', 'phase']),
                                      name="fieldmap_datagrabber")
        datasource_fieldmap.inputs.base_directory = c.field_dir
        datasource_fieldmap.inputs.sort_filelist = True
        datasource_fieldmap.inputs.template = '*'
        datasource_fieldmap.inputs.field_template = dict(
            mag=c.magnitude_template, phase=c.phase_template)
        datasource_fieldmap.inputs.template_args = dict(mag=[['subject_id']],
                                                        phase=[['subject_id']])

        modelflow.connect(infosource, 'subject_id', datasource_fieldmap,
                          'subject_id')
        modelflow.connect(datasource_fieldmap, 'mag', preproc,
                          'fieldmap_input.magnitude_file')
        modelflow.connect(datasource_fieldmap, 'phase', preproc,
                          'fieldmap_input.phase_file')
        modelflow.connect(preproc, 'outputspec.FM_unwarped_mean', sinkd,
                          'preproc.fieldmap.@unwarped_mean')
        modelflow.connect(preproc, 'outputspec.FM_unwarped_epi', sinkd,
                          'preproc.fieldmap.@unwarped_epi')
    else:
        preproc = create_prep()

    if not c.do_zscore:
        z_score = preproc.get_node('z_score')
        preproc.remove_nodes([z_score])

    preproc.inputs.inputspec.motion_correct_node = c.motion_correct_node

    preproc.inputs.inputspec.realign_parameters = {
        "loops": c.loops,
        "speedup": c.speedup
    }
    preproc.inputs.inputspec.timepoints_to_remove = c.timepoints_to_remove
    preproc.inputs.inputspec.smooth_type = c.smooth_type
    preproc.inputs.inputspec.surface_fwhm = c.surface_fwhm
    preproc.inputs.inputspec.fssubject_dir = c.surf_dir
    preproc.get_node('fwhm_input').iterables = ('fwhm', c.fwhm)
    preproc.inputs.inputspec.highpass = c.hpcutoff / (2 * c.TR)
    preproc.inputs.inputspec.num_noise_components = c.num_noise_components
    preproc.crash_dir = c.crash_dir
    preproc.inputs.inputspec.ad_normthresh = c.norm_thresh
    preproc.inputs.inputspec.ad_zthresh = c.z_thresh
    preproc.inputs.inputspec.tr = c.TR
    preproc.inputs.inputspec.do_slicetime = c.do_slicetiming
    preproc.inputs.inputspec.regress_before_PCA = c.regress_before_PCA

    if c.do_slicetiming:
        preproc.inputs.inputspec.sliceorder = c.SliceOrder
    else:
        preproc.inputs.inputspec.sliceorder = None
    preproc.inputs.inputspec.compcor_select = c.compcor_select

    # make connections
    modelflow.connect(infosource, 'subject_id', sinkd, 'container')
    modelflow.connect(infosource,
                      ('subject_id', get_substitutions, c.use_fieldmap), sinkd,
                      'substitutions')
    modelflow.connect(infosource, 'subject_id', dataflow, 'subject_id')
    modelflow.connect(infosource, 'subject_id', preproc,
                      'inputspec.fssubject_id')
    modelflow.connect(dataflow, 'func', preproc, 'inputspec.func')
    modelflow.connect(preproc, 'outputspec.mean', sinkd,
                      'preproc.motion.reference')
    modelflow.connect(preproc, 'outputspec.motion_parameters', sinkd,
                      'preproc.motion')
    modelflow.connect(preproc, 'outputspec.realigned_files', sinkd,
                      'preproc.motion.realigned')
    modelflow.connect(preproc, 'outputspec.mean', sinkd, 'preproc.meanfunc')
    #modelflow.connect(preproc, 'plot_motion.out_file',
    #                  sinkd, 'preproc.motion.@plots')
    modelflow.connect(preproc, 'outputspec.mask', sinkd, 'preproc.mask')
    modelflow.connect(preproc, 'outputspec.outlier_files', sinkd,
                      'preproc.art')
    modelflow.connect(preproc, 'outputspec.intensity_files', sinkd,
                      'preproc.art.@intensity')
    modelflow.connect(preproc, 'outputspec.combined_motion', sinkd,
                      'preproc.art.@norm')
    modelflow.connect(preproc, 'outputspec.outlier_stat_files', sinkd,
                      'preproc.art.@stats')
    modelflow.connect(preproc, 'outputspec.reg_file', sinkd, 'preproc.bbreg')
    modelflow.connect(preproc, 'outputspec.reg_cost', sinkd,
                      'preproc.bbreg.@reg_cost')
    modelflow.connect(preproc, 'outputspec.highpassed_files', sinkd,
                      'preproc.highpass')
    modelflow.connect(preproc, 'outputspec.smoothed_files', sinkd,
                      'preproc.smooth')
    modelflow.connect(preproc, 'outputspec.tsnr_file', sinkd, 'preproc.tsnr')
    modelflow.connect(preproc, 'outputspec.csf_mask', sinkd,
                      'preproc.compcor.@acompcor')
    modelflow.connect(preproc, 'outputspec.noise_mask', sinkd,
                      'preproc.compcor.@tcompcor')
    modelflow.connect(preproc, 'outputspec.tsnr_detrended', sinkd,
                      'preproc.tsnr.@detrended')
    modelflow.connect(preproc, 'outputspec.stddev_file', sinkd,
                      'preproc.tsnr.@stddev')
    if c.do_zscore:
        modelflow.connect(preproc, 'outputspec.z_img', sinkd,
                          'preproc.z_image')
    modelflow.connect(preproc, 'outputspec.noise_components', sinkd,
                      'preproc.noise_components')
    modelflow.connect(preproc, 'outputspec.reg_fsl_file', sinkd,
                      'preproc.bbreg.@fsl')

    modelflow.base_dir = os.path.join(c.working_dir, 'work_dir')
    return modelflow
Ejemplo n.º 2
0
def prep_workflow(c):
    import nipype.pipeline.engine as pe
    import nipype.interfaces.utility as util
    import nipype.interfaces.io as nio

    fieldmap=c.use_fieldmap
    infosource = pe.Node(util.IdentityInterface(fields=['subject_id']),
                         name='subject_names')
    if not c.test_mode:
        infosource.iterables = ('subject_id', c.subjects)
    else:
        infosource.iterables = ('subject_id', c.subjects[:1])

    modelflow = pe.Workflow(name='preproc')
    
    # make a data sink
    sinkd = get_datasink(c.sink_dir, c.fwhm)
    
    # generate preprocessing workflow
    #dataflow = c.create_dataflow()

    # create a node to obtain the functional images
    dataflow = get_dataflow(c)

    if fieldmap:
        preproc = create_prep_fieldmap()
        preproc.inputs.inputspec.FM_Echo_spacing = c.echospacing
        preproc.inputs.inputspec.FM_TEdiff = c.TE_diff
        preproc.inputs.inputspec.FM_sigma = c.sigma
        
        #datasource_fieldmap = c.create_fieldmap_dataflow()
        datasource_fieldmap = pe.Node(nio.DataGrabber(infields=['subject_id'],
                                                      outfields=['mag',
                                                                 'phase']),
                                      name = "fieldmap_datagrabber")
        datasource_fieldmap.inputs.base_directory = c.field_dir
        datasource_fieldmap.inputs.sort_filelist = True
        datasource_fieldmap.inputs.template ='*'
        datasource_fieldmap.inputs.field_template = dict(mag=c.magnitude_template,
                                                         phase=c.phase_template)
        datasource_fieldmap.inputs.template_args = dict(mag=[['subject_id']],
                                                        phase=[['subject_id']])
        
        
        modelflow.connect(infosource, 'subject_id',
                          datasource_fieldmap, 'subject_id')
        modelflow.connect(datasource_fieldmap,'mag',
                          preproc,'fieldmap_input.magnitude_file')
        modelflow.connect(datasource_fieldmap,'phase',
                          preproc,'fieldmap_input.phase_file')
        modelflow.connect(preproc, 'outputspec.FM_unwarped_mean',
                          sinkd, 'preproc.fieldmap.@unwarped_mean')
        modelflow.connect(preproc, 'outputspec.FM_unwarped_epi',
                          sinkd, 'preproc.fieldmap.@unwarped_epi')
    else:
        preproc = create_prep()

    if not c.do_zscore:
        z_score = preproc.get_node('z_score')
        preproc.remove_nodes([z_score])

    preproc.inputs.inputspec.motion_correct_node = c.motion_correct_node

    preproc.inputs.inputspec.realign_parameters = {"loops":c.loops,
                                                        "speedup":c.speedup}
    preproc.inputs.inputspec.timepoints_to_remove = c.timepoints_to_remove
    preproc.inputs.inputspec.smooth_type = c.smooth_type
    preproc.inputs.inputspec.surface_fwhm = c.surface_fwhm
    preproc.inputs.inputspec.fssubject_dir = c.surf_dir
    preproc.get_node('fwhm_input').iterables = ('fwhm', c.fwhm)
    preproc.inputs.inputspec.highpass = c.hpcutoff/(2*c.TR)
    preproc.inputs.inputspec.num_noise_components = c.num_noise_components
    preproc.crash_dir = c.crash_dir
    preproc.inputs.inputspec.ad_normthresh = c.norm_thresh
    preproc.inputs.inputspec.ad_zthresh = c.z_thresh
    preproc.inputs.inputspec.tr = c.TR
    preproc.inputs.inputspec.do_slicetime = c.do_slicetiming
    preproc.inputs.inputspec.regress_before_PCA = c.regress_before_PCA

    if c.do_slicetiming:
        preproc.inputs.inputspec.sliceorder = c.SliceOrder
    else:
        preproc.inputs.inputspec.sliceorder = None
    preproc.inputs.inputspec.compcor_select = c.compcor_select
    
    # make connections
    modelflow.connect(infosource, 'subject_id',
                      sinkd, 'container')
    modelflow.connect(infosource, ('subject_id', get_substitutions,
                                   c.use_fieldmap),
                      sinkd, 'substitutions')
    modelflow.connect(infosource, 'subject_id',
                      dataflow, 'subject_id')
    modelflow.connect(infosource, 'subject_id', 
                      preproc, 'inputspec.fssubject_id')
    modelflow.connect(dataflow,'func',
                      preproc, 'inputspec.func')
    modelflow.connect(preproc, 'outputspec.mean',
                      sinkd, 'preproc.motion.reference')
    modelflow.connect(preproc, 'outputspec.motion_parameters',
                      sinkd, 'preproc.motion')
    modelflow.connect(preproc, 'outputspec.realigned_files',
                      sinkd, 'preproc.motion.realigned')
    modelflow.connect(preproc, 'outputspec.mean',
                      sinkd, 'preproc.meanfunc')
    #modelflow.connect(preproc, 'plot_motion.out_file',
    #                  sinkd, 'preproc.motion.@plots')
    modelflow.connect(preproc, 'outputspec.mask',
                      sinkd, 'preproc.mask')
    modelflow.connect(preproc, 'outputspec.outlier_files',
                      sinkd, 'preproc.art')
    modelflow.connect(preproc, 'outputspec.intensity_files',
                      sinkd, 'preproc.art.@intensity')
    modelflow.connect(preproc, 'outputspec.combined_motion',
                      sinkd, 'preproc.art.@norm')
    modelflow.connect(preproc, 'outputspec.outlier_stat_files',
                      sinkd, 'preproc.art.@stats')
    modelflow.connect(preproc, 'outputspec.reg_file',
                      sinkd, 'preproc.bbreg')
    modelflow.connect(preproc, 'outputspec.reg_cost',
                      sinkd, 'preproc.bbreg.@reg_cost')
    modelflow.connect(preproc, 'outputspec.highpassed_files',
                      sinkd, 'preproc.highpass')
    modelflow.connect(preproc, 'outputspec.smoothed_files',
                      sinkd, 'preproc.smooth')
    modelflow.connect(preproc, 'outputspec.tsnr_file',
                      sinkd, 'preproc.tsnr')
    modelflow.connect(preproc, 'outputspec.csf_mask',
        sinkd, 'preproc.compcor.@acompcor')
    modelflow.connect(preproc, 'outputspec.noise_mask',
        sinkd, 'preproc.compcor.@tcompcor')
    modelflow.connect(preproc, 'outputspec.tsnr_detrended',
                      sinkd, 'preproc.tsnr.@detrended')
    modelflow.connect(preproc, 'outputspec.stddev_file',
                      sinkd, 'preproc.tsnr.@stddev')
    if c.do_zscore:
        modelflow.connect(preproc, 'outputspec.z_img',
                          sinkd, 'preproc.z_image')
    modelflow.connect(preproc, 'outputspec.noise_components',
                      sinkd, 'preproc.noise_components')
    modelflow.connect(preproc, 'outputspec.reg_fsl_file',
                      sinkd, 'preproc.bbreg.@fsl')    

    modelflow.base_dir = os.path.join(c.working_dir, 'work_dir')
    return modelflow
Ejemplo n.º 3
0
def prep_workflow(subjects,fieldmap):
    
    infosource = pe.Node(util.IdentityInterface(fields=['subject_id']),
                         name='subject_names')
    infosource.iterables = ('subject_id', subjects)

    modelflow = pe.Workflow(name='preproc')
    
    # make a data sink
    sinkd = get_datasink(c.sink_dir,c.fwhm)
    
    # generate preprocessing workflow
    dataflow = c.create_dataflow()

    if fieldmap:
        preproc = create_prep_fieldmap()
        preproc.inputs.inputspec.FM_Echo_spacing = c.echospacing
        preproc.inputs.inputspec.FM_TEdiff = c.TE_diff
        preproc.inputs.inputspec.FM_sigma = c.sigma
        datasource_fieldmap = c.create_fieldmap_dataflow()
        modelflow.connect(infosource, 'subject_id',
                          datasource_fieldmap, 'subject_id')
        modelflow.connect(datasource_fieldmap,'mag',
                          preproc,'fieldmap_input.magnitude_file')
        modelflow.connect(datasource_fieldmap,'phase',
                          preproc,'fieldmap_input.phase_file')
        modelflow.connect(preproc, 'outputspec.FM_unwarped_mean',
                          sinkd, 'preproc.fieldmap.@unwarped_mean')
        modelflow.connect(preproc, 'outputspec.FM_unwarped_epi',
                          sinkd, 'preproc.fieldmap.@unwarped_epi')
    else:
        preproc = create_prep()
    
    preproc.inputs.inputspec.fssubject_dir = c.surf_dir
    preproc.get_node('fwhm_input').iterables = ('fwhm',c.fwhm)
    preproc.inputs.inputspec.highpass = c.hpcutoff/(2*c.TR)
    preproc.inputs.inputspec.num_noise_components = c.num_noise_components
    preproc.crash_dir = c.crash_dir
    preproc.inputs.inputspec.ad_normthresh = c.norm_thresh
    preproc.inputs.inputspec.ad_zthresh = c.z_thresh
    preproc.inputs.inputspec.tr = c.TR
    preproc.inputs.inputspec.interleaved = c.Interleaved
    preproc.inputs.inputspec.sliceorder = c.SliceOrder
    preproc.inputs.inputspec.compcor_select = c.compcor_select
    
    # make connections
    modelflow.connect(infosource, 'subject_id',
                      sinkd, 'container')
    modelflow.connect(infosource, ('subject_id', get_substitutions, c.use_fieldmap),
                      sinkd, 'substitutions')
    modelflow.connect(infosource, 'subject_id',
                      dataflow, 'subject_id')
    modelflow.connect(infosource, 'subject_id', 
                      preproc, 'inputspec.fssubject_id')
    modelflow.connect(dataflow,'func',
                      preproc, 'inputspec.func')
    modelflow.connect(preproc, 'outputspec.mean',
                      sinkd, 'preproc.motion.reference')
    modelflow.connect(preproc, 'outputspec.motion_parameters',
                      sinkd, 'preproc.motion')
    modelflow.connect(preproc, 'outputspec.realigned_files',
                      sinkd, 'preproc.motion.realigned')
    modelflow.connect(preproc, 'outputspec.mean',
                      sinkd, 'preproc.meanfunc')
    modelflow.connect(preproc, 'plot_motion.out_file',
                      sinkd, 'preproc.motion.@plots')
    modelflow.connect(preproc, 'outputspec.mask',
                      sinkd, 'preproc.mask')
    modelflow.connect(preproc, 'outputspec.outlier_files',
                      sinkd, 'preproc.art')
    modelflow.connect(preproc, 'outputspec.combined_motion',
                      sinkd, 'preproc.art.@stats')
    modelflow.connect(preproc, 'outputspec.reg_file',
                      sinkd, 'preproc.bbreg')
    modelflow.connect(preproc, 'outputspec.reg_cost',
                      sinkd, 'preproc.bbreg.@reg_cost')
    modelflow.connect(preproc, 'outputspec.highpassed_files',
                      sinkd, 'preproc.highpass')
    modelflow.connect(preproc, 'outputspec.smoothed_files',
                      sinkd, 'preproc.smooth')
    modelflow.connect(preproc, 'outputspec.tsnr_file',
                      sinkd, 'preproc.tsnr')
    modelflow.connect(preproc, 'outputspec.tsnr_detrended',
                      sinkd, 'preproc.tsnr.@detrended')
    modelflow.connect(preproc, 'outputspec.stddev_file',
                      sinkd, 'preproc.tsnr.@stddev')
    modelflow.connect(preproc, 'outputspec.z_img', 
                      sinkd, 'preproc.z_image')
    modelflow.connect(preproc, 'outputspec.noise_components',
                      sinkd, 'preproc.noise_components')
    

    modelflow.base_dir = os.path.join(c.working_dir,'work_dir')
    return modelflow