def create_workflow(name='tracking'): from nipype.workflows.dmri.fsl import create_bedpostx_pipeline import nipype.interfaces.fsl as fsl import nipype.pipeline.engine as pe import nipype.interfaces.utility as niu wf = pe.Workflow(name=name) bed_wf = create_bedpostx_pipeline() inputspec = pe.Node(niu.IdentityInterface(fields=[ 'dwi', 'mask', 'reg', 'mean', 'bvecs', 'bvals', "subject_id", "surf_dir" ]), name="inputspec") outputspec = pe.Node(niu.IdentityInterface( fields=['fdt_paths', 'log', 'particle_files', 'targets', 'way_total']), name='outputspec') wf.connect(inputspec, 'dwi', bed_wf, 'inputnode.dwi') wf.connect(inputspec, 'mask', bed_wf, 'inputnode.mask') wf.connect(inputspec, 'bvecs', bed_wf, 'inputnode.bvecs') wf.connect(inputspec, 'bvals', bed_wf, 'inputnode.bvals') try: prob2 = fsl.ProbTrackX2(verbose=2) except AttributeError: prob2 = fsl.ProbTrackX(verbose=2) #prob2._cmd='probtrackx2' #prob2.inputs.mode = Undefined track = pe.MapNode(prob2, name='probtrackx', iterfield=["seed"]) wf.connect(bed_wf, 'outputnode.thsamples', track, 'thsamples') wf.connect(bed_wf, 'outputnode.phsamples', track, 'phsamples') wf.connect(bed_wf, 'outputnode.fsamples', track, 'fsamples') wf.connect(inputspec, 'mask', track, 'mask') regions = get_regions() wf.connect(inputspec, "subject_id", regions, "inputspec.subject_id") wf.connect(inputspec, "surf_dir", regions, "inputspec.surf_dir") wf.connect(inputspec, "reg", regions, "inputspec.reg_file") wf.connect(inputspec, "mean", regions, "inputspec.mean") wf.connect(regions, "outputspec.ROIs", track, "seed") wf.connect(regions, "outputspec.ROIs", track, "target_masks") wf.connect(track, 'fdt_paths', outputspec, 'fdt_paths') wf.connect(track, 'log', outputspec, 'log') wf.connect(track, 'particle_files', outputspec, 'particle_files') wf.connect(track, 'targets', outputspec, 'targets') wf.connect(track, 'way_total', outputspec, 'way_total') return wf
def __init__(self, subject, dti_source, mask_source, bval_source, bvec_source, seed_source, datasink): self.subject = subject self.bval_source = bval_source self.bvec_source = bvec_source self.dti_source = dti_source self.mask_source = mask_source self.seed_source = seed_source self.datasink = datasink ############################################################################## # declare nodes ############################################################################## self.bedp = pe.Node(interface=fsl.BEDPOSTX5(), name="bedpostx") self.bedp.inputs.n_fibres = 2 # Maximum number of fibres to fit in each voxel self.bedp.inputs.non_linear = True self.pbx = pe.Node(interface=fsl.ProbTrackX(), name='ProbTrackX') self.pbx.inputs.mode = 'seedmask' self.pbx.inputs.n_samples = 500 self.pbx.inputs.opd = True self.pbx.inputs.os2t = True # ======================= SPLIT LINE ========================================= ############################################################################## # declare workflow, and connect nodes ############################################################################## self.workflow = pe.Workflow(name='tractography_workflow') self.workflow.connect([ (self.bval_source, self.bedp, [('outfiles', 'bvals')]), (self.bvec_source, self.bedp, [('outfiles', 'bvecs')]), (self.dti_source, self.bedp, [('outfiles', 'dwi')]), (self.mask_source, self.bedp, [('outfiles', 'mask')]), (self.mask_source, self.pbx, [('outfiles', 'mask')]), (self.bedp, self.pbx, [('merged_fsamples', 'fsamples'), ('merged_phsamples', 'phsamples'), ('merged_thsamples', 'thsamples')]), (self.seed_source, self.pbx, [('outfiles', 'seed')]), (self.pbx, self.datasink, [('fdt_paths', 'streamline_density_map'), ('way_total', 'way_total')]) ])
tractography.base_dir = os.path.abspath('fsl_dti_tutorial') """ estimate the diffusion parameters: phi, theta, and so on """ bedpostx = create_bedpostx_pipeline() bedpostx.get_node("xfibres").iterables = ("n_fibres", [1, 2]) flirt = pe.Node(interface=fsl.FLIRT(), name='flirt') flirt.inputs.in_file = fsl.Info.standard_image('MNI152_T1_2mm_brain.nii.gz') flirt.inputs.dof = 12 """ perform probabilistic tracktography """ probtrackx = pe.Node(interface=fsl.ProbTrackX(), name='probtrackx') probtrackx.inputs.mode = 'seedmask' probtrackx.inputs.c_thresh = 0.2 probtrackx.inputs.n_steps = 2000 probtrackx.inputs.step_length = 0.5 probtrackx.inputs.n_samples = 5000 probtrackx.inputs.opd = True probtrackx.inputs.os2t = True probtrackx.inputs.loop_check = True """ perform hard segmentation on the output of probtrackx """ findthebiggest = pe.Node(interface=fsl.FindTheBiggest(), name='findthebiggest') """ connect all the nodes for this workflow
def create_prepare_seeds_from_fmri_pipeline(name="prepare_seeds_from_fmri"): inputnode = pe.Node(interface=util.IdentityInterface(fields=[ 'epi', "stat", "dwi", "mask", "phsamples", "thsamples", "fsamples", "T1", "stat_labels" ]), name="inputnode") first_dwi = pe.Node(interface=fsl.ExtractROI(t_min=0, t_size=1), name="first_dwi") first_epi = first_dwi.clone(name="first_epi") coregister = pe.Node(interface=fsl.FLIRT(), name="coregister_epi2dwi") reslice_stat = pe.MapNode(interface=fsl.FLIRT(), name="reslice_stat", iterfield=["in_file"]) reslice_stat.inputs.apply_xfm = True reslice_mask = pe.Node(interface=fsl.FLIRT(), name="reslice_mask") reslice_mask.inputs.interp = "nearestneighbour" smm = pe.MapNode(interface=fsl.SMM(), name="smm", iterfield=['spatial_data_file']) threshold = pe.MapNode(interface=fsl.Threshold(), name="threshold", iterfield=['in_file']) threshold.inputs.thresh = 0.95 probtractx = pe.Node(interface=fsl.ProbTrackX(), name="probtractx") #, iterfield=['waypoints']) probtractx.inputs.opd = True probtractx.inputs.loop_check = True probtractx.inputs.c_thresh = 0.2 probtractx.inputs.n_steps = 2000 probtractx.inputs.step_length = 0.5 probtractx.inputs.n_samples = 100 probtractx.inputs.correct_path_distribution = True probtractx.inputs.verbose = 2 segment = pe.Node(interface=spm.Segment(), name="segment") segment.inputs.gm_output_type = [False, False, True] segment.inputs.wm_output_type = [False, False, True] segment.inputs.csf_output_type = [False, False, False] th_wm = pe.Node(interface=fsl.Threshold(), name="th_wm") th_wm.inputs.direction = "below" th_wm.inputs.thresh = 0.2 th_gm = th_wm.clone("th_gm") wm_gm_interface = pe.Node(fsl.ApplyMask(), name="wm_gm_interface") bet_t1 = pe.Node(fsl.BET(), name="bet_t1") coregister_t1_to_dwi = pe.Node(interface=fsl.FLIRT(), name="coregister_t1_to_dwi") invert_dwi_to_t1_xfm = pe.Node(interface=fsl.ConvertXFM(), name="invert_dwi_to_t1_xfm") invert_dwi_to_t1_xfm.inputs.invert_xfm = True reslice_gm = pe.Node(interface=fsl.FLIRT(), name="reslice_gm") reslice_gm.inputs.apply_xfm = True reslice_wm = reslice_gm.clone("reslice_wm") particles2trackvis = pe.Node(interface=neuroutils.Particle2Trackvis(), name='particles2trackvis') annotate_trackvis = pe.Node(interface=neuroutils.AnnotateTracts(), name='annotate_trackvis') smooth_tracks = pe.Node(interface=dt.SplineFilter(), name="smooth_tracks") smooth_tracks.inputs.step_length = 0.5 pipeline = pe.Workflow(name=name) pipeline.connect([ (inputnode, first_dwi, [("dwi", "in_file")]), (inputnode, first_epi, [("epi", "in_file")]), (first_epi, coregister, [("roi_file", "in_file")]), (first_dwi, coregister, [("roi_file", "reference")]), (inputnode, reslice_stat, [("stat", "in_file"), ("dwi", "reference")]), (inputnode, reslice_mask, [("mask", "in_file"), ("dwi", "reference")]), (coregister, reslice_stat, [("out_matrix_file", "in_matrix_file")]), (coregister, reslice_mask, [("out_matrix_file", "in_matrix_file")]), (reslice_stat, smm, [("out_file", "spatial_data_file")]), (reslice_mask, smm, [("out_file", "mask")]), (smm, threshold, [('activation_p_map', 'in_file')]), (inputnode, probtractx, [("phsamples", "phsamples"), ("thsamples", "thsamples"), ("fsamples", "fsamples")]), (reslice_mask, probtractx, [("out_file", "mask")]), #(threshold, probtractx, [("out_file", "waypoints")]), (inputnode, segment, [("T1", "data")]), (inputnode, bet_t1, [("T1", "in_file")]), (bet_t1, coregister_t1_to_dwi, [("out_file", "reference")]), (first_dwi, coregister_t1_to_dwi, [("roi_file", "in_file")]), (coregister_t1_to_dwi, invert_dwi_to_t1_xfm, [("out_matrix_file", "in_file")]), (invert_dwi_to_t1_xfm, reslice_gm, [("out_file", "in_matrix_file")]), (segment, reslice_gm, [("native_gm_image", "in_file")]), (first_dwi, reslice_gm, [("roi_file", "reference")]), (reslice_gm, th_gm, [("out_file", "in_file")]), (th_gm, wm_gm_interface, [("out_file", "in_file")]), (invert_dwi_to_t1_xfm, reslice_wm, [("out_file", "in_matrix_file")]), (segment, reslice_wm, [("native_wm_image", "in_file")]), (first_dwi, reslice_wm, [("roi_file", "reference")]), (reslice_wm, th_wm, [("out_file", "in_file")]), (th_wm, wm_gm_interface, [("out_file", "mask_file")]), (wm_gm_interface, probtractx, [("out_file", "seed")]), (probtractx, particles2trackvis, [('particle_files', 'particle_files') ]), (reslice_mask, particles2trackvis, [("out_file", "reference_file")]), (particles2trackvis, annotate_trackvis, [('trackvis_file', 'trackvis_file')]), (smm, annotate_trackvis, [('activation_p_map', 'stat_files')]), (inputnode, annotate_trackvis, [('stat_labels', 'stat_labels')]), (annotate_trackvis, smooth_tracks, [('annotated_trackvis_file', 'track_file')]) ]) return pipeline