예제 #1
0
def run_group_analysis(c):

    wfname = 'resting_preproc' + '_group_analysis'
    workflow = pe.Workflow(name=wfname)
    workflow.base_dir = c.workingDirectory
    workflow.crash_dir = c.crashLogDirectory
    workflow.config['execution'] = {'hash_method': 'timestamp'}

    """
        FSL Group Analysis
    """
    if c.derivatives[6]:
        """
                grab the Group Analysis Data 
        """
        sublist, modelist, dervlist, labelist, template_dict, template_args = getGroupAnalysisInputs(c)

        gp_flow = create_gp_dataflow(c.sinkDirectory, modelist,
                                     dervlist, labelist, template_dict,
                                     template_args, 'gpflow')

        gppreproc = get_workflow('group_analysis', c)

        workflow.connect(gp_flow, 'gpflow.mat',
                     gppreproc, 'inputspec.mat_file')
def run_group_analysis(rest_session_list, anat_session_list, seed_list, c):

    wfname = 'resting_preproc' + '_group_analysis'
    workflow = pe.Workflow(name=wfname)
    workflow.base_dir = c.workingDirectory
    workflow.crash_dir = c.crashLogDirectory
    workflow.config['execution'] = {'hash_method': 'timestamp'}

    """
        FSL Group Analysis
    """
    if c.derivatives[6]:
        """
                grab the Group Analysis Data 
        """
        modelist, dervlist, labelist, template_dict, template_args = getGroupAnalysisInputs(c)

        gp_flow = create_gp_dataflow(c.sinkDirectory, modelist,
                                     dervlist, labelist, template_dict,
                                     template_args, 'gpflow')

        gppreproc = get_workflow('group_analysis', c)

        workflow.connect(gp_flow, 'gpflow.mat',
                     gppreproc, 'inputspec.mat_file')
        workflow.connect(gp_flow, 'gpflow.con',
                     gppreproc, 'inputspec.con_file')
        workflow.connect(gp_flow, 'gpflow.fts',
                     gppreproc, 'inputspec.fts_file')
        workflow.connect(gp_flow, 'gpflow.grp',
                     gppreproc, 'inputspec.grp_file')
        workflow.connect(gp_flow, 'gpflow.derv',
                     gppreproc, 'inputspec.zmap_files')


        gp_datasink = create_gp_datasink(c.sinkDirectory)
        workflow.connect(gp_flow, 'inputnode.label', gp_datasink, 'container')
        group_analysis_sink(workflow, gp_datasink, gppreproc)
def prep_workflow(sub, rest_session_list, anat_session_list, seed_list, c):



    wfname = 'resting_preproc_sge'
    workflow = pe.Workflow(name=wfname)
    workflow.base_dir = c.workingDirectory
    workflow.crash_dir = c.crashLogDirectory
    workflow.config['execution'] = {'hash_method': 'timestamp'}


    """
        BASIC and ALL preprocessing paths implemented below
    """

    """
        grab the subject data
    """
    flowAnatFunc = create_anat_func_dataflow(sub,
                                              rest_session_list,
                                              anat_session_list,
                                              c.subjectDirectory,
                                              c.anatTemplate,
                                              c.funcTemplate,
                                              c.anatTemplateList,
                                              c.funcTemplateList)


    if c.derivatives[6]:
        """
                grab the Group Analysis Data 
        """
        modelist, dervlist, labelist, template_dict, template_args = getGroupAnalysisInputs(c)

        gp_flow = create_gp_dataflow(c.sinkDirectory, modelist,
                                     dervlist, labelist, template_dict,
                                     template_args, 'gpflow')

    if c.derivatives[1]:
        """
            grab the seeds data
        """
        seedFlow = create_seed_dataflow(c.seedFile)

    if c.derivatives[4]:
        """
            grab parcellation data for time series extraction
        """
        pflow = create_parc_dataflow(c.unitDefinitionsDirectory)

    if c.derivatives[5]:
        pflow = create_parc_dataflow(c.unitDefinitionsDirectory)

    if c.derivatives[5]:
        """
            grab mask data for time series extraction
        """
        mflow = create_mask_dataflow(c.voxelMasksDirectory)

    """
        Define workflows and set parameters
    """
    anatpreproc = get_workflow('anat', c)
    funcpreproc = get_workflow('func', c)
    regpreproc = get_workflow('reg', c)
    segpreproc = get_workflow('seg', c)
    scpreproc = get_workflow('sc', c)
    select = get_workflow('select', c)
    nuisancepreproc = get_workflow('nuisance', c)
    mprage_mni = get_workflow('mprage_in_mnioutputs', c)
    func_in_mni = get_workflow('func_in_mnioutputs', c)
    freq_filter = get_workflow('freq_filter', c)

    if c.derivatives[0]:
        alffpreproc = get_workflow('alff', c)

    if c.derivatives[1]:
        scapreproc = get_workflow('sca', c)

    if c.derivatives[2]:
        vmhcpreproc = get_workflow('vmhc', c)

    if c.derivatives[4] or c.derivatives[5]:
        tspreproc = get_workflow('ts', c)

    if c.derivatives[6]:
        gppreproc = get_workflow('group_analysis', c)
    """
        Calling datasink
    """
    datasink = create_datasink(c.sinkDirectory)
    workflow.connect(flowAnatFunc, 'inputnode.subject_id',
    datasink, 'container')
    """
        Make Connections
    """

    workflow.connect(flowAnatFunc, 'datasource.anat',
                     anatpreproc, 'inputspec.anat')
    workflow.connect(flowAnatFunc, 'datasource.rest',
                     funcpreproc, 'inputspec.rest')
    workflow.connect(funcpreproc, 'outputspec.example_func',
                     regpreproc, 'inputspec.example_func')
    workflow.connect(anatpreproc, 'outputspec.brain',
                     regpreproc, 'inputspec.brain')
    workflow.connect(anatpreproc, 'outputspec.reorient',
                     regpreproc, 'inputspec.reorient')
    workflow.connect(funcpreproc, 'outputspec.preprocessed_mask',
                     segpreproc, 'inputspec.preprocessed_mask')
    workflow.connect(anatpreproc, 'outputspec.brain',
                     segpreproc, 'inputspec.brain')
    workflow.connect(funcpreproc, 'outputspec.example_func',
                     segpreproc, 'inputspec.example_func')
    workflow.connect(regpreproc, 'outputspec.highres2example_func_mat',
                     segpreproc, 'inputspec.highres2example_func_mat')
    workflow.connect(regpreproc, 'outputspec.stand2highres_warp',
                     segpreproc, 'inputspec.stand2highres_warp')


    workflow.connect(segpreproc, 'outputspec.wm_mask',
                     nuisancepreproc, 'inputspec.wm_mask')
    workflow.connect(segpreproc, 'outputspec.csf_mask',
                     nuisancepreproc, 'inputspec.csf_mask')
    workflow.connect(segpreproc, 'outputspec.gm_mask',
                     nuisancepreproc, 'inputspec.gm_mask')

    """
        Get T1 outputs in MNI
    """
    workflow.connect(regpreproc, 'outputspec.highres2standard_warp',
                     mprage_mni, 'inputspec.highres2standard_warp')
    workflow.connect(anatpreproc, 'outputspec.reorient',
                     mprage_mni, 'inputspec.reorient')
    workflow.connect(anatpreproc, 'outputspec.brain',
                     mprage_mni, 'inputspec.brain')
    workflow.connect(segpreproc, 'outputspec.probability_maps',
                     mprage_mni, 'inputspec.probability_maps')
    workflow.connect(segpreproc, 'outputspec.mixeltype',
                     mprage_mni, 'inputspec.mixeltype')
    workflow.connect(segpreproc, 'outputspec.partial_volume_map',
                     mprage_mni, 'inputspec.partial_volume_map')
    workflow.connect(segpreproc, 'outputspec.partial_volume_files',
                    mprage_mni, 'inputspec.partial_volume_files')

    """
         Nuisance
    """
    workflow.connect(funcpreproc, 'outputspec.preprocessed',
                     nuisancepreproc, 'inputspec.realigned_file')
    workflow.connect(funcpreproc, 'outputspec.movement_parameters',
                     nuisancepreproc, 'inputspec.motion_components')

    if(c.nuisanceBandpassFreq):

        workflow.connect(nuisancepreproc, 'outputspec.residual_file',
                         freq_filter, 'realigned_file')

        workflow.connect(freq_filter, 'bandpassed_file',
                         scpreproc, 'inputspec.preprocessed')
        workflow.connect(freq_filter, 'bandpassed_file',
                         select, 'inputspec.preprocessed')
    else:
        workflow.connect(nuisancepreproc, 'outputspec.residual_file',
                         scpreproc, 'inputspec.preprocessed')
        workflow.connect(nuisancepreproc, 'outputspec.residual_file',
                         select, 'inputspec.preprocessed')

    workflow.connect(flowAnatFunc, 'datasource.rest',
                     scpreproc, 'inputspec.rest')
    workflow.connect(funcpreproc, 'outputspec.movement_parameters',
                     scpreproc, 'inputspec.movement_parameters')

    workflow.connect(scpreproc, 'outputspec.scrubbed_preprocessed',
                     select, 'inputspec.scrubbed_preprocessed')
    workflow.connect(funcpreproc, 'outputspec.movement_parameters',
                     select, 'inputspec.movement_parameters')
    workflow.connect(scpreproc, 'outputspec.scrubbed_movement_parameters',
                     select, 'inputspec.scrubbed_movement_parameters')
    """
        Get Func outputs in MNI
    """
    workflow.connect(regpreproc, 'outputspec.highres2standard_warp',
                     func_in_mni, 'inputspec.highres2standard_warp')
    workflow.connect(regpreproc, 'outputspec.example_func2highres_mat',
                     func_in_mni, 'inputspec.premat')
    workflow.connect(funcpreproc, 'outputspec.preprocessed_mask',
                     func_in_mni, 'inputspec.preprocessed_mask')

    workflow.connect(select, 'outputspec.preprocessed_selector',
                     func_in_mni, 'inputspec.residual_file')


    anat_sink(workflow,
              datasink,
              mprage_mni)
    func_sink(workflow,
              datasink,
              funcpreproc,
              func_in_mni)
    reg_sink(workflow,
             datasink,
             regpreproc)
    seg_sink(workflow,
             datasink,
             segpreproc,
             mprage_mni)
    scrubbing_sink(workflow,
                   datasink,
                   scpreproc)
    nuisance_sink(workflow,
                  datasink,
                  nuisancepreproc)

    if c.derivatives[0]:
        """
                ALFF/fALFF
        """
        workflow.connect(select, 'outputspec.preprocessed_selector',
                         alffpreproc, 'inputspec.rest_res')
        workflow.connect(funcpreproc, 'outputspec.preprocessed_mask',
                         alffpreproc, 'inputspec.rest_mask')
        workflow.connect(func_in_mni, 'outputspec.preprocessed_mask_mni',
                         alffpreproc, 'inputspec.rest_mask2standard')
        workflow.connect(regpreproc, 'outputspec.example_func2highres_mat',
                         alffpreproc, 'inputspec.premat')
        workflow.connect(regpreproc, 'outputspec.highres2standard_warp',
                         alffpreproc, 'inputspec.fieldcoeff_file')
        alff_sink(workflow,
                  datasink,
                  alffpreproc)


    if c.derivatives[1]:
        """
            SCA (Seed Based Correlation Analysis)
        """
        workflow.connect(seedFlow, 'out_file',
                         scapreproc, 'seed_list_input.seed_list')
        workflow.connect(regpreproc, 'outputspec.example_func2highres_mat',
                         scapreproc, 'inputspec.premat')

        workflow.connect(select, 'outputspec.preprocessed_selector',
                         scapreproc, 'inputspec.residual_file')
        workflow.connect(select, 'outputspec.preprocessed_selector',
                         scapreproc, 'inputspec.rest_res_filt')

        workflow.connect(regpreproc, 'outputspec.highres2standard_warp',
                         scapreproc, 'inputspec.fieldcoeff_file')
        workflow.connect(func_in_mni, 'outputspec.preprocessed_mask_mni',
                         scapreproc, 'inputspec.rest_mask2standard')
        sca_sink(workflow,
                 datasink,
                 scapreproc)


    if c.derivatives[2]:
        """
            VMHC (Voxel-Mirrored Homotopic Connectivity)
        """
        workflow.connect(nuisancepreproc, 'outputspec.residual_file',
                         vmhcpreproc, 'inputspec.rest_res')
        workflow.connect(anatpreproc, 'outputspec.reorient',
                         vmhcpreproc, 'inputspec.reorient')
        workflow.connect(anatpreproc, 'outputspec.brain',
                         vmhcpreproc, 'inputspec.brain')
        workflow.connect(regpreproc, 'outputspec.example_func2highres_mat',
                         vmhcpreproc, 'inputspec.example_func2highres_mat')

        vmhc_sink(workflow,
                  datasink,
                  vmhcpreproc)

    """
        Time Series Extraction, Voxel Based and Vertices based
        Generates CSV and NUMPY files
    """

    if c.derivatives[4] or c.derivatives[5]:
        workflow.connect(anatpreproc, 'outputspec.brain',
                         tspreproc, 'inputspec.brain')
        workflow.connect(anatpreproc, 'outputspec.reorient',
                         tspreproc, 'inputspec.reorient')
        workflow.connect(funcpreproc, 'outputspec.motion_correct',
                         tspreproc, 'inputspec.motion_correct')
        workflow.connect(regpreproc, 'outputspec.highres2standard_warp',
                         tspreproc, 'inputspec.warp_file')
        workflow.connect(regpreproc, 'outputspec.example_func2highres_mat',
                         tspreproc, 'inputspec.premat')

        workflow.connect(pflow, 'out_file',
                         tspreproc, 'getparc.parcelations')
        workflow.connect(mflow, 'out_file',
                         tspreproc, 'getmask.masks')

        timeseries_sink(workflow,
                        datasink,
                        tspreproc,
                        c.runSurfaceRegistraion)

    """
        FSL Group Analysis
    """
    if c.derivatives[6]:
        workflow.connect(gp_flow, 'gpflow.mat',
                     gppreproc, 'inputspec.mat_file')
        workflow.connect(gp_flow, 'gpflow.con',
                     gppreproc, 'inputspec.con_file')
        workflow.connect(gp_flow, 'gpflow.fts',
                     gppreproc, 'inputspec.fts_file')
        workflow.connect(gp_flow, 'gpflow.grp',
                     gppreproc, 'inputspec.grp_file')
        workflow.connect(gp_flow, 'gpflow.derv',
                     gppreproc, 'inputspec.zmap_files')


        gp_datasink = create_gp_datasink(c.sinkDirectory)
        workflow.connect(gp_flow, 'inputnode.label', gp_datasink, 'container')
        group_analysis_sink(workflow, gp_datasink, gppreproc)

    if(not c.runOnGrid):
        workflow.run(plugin='MultiProc',
                     plugin_args={'n_procs': c.numCoresPerSubject})
    else:
        template_str = """
#!/bin/bash
#$ -S /bin/bash
#$ -V
    """
        workflow.run(plugin='SGE',
                     plugin_args=dict(qsub_args=c.qsubArgs, template=template_str))

    workflow.write_graph()