コード例 #1
0
def nrrd2nii_pmap(in_file, output_prefix):
    from os.path import abspath as opap
    from nipype.interfaces.base import CommandLine
    from nipype.utils.filemanip import split_filename
    _, name, _ = split_filename(in_file)
    out_vol = experiment_dir + '/' + output_prefix + '/' + ('%s.nii.gz' % name)

    cmd = CommandLine(('DWIConvert --inputVolume %s --outputVolume %s'
                       ' --conversionMode NrrdToFSL') % (in_file, out_vol))

    print "NRRD->NIFTI:" + cmd.cmd
    cmd.run()
    return opap(out_vol), opap(out_bval), opap(out_bvec)
コード例 #2
0
def nrrd2nii_pmap(in_file, output_prefix):
    from os.path import abspath as opap
    from nipype.interfaces.base import CommandLine
    from nipype.utils.filemanip import split_filename
    _, name, _ = split_filename(in_file)
    out_vol = experiment_dir + '/' + output_prefix + '/' + ('%s.nii.gz' % name)

    cmd = CommandLine(('DWIConvert --inputVolume %s --outputVolume %s'
                       ' --conversionMode NrrdToFSL') % (in_file, out_vol))

    print "NRRD->NIFTI:" + cmd.cmd
    cmd.run()
    return opap(out_vol), opap(out_bval), opap(out_bvec)
コード例 #3
0
def nrrd2nii(in_file):
    from os.path import abspath as opap
    from nipype.interfaces.base import CommandLine
    from nipype.utils.filemanip import split_filename
    _, name, _ = split_filename(in_file)
    out_vol = '%s.nii.gz' % name
    out_bval = '%s.bval' % name
    out_bvec = '%s.bvec' % name
    cmd = CommandLine(
        ('DWIConvert --inputVolume %s --outputVolume %s --outputBValues %s'
         ' --outputBVectors %s --conversionMode NrrdToFSL') %
        (in_file, out_vol, out_bval, out_bvec))
    cmd.run()
    return opap(out_vol), opap(out_bval), opap(out_bvec)
コード例 #4
0
ファイル: mvpa_preproc.py プロジェクト: mikbuch/pymri
def create_realign_reference(run, whichvol_glob, name="realignref"):
    """
    run (int): run's number

    whichvol_glob: 'first' or 'middle' or 'last' or
        'mean', if 'mean' was chosed for run then whichvol_glob does't matter
    """
    realignref = Workflow(name=name)

    inputnode = Node(interface=util.IdentityInterface(fields=["in_sub", "in_hand"]), name="inputspec")

    ds = Node(DataGrabber(infields=["subject_id", "hand"], outfields=["func"]), name="datasource")
    ds.inputs.base_directory = opap(base_directory)
    ds.inputs.template = "%s/%s_Hand/*.nii*"
    ds.inputs.sort_filelist = True
    # ds.inputs.subject_id = 'GK011RZJA'
    # ds.inputs.hand = 'Left'

    realignref.connect(inputnode, "in_hand", ds, "hand")
    realignref.connect(inputnode, "in_sub", ds, "subject_id")

    img2float = MapNode(
        interface=fsl.ImageMaths(out_data_type="float", op_string="", suffix="_dtype"),
        iterfield=["in_file"],
        name="img2float",
    )

    realignref.connect(ds, ("func", pickrun), img2float, "in_file")
    # realignref.connect(inputnode, 'in_files', img2float, 'in_file')

    if whichvol_glob != "mean":
        extract_ref = Node(interface=fsl.ExtractROI(t_size=1), iterfield=["in_file"], name="extractref")

        realignref.connect(img2float, ("out_file", pickfirst), extract_ref, "in_file")
        realignref.connect(img2float, ("out_file", pickvol, 0, whichvol_glob), extract_ref, "t_min")

    outputnode = pe.Node(interface=util.IdentityInterface(fields=["ref_vol"]), name="outputnode")

    if whichvol_glob != "mean":
        realignref.connect(extract_ref, "roi_file", outputnode, "ref_vol")
    else:
        meanfunc = pe.Node(interface=fsl.ImageMaths(op_string="-Tmean", suffix="_mean"), name="meanfunc")
        realignref.connect(img2float, ("out_file", pickfirst), meanfunc, "in_file")
        realignref.connect(meanfunc, "out_file", outputnode, "ref_vol")

    return realignref
コード例 #5
0
###############################################################################
#
#     DATA GRABBER NODE
#
###############################################################################

from nipype.interfaces.io import DataGrabber
from os.path import abspath as opap

base_directory = '/Users/AClab/Documents/mikbuch/Maestro_Project1'

ds = Node(DataGrabber(
    infields=['subject_id', 'hand'], outfields=['func']), name='datasource'
    )
ds.inputs.base_directory = opap(base_directory)
ds.inputs.template = '%s/%s_Hand/*.nii'
ds.inputs.sort_filelist = True
ds.inputs.subject_id = 'GK011RZJA'
ds.inputs.hand = 'Left'

'''
    To print the list of files being taken uncomment the following lines.
'''
#  functional_input = ds.run().outputs
#  input_files = functional_input.get()['func']
#  print input_files


###############################################################################
#
コード例 #6
0

###############################################################################
#
#     DATA GRABBER NODE
#
###############################################################################

from nipype.interfaces.io import DataGrabber
from os.path import abspath as opap


ds = Node(DataGrabber(
    infields=['subject_id', 'hand'], outfields=['func']), name='datasource'
    )
ds.inputs.base_directory = opap(base_directory)
ds.inputs.template = '%s/%s_Hand/*.nii*'
ds.inputs.sort_filelist = True
# ds.inputs.subject_id = 'GK011RZJA'
# ds.inputs.hand = 'Left'

featreg_merge.connect(inputnode, 'in_hand', ds, 'hand')
featreg_merge.connect(inputnode, 'in_sub', ds, 'subject_id')

'''
    To print the list of files being taken uncomment the following lines.
'''
#  functional_input = ds.run().outputs
#  input_files = functional_input.get()['func']
#  print input_files
コード例 #7
0

###############################################################################
#
#      MASK MULTIPLE WORKFLOW
#
###############################################################################

from nipype.pipeline import Workflow, Node
import nipype.interfaces.io as nio
from os.path import abspath as opap

mask_multiple = Workflow(name='mask_multiple')

grabber = nio.DataGrabber()
grabber.inputs.base_directory = opap(base_directory)
grabber.inputs.template = '*.nii*'
grabber.inputs.sort_filelist = True

grabbed = grabber.run()
rois_filelist = grabbed.outputs.outfiles

###############################################################################
#
#      MASK SINGLE WORKFLOW
#
###############################################################################
apply_mask_multiple = Workflow(name='apply_mask_multiple')

import nipype.interfaces.utility as util
inputnode = Node(
コード例 #8
0
ファイル: workflow_flirt.py プロジェクト: mikbuch/pymri
###############################################################################
#
#     DATA GRABBER NODE
#
###############################################################################

from nipype.interfaces.io import DataGrabber
from os.path import abspath as opap

grabber = Node(DataGrabber(
    infields=['subject_id', 'hand'],
    outfields=['reference', 'matrix']),
    name='moloch'
    )
grabber.inputs.base_directory = opap(base_directory)
grabber.inputs.template = '*'
reg_dir_template = '%s/Analyzed_Data/Main*Exp_%sHand_Run-3.feat/reg/'
grabber.inputs.field_template = dict(
    reference=reg_dir_template + 'example_func.nii.gz',
    matrix=reg_dir_template + 'standard2example*'
    )
grabber.inputs.template_args = dict(
    reference=[['subject_id', 'hand']],
    matrix=[['subject_id', 'hand']]
    )
grabber.inputs.sort_filelist = True


flirt_apply_all_subs.connect(
    inputsub, 'sub',
コード例 #9
0
ファイル: mvpa_preproc.py プロジェクト: mikbuch/pymri
def create_mvpa_preproc(
    base_directory,
    datasink_directory,
    workflow_base_directory,
    subject_template,
    name="mvpapreproc",
    run=1,
    whichvol_glob="mean",
):

    mvpapreproc = pe.Workflow(name=name)

    inputsub = Node(interface=util.IdentityInterface(fields=["sub"]), name="inputsub")
    # inputsub.inputs.sub = ['GK011RZJA', 'GK012OHPA']
    # inputsub.iterables = ('sub', ['GK011RZJA', 'GK012OHPA'])
    inputsub.iterables = ("sub", get_subject_names(base_directory, subject_template))

    inputhand = Node(interface=util.IdentityInterface(fields=["hand"]), name="inputhand")
    inputhand.iterables = ("hand", ["Left", "Right"])

    # ### REFERENCE EXTRACTION ################################################
    reference = create_realign_reference(run=run, whichvol_glob=whichvol_glob)
    mvpapreproc.connect(inputsub, "sub", reference, "inputspec.in_sub")
    mvpapreproc.connect(inputhand, "hand", reference, "inputspec.in_hand")

    # featreg_merge workflow
    merge = create_featreg_merge(run=run, whichvol_glob=whichvol_glob)

    mvpapreproc.connect(inputsub, "sub", merge, "inputspec.in_sub")
    mvpapreproc.connect(inputhand, "hand", merge, "inputspec.in_hand")

    mvpapreproc.connect(reference, "outputnode.ref_vol", merge, "featpreproc.realign.ref_file")

    ###########################################################################
    #
    #     DATA SINK NODE
    #
    ###########################################################################

    from nipype.interfaces.utility import Function

    add_two_strings_node = Node(
        interface=Function(input_names=["subject", "hand"], output_names=["sub_hand_name"], function=add_two_strings),
        name="ats",
    )

    """
    If iterating trought hands will be available
    """
    mvpapreproc.connect(inputsub, "sub", add_two_strings_node, "subject")
    mvpapreproc.connect(inputhand, "hand", add_two_strings_node, "hand")

    from nipype.interfaces.io import DataSink

    datasink = Node(interface=DataSink(), name="datasink")
    datasink.inputs.base_directory = opap(datasink_directory)
    datasink.inputs.parameterization = False

    mvpapreproc.connect(add_two_strings_node, "sub_hand_name", datasink, "container")

    mvpapreproc.connect(
        merge,
        "merge.merged_file",
        # datasink, ds.inputs.subject_id + '/' + ds.inputs.hand + '_Hand/mvpa'
        datasink,
        "preprocessed",
    )
    # mvpa_preproc.connect(inputsub, 'sub', datasink, 'container')

    datasink_masks = Node(interface=DataSink(), name="datasink_masks")
    datasink_masks.inputs.base_directory = opap(datasink_directory)
    datasink_masks.inputs.parameterization = False
    datasink_masks.inputs.substitutions = [("", ""), ("vol0000", "mask")]

    mvpapreproc.connect(add_two_strings_node, "sub_hand_name", datasink_masks, "container")

    mvpapreproc.connect(merge, ("splitnode.out_files", pickfirst), datasink_masks, "preprocessed")

    ###########################################################################
    #
    #     BASE_DIR, GRAPH, AND RUN
    #
    ###########################################################################

    mvpapreproc.base_dir = workflow_base_directory
    # mvpa_preproc.base_dir = \
    #    '/Users/AClab/Documents/mikbuch/Maestro_Project1/mvpa/preprocessing/'

    return mvpapreproc
コード例 #10
0
ファイル: mvpa_preproc.py プロジェクト: mikbuch/pymri
def create_featreg_merge(run, whichvol_glob, name="featregmerge"):
    ###########################################################################
    #
    #     FEATREG_MERGE WORKFLOW
    #
    ###########################################################################

    featregmerge = Workflow(name=name)

    inputnode = Node(
        interface=util.IdentityInterface(fields=["in_sub", "in_hand", "run", "whichvol_glob"]), name="inputspec"
    )
    # inputnode.inputs.in_sub = 'GK011RZJA'

    ###########################################################################
    #
    #     DATA GRABBER NODE
    #
    ###########################################################################

    ds = Node(DataGrabber(infields=["subject_id", "hand"], outfields=["func"]), name="datasource")
    ds.inputs.base_directory = opap(base_directory)
    ds.inputs.template = "%s/%s_Hand/*.nii*"
    ds.inputs.sort_filelist = True
    # ds.inputs.subject_id = 'GK011RZJA'
    # ds.inputs.hand = 'Left'

    featregmerge.connect(inputnode, "in_hand", ds, "hand")
    featregmerge.connect(inputnode, "in_sub", ds, "subject_id")

    """
        To print the list of files being taken uncomment the following lines.
    """
    #  functional_input = ds.run().outputs
    #  input_files = functional_input.get()['func']
    #  print input_files

    ###########################################################################
    #
    #     CREATE FEAT REGISTRATION WORKFLOW NODE
    #
    ###########################################################################

    preproc = create_featreg_preproc(highpass=True, whichvol="first")
    preproc.inputs.inputspec.fwhm = 0
    preproc.inputs.inputspec.highpass = 128.0 / (2 * 2.5)

    # remove_nodes takes list as an argument
    preproc.remove_nodes([preproc.get_node("extractref")])
    """
    preproc.disconnect(
        preproc.get_node('extractref'), 'roi_file',
        preproc.get_node('realign'), 'ref_file'
        )
    """
    featregmerge.connect(ds, "func", preproc, "inputspec.func")

    ###########################################################################
    #
    #     MERGE NODE
    #
    ###########################################################################

    merge = Node(
        interface=fsl.utils.Merge(dimension="t", output_type="NIFTI_GZ", merged_file="bold.nii.gz"), name="merge"
    )
    featregmerge.connect(preproc, "outputspec.highpassed_files", merge, "in_files")

    masksnode = Node(
        interface=fsl.utils.Merge(dimension="t", output_type="NIFTI_GZ", merged_file="masks_merged.nii.gz"),
        name="masksnode",
    )
    featregmerge.connect(preproc, "outputspec.mask", masksnode, "in_files")

    # ### SPLIT MERGED MASKS ##################################################

    splitnode = Node(interface=fsl.utils.Split(dimension="t", output_type="NIFTI_GZ"), name="splitnode")
    featregmerge.connect(masksnode, "merged_file", splitnode, "in_file")

    return featregmerge
コード例 #11
0
from nipype.interfaces.io import DataGrabber
from nipype.pipeline import Node
from os.path import abspath as opap

ds = Node(DataGrabber(
    infields=['subject_id'], outfields=['func']), name='datasource'
    )
ds.inputs.base_directory = opap('ds105')
ds.inputs.template = '%s/BOLD/task001*/bold.nii.gz'
ds.inputs.sort_filelist = True
ds.inputs.subject_id = 'sub001'

functional_input = ds.run().outputs
input_files = functional_input.get()['func']

print input_files
コード例 #12
0
preproc.inputs.inputspec.highpass = 128. / (2 * 2.5)

###############################################################################
#
#     DATA GRABBER NODE
#
###############################################################################

from nipype.interfaces.io import DataGrabber
from os.path import abspath as opap

base_directory = '/Users/AClab/Documents/mikbuch/Maestro_Project1'

ds = Node(DataGrabber(infields=['subject_id', 'hand'], outfields=['func']),
          name='datasource')
ds.inputs.base_directory = opap(base_directory)
ds.inputs.template = '%s/%s_Hand/*.nii'
ds.inputs.sort_filelist = True
ds.inputs.subject_id = 'GK011RZJA'
ds.inputs.hand = 'Left'
'''
    To print the list of files being taken uncomment the following lines.
'''
#  functional_input = ds.run().outputs
#  input_files = functional_input.get()['func']
#  print input_files

###############################################################################
#
#     MERGE NODE
#