def create_corr_ts(name='corr_ts'):

    corr_ts = Workflow(name='corr_ts')
    # Define nodes
    inputnode = Node(util.IdentityInterface(fields=[
        'ts',
        'hc_mask',
    ]),
                     name='inputnode')

    outputnode = Node(interface=util.IdentityInterface(
        fields=['corrmap', 'corrmap_z', 'hc_ts']),
                      name='outputnode')

    #extract mean time series of mask
    mean_TS = MapNode(interface=fsl.ImageMeants(),
                      name="mean_TS",
                      iterfield='mask')
    #iterate over using Eigenvalues or mean
    #mean_TS.iterables = ("eig", [True, False])
    #mean_TS.inputs.order = 1
    #mean_TS.inputs.show_all = True
    mean_TS.inputs.eig = False  #use only mean of ROI
    mean_TS.inputs.out_file = "TS.1D"

    #calculate correlation of all voxels with seed voxel
    corr_TS = MapNode(interface=afni.Fim(),
                      name='corr_TS',
                      iterfield='ideal_file')
    corr_TS.inputs.out = 'Correlation'
    corr_TS.inputs.out_file = "corr.nii.gz"

    apply_FisherZ = MapNode(interface=afni.Calc(),
                            name="apply_FisherZ",
                            iterfield='in_file_a')
    apply_FisherZ.inputs.expr = 'log((1+a)/(1-a))/2'  #log = ln
    apply_FisherZ.inputs.out_file = 'corr_Z.nii.gz'
    apply_FisherZ.inputs.outputtype = "NIFTI"

    corr_ts.connect([(inputnode, mean_TS, [('hc_mask', 'mask')]),
                     (inputnode, mean_TS, [('ts', 'in_file')]),
                     (mean_TS, outputnode, [('out_file', 'hc_ts')]),
                     (inputnode, corr_TS, [('ts', 'in_file')]),
                     (mean_TS, corr_TS, [('out_file', 'ideal_file')]),
                     (corr_TS, apply_FisherZ, [('out_file', 'in_file_a')]),
                     (corr_TS, outputnode, [('out_file', 'corrmap')]),
                     (apply_FisherZ, outputnode, [('out_file', 'corrmap_z')])])

    return corr_ts
Exemple #2
0
def test_fim():
    input_map = dict(
        args=dict(argstr='%s', ),
        environ=dict(usedefault=True, ),
        fim_thr=dict(argstr='-fim_thr %f', ),
        ideal_file=dict(
            argstr='-ideal_file %s',
            mandatory=True,
        ),
        ignore_exception=dict(usedefault=True, ),
        in_file=dict(
            argstr=' -input %s',
            mandatory=True,
        ),
        out=dict(argstr='-out %s', ),
        out_file=dict(argstr='-bucket %s', ),
        outputtype=dict(),
    )
    instance = afni.Fim()
    for key, metadata in input_map.items():
        for metakey, value in metadata.items():
            yield assert_equal, getattr(instance.inputs.traits()[key],
                                        metakey), value
def roi2name(coord):
    return 'roi_sphere_%s_%s_%s.nii.gz' % (str(coord[0]), str(
        coord[1]), str(coord[2]))


wf.connect(roi_infosource, ("roi", roi2exp), sphere, "expr")
wf.connect(roi_infosource, ("roi", roi2name), sphere, "out_file")
wf.connect(sphere, "out_file", ds, "@sphere")

extract_timeseries = pe.Node(afni.Maskave(), name="extract_timeseries")
extract_timeseries.inputs.quiet = True
wf.connect(sphere, "out_file", extract_timeseries, "mask")
wf.connect(datasource, 'EPI_bandpassed', extract_timeseries, "in_file")

correlation_map = pe.Node(afni.Fim(), name="correlation_map")
correlation_map.inputs.out = "Correlation"
correlation_map.inputs.outputtype = "NIFTI_GZ"
correlation_map.inputs.out_file = "corr_map.nii.gz"
correlation_map.inputs.fim_thr = 0.0001
wf.connect(extract_timeseries, "out_file", correlation_map, "ideal_file")
wf.connect(datasource, 'EPI_bandpassed', correlation_map, "in_file")


def add_arg_fim_mask(input):
    return ('-mask %s' % input)


wf.connect(automask, ('out_file', add_arg_fim_mask), correlation_map, 'args')

z_trans = pe.Node(interface=afni.Calc(), name='z_trans')
Exemple #4
0
def create_sca_wf(working_dir, name='sca'):
    afni.base.AFNICommand.set_default_output_type('NIFTI_GZ')
    fsl.FSLCommand.set_default_output_type('NIFTI_GZ')

    sca_wf = Workflow(name=name)
    sca_wf.base_dir = os.path.join(working_dir)

    # inputnode
    inputnode = Node(util.IdentityInterface(
        fields=['rs_preprocessed', 'MNI_template', 'roi_coords']),
                     name='inputnode')

    # outputnode
    outputnode = Node(
        util.IdentityInterface(fields=['seed_based_z', 'roi_img']),
        name='outputnode')

    # epi_mask = Node(interface=afni.Automask(), name='epi_mask')
    # sca_wf.connect(inputnode, 'rs_preprocessed', epi_mask, 'in_file')
    # sca_wf.connect(epi_mask, 'out_file', outputnode, 'functional_mask')

    def roi2exp_fct(coord):
        return 'step(4-(x%+d)*(x%+d)-(y%+d)*(y%+d)-(z%+d)*(z%+d))' % (
            coord[0], coord[0], coord[1], coord[1], -coord[2], -coord[2])

    roi2exp = Node(util.Function(input_names=['coord'],
                                 output_names=['expr'],
                                 function=roi2exp_fct),
                   name='roi2exp')
    sca_wf.connect(inputnode, 'roi_coords', roi2exp, 'coord')

    point = Node(afni.Calc(), name='point')
    sca_wf.connect(inputnode, 'MNI_template', point, 'in_file_a')
    point.inputs.outputtype = 'NIFTI_GZ'
    point.inputs.out_file = 'roi_point.nii.gz'
    sca_wf.connect(roi2exp, 'expr', point, 'expr')

    def format_filename(roi_str):
        import string
        valid_chars = '-_.%s%s' % (string.ascii_letters, string.digits)
        return 'roi_' + ''.join(c for c in str(roi_str).replace(',', '_')
                                if c in valid_chars) + '_roi.nii.gz'

    sphere = Node(fsl.ImageMaths(), name='sphere')
    sphere.inputs.out_data_type = 'float'
    sphere.inputs.op_string = '-kernel sphere 4 -fmean -bin'
    sca_wf.connect(point, 'out_file', sphere, 'in_file')
    sca_wf.connect(inputnode, ('roi_coords', format_filename), sphere,
                   'out_file')
    sca_wf.connect(sphere, 'out_file', outputnode, 'roi_img')

    extract_timeseries = Node(afni.Maskave(), name='extract_timeseries')
    extract_timeseries.inputs.quiet = True
    sca_wf.connect(sphere, 'out_file', extract_timeseries, 'mask')
    sca_wf.connect(inputnode, 'rs_preprocessed', extract_timeseries, 'in_file')

    correlation_map = Node(afni.Fim(), name='correlation_map')
    correlation_map.inputs.out = 'Correlation'
    correlation_map.inputs.outputtype = 'NIFTI_GZ'
    correlation_map.inputs.out_file = 'corr_map.nii.gz'
    sca_wf.connect(extract_timeseries, 'out_file', correlation_map,
                   'ideal_file')
    sca_wf.connect(inputnode, 'rs_preprocessed', correlation_map, 'in_file')

    z_trans = Node(interface=afni.Calc(), name='z_trans')
    z_trans.inputs.expr = 'log((1+a)/(1-a))/2'
    z_trans.inputs.outputtype = 'NIFTI_GZ'
    sca_wf.connect(correlation_map, 'out_file', z_trans, 'in_file_a')
    sca_wf.connect(z_trans, 'out_file', outputnode, 'seed_based_z')

    sca_wf.write_graph(dotfilename='sca', graph2use='flat', format='pdf')

    return sca_wf