Exemple #1
0
def test_GLM_inputs():
    input_map = dict(
        args=dict(argstr='%s', ),
        contrasts=dict(argstr='-c %s', ),
        dat_norm=dict(argstr='--dat_norm', ),
        demean=dict(argstr='--demean', ),
        des_norm=dict(argstr='--des_norm', ),
        design=dict(
            argstr='-d %s',
            mandatory=True,
            position=2,
        ),
        dof=dict(argstr='--dof=%d', ),
        environ=dict(
            nohash=True,
            usedefault=True,
        ),
        ignore_exception=dict(
            nohash=True,
            usedefault=True,
        ),
        in_file=dict(
            argstr='-i %s',
            mandatory=True,
            position=1,
        ),
        mask=dict(argstr='-m %s', ),
        out_cope=dict(argstr='--out_cope=%s', ),
        out_data_name=dict(argstr='--out_data=%s', ),
        out_f_name=dict(argstr='--out_f=%s', ),
        out_file=dict(
            argstr='-o %s',
            keep_extension=True,
            name_source='in_file',
            name_template='%s_glm',
            position=3,
        ),
        out_p_name=dict(argstr='--out_p=%s', ),
        out_pf_name=dict(argstr='--out_pf=%s', ),
        out_res_name=dict(argstr='--out_res=%s', ),
        out_sigsq_name=dict(argstr='--out_sigsq=%s', ),
        out_t_name=dict(argstr='--out_t=%s', ),
        out_varcb_name=dict(argstr='--out_varcb=%s', ),
        out_vnscales_name=dict(argstr='--out_vnscales=%s', ),
        out_z_name=dict(argstr='--out_z=%s', ),
        output_type=dict(),
        terminal_output=dict(nohash=True, ),
        var_norm=dict(argstr='--vn', ),
    )
    inputs = GLM.input_spec()

    for key, metadata in input_map.items():
        for metakey, value in metadata.items():
            yield assert_equal, getattr(inputs.traits()[key], metakey), value
def test_GLM_outputs():
    output_map = dict(out_cope=dict(),
    out_data=dict(),
    out_f=dict(),
    out_file=dict(),
    out_p=dict(),
    out_pf=dict(),
    out_res=dict(),
    out_sigsq=dict(),
    out_t=dict(),
    out_varcb=dict(),
    out_vnscales=dict(),
    out_z=dict(),
    )
    outputs = GLM.output_spec()

    for key, metadata in output_map.items():
        for metakey, value in metadata.items():
            yield assert_equal, getattr(outputs.traits()[key], metakey), value
Exemple #3
0
def test_GLM_outputs():
    output_map = dict(
        out_cope=dict(),
        out_data=dict(),
        out_f=dict(),
        out_file=dict(),
        out_p=dict(),
        out_pf=dict(),
        out_res=dict(),
        out_sigsq=dict(),
        out_t=dict(),
        out_varcb=dict(),
        out_vnscales=dict(),
        out_z=dict(),
    )
    outputs = GLM.output_spec()

    for key, metadata in output_map.items():
        for metakey, value in metadata.items():
            yield assert_equal, getattr(outputs.traits()[key], metakey), value
Exemple #4
0
    orig = genfromtxt(orig, delimiter='  ', dtype=None, skip_header=0)
    new = 'func_roi_ts.txt'
    savetxt(new, orig, delimiter='  ')

    new_file = abspath(new)
    return (new_file)


converthex = Node(name='converthex',
                  interface=Function(input_names=['orig'],
                                     output_names=['new_file'],
                                     function=converthex))

# model ROI connectivity
glm = Node(GLM(out_file='betas.nii', out_cope='cope.nii'),
           name='glm',
           iterfield='design')

# In[4]:

sbc1_workflow = Workflow(name='sbc1_workflow')
sbc1_workflow.connect([
    (infosource, selectfiles, [('subject_id', 'subject_id')]),
    (selectfiles, ROI_timeseries, [('orig_func', 'in_file')]),
    (infosource, ROI_timeseries, [('ROIs', 'mask')]),
    (ROI_timeseries, converthex, [('out_file', 'orig')]),
    (converthex, glm, [('new_file', 'design')]),
    (selectfiles, glm, [('orig_func', 'in_file')]),
    (converthex, datasink, [('new_file', 'roi_ts')]),
    (glm, datasink, [('out_cope', 'glm_seed_copes')]),
Exemple #5
0
    noise_file = 'noise_matrix.txt'
    savetxt(noise_file, noise_matrix, delimiter='\t')
    noise_filepath = path.abspath(noise_file)

    return (noise_filepath)


noise_mat = Node(name='noise_mat',
                 interface=Function(input_names=[
                     'vols_to_censor', 'motion_params', 'comp_noise'
                 ],
                                    output_names=['noise_filepath'],
                                    function=create_noise_matrix))

denoise = Node(GLM(out_res_name='denoised_residuals.nii',
                   out_data_name='denoised_func.nii'),
               name='denoise')


# band pass filtering- all rates are in Hz (1/TR or samples/second)
def bandpass_filter(in_file, lowpass, highpass, TR):
    import numpy as np
    import nibabel as nb
    from os import path
    from nipype.interfaces.afni.preprocess import Bandpass
    from nipype import config, logging
    config.enable_debug_mode()
    logging.update_logging(config)

    out_file = 'func_filtered.nii'
    bp = Bandpass()
Exemple #6
0
def rs_preprocess(in_file, fwhm, work_dir, output_dir):

    from nipype.workflows.fmri.fsl.preprocess import create_susan_smooth
    from nipype.interfaces.fsl.model import GLM
    from nipype.interfaces import fsl as fsl


    # define nodes and workflows
    rs_preproc_workflow = pe.Workflow(name="rs_preproc_workflow")
    rs_preproc_workflow.base_dir = work_dir

    inputnode = pe.Node(interface=util.IdentityInterface(fields=['func', 'fwhm']), name='inputspec')
    inputnode.inputs.func = in_file
    inputnode.inputs.fwhm = fwhm

    #make a brain mask
    immask = pe.Node(interface=fsl.ImageMaths(op_string = '-abs -bin -Tmin'), name='immask')
    rs_preproc_workflow.connect(inputnode, 'func', immask, 'in_file')

    #calculate mean image from smoothed data, for adding back after GSR
    immean = pe.Node(interface=fsl.ImageMaths(op_string = '-Tmean'), name='immean')
    rs_preproc_workflow.connect(inputnode, 'func', immean, 'in_file')

    #get time-series for GSR
    meants = pe.Node(interface=fsl.utils.ImageMeants(), name='meants')
    rs_preproc_workflow.connect(inputnode, 'func', meants, 'in_file')
    rs_preproc_workflow.connect(immask, 'out_file', meants, 'mask')

    #removing global signal
    glm = pe.Node(interface=GLM(), name='glm')
    glm.inputs.out_res_name = op.join(work_dir, 'res4d.nii.gz')
    rs_preproc_workflow.connect(inputnode, 'func', glm, 'in_file')
    rs_preproc_workflow.connect(immask, 'out_file', glm, 'mask')
    rs_preproc_workflow.connect(meants, 'out_file', glm, 'design')

    #add mean back to GSR'ed image
    maths = pe.Node(interface=fsl.maths.BinaryMaths(operation = 'add'), name='maths')
    rs_preproc_workflow.connect(glm, 'out_res', maths, 'in_file')
    rs_preproc_workflow.connect(immean, 'out_file', maths, 'operand_file')

    #do the smoothing
    smooth = create_susan_smooth()
    rs_preproc_workflow.connect(maths, 'out_file', smooth, 'inputnode.in_files')
    rs_preproc_workflow.connect(inputnode, 'fwhm', smooth, 'inputnode.fwhm')
    rs_preproc_workflow.connect(immask, 'out_file', smooth, 'inputnode.mask_file')

    datasink = pe.Node(nio.DataSink(), name='sinker')
    datasink.inputs.base_directory = work_dir

    rs_preproc_workflow.connect(maths, 'out_file', datasink, 'gsr')
    rs_preproc_workflow.connect(immask, 'out_file', datasink, 'mask')
    rs_preproc_workflow.connect(smooth.get_node('smooth'), ('smoothed_file', pickfirst), datasink, 'gsr_smooth')

    rs_preproc_workflow.run()

    #copy data to directory
    gsr_fn = glob(op.join(work_dir, 'gsr', '*.nii.gz'))[0]
    mask_fn = glob(op.join(work_dir, 'mask', '*.nii.gz'))[0]
    gsr_smooth_fn = glob(op.join(work_dir, 'gsr_smooth', '*', '*.nii.gz'))[0]
    gsr_fn2 = op.join(output_dir, '{0}.nii.gz'.format(op.basename(in_file).split('.')[0]))
    mask_fn2 = op.join(output_dir, '{0}_mask.nii.gz'.format(op.basename(in_file).split('.')[0]))
    gsr_smooth_fn2 = op.join(output_dir, '{0}_smooth.nii.gz'.format(op.basename(in_file).split('.')[0]))

    shutil.copyfile(gsr_fn, gsr_fn2)
    shutil.copyfile(mask_fn, mask_fn2)
    shutil.copyfile(gsr_smooth_fn, gsr_smooth_fn2)

    shutil.rmtree(work_dir)
def test_GLM_inputs():
    input_map = dict(args=dict(argstr='%s',
    ),
    contrasts=dict(argstr='-c %s',
    ),
    dat_norm=dict(argstr='--dat_norm',
    ),
    demean=dict(argstr='--demean',
    ),
    des_norm=dict(argstr='--des_norm',
    ),
    design=dict(argstr='-d %s',
    mandatory=True,
    position=2,
    ),
    dof=dict(argstr='--dof=%d',
    ),
    environ=dict(nohash=True,
    usedefault=True,
    ),
    ignore_exception=dict(nohash=True,
    usedefault=True,
    ),
    in_file=dict(argstr='-i %s',
    mandatory=True,
    position=1,
    ),
    mask=dict(argstr='-m %s',
    ),
    out_cope=dict(argstr='--out_cope=%s',
    ),
    out_data_name=dict(argstr='--out_data=%s',
    ),
    out_f_name=dict(argstr='--out_f=%s',
    ),
    out_file=dict(argstr='-o %s',
    keep_extension=True,
    name_source='in_file',
    name_template='%s_glm',
    position=3,
    ),
    out_p_name=dict(argstr='--out_p=%s',
    ),
    out_pf_name=dict(argstr='--out_pf=%s',
    ),
    out_res_name=dict(argstr='--out_res=%s',
    ),
    out_sigsq_name=dict(argstr='--out_sigsq=%s',
    ),
    out_t_name=dict(argstr='--out_t=%s',
    ),
    out_varcb_name=dict(argstr='--out_varcb=%s',
    ),
    out_vnscales_name=dict(argstr='--out_vnscales=%s',
    ),
    out_z_name=dict(argstr='--out_z=%s',
    ),
    output_type=dict(),
    terminal_output=dict(nohash=True,
    ),
    var_norm=dict(argstr='--vn',
    ),
    )
    inputs = GLM.input_spec()

    for key, metadata in input_map.items():
        for metakey, value in metadata.items():
            yield assert_equal, getattr(inputs.traits()[key], metakey), value
Exemple #8
0
    from os.path import abspath
    
    orig = genfromtxt(orig, delimiter='  ', dtype=None, skip_header=0)
    new = 'func_roi_ts.txt'
    savetxt(new, orig, delimiter='  ')
    
    new_file = abspath(new)
    return(new_file)

converthex = Node(name='converthex', 
                  interface=Function(input_names=['orig'], 
                                     output_names=['new_file'], 
                                     function=converthex))

# model ROI connectivity
glm = Node(GLM(out_file='betas.nii',out_cope='cope.nii'), name='glm', iterfield='design')


# In[4]:


sbc1_workflow2 = Workflow(name='sbc1_workflow2')
sbc1_workflow2.connect([(infosource,selectfiles,[('subject_id','subject_id')]),
                        (selectfiles,ROI_timeseries,[('orig_func','in_file')]),
                        (infosource,ROI_timeseries,[('ROIs','mask')]),
                        (ROI_timeseries,converthex,[('out_file','orig')]),
                        (converthex,glm,[('new_file','design')]),
                        (selectfiles,glm,[('orig_func','in_file')]),
                        (converthex, datasink, [('new_file','roi_ts')]),
                        (glm,datasink,[('out_cope','glm_seed_copes')]),
                        (glm,datasink,[('out_file','glm_betas')])