def create_fsl_recon_flow(config): flow = pe.Workflow(name="reconstruction") inputnode = pe.Node(interface=util.IdentityInterface(fields=["diffusion_resampled","wm_mask_resampled"]),name="inputnode") outputnode = pe.Node(interface=util.IdentityInterface(fields=["phsamples","fsamples","thsamples"],mandatory_inputs=True),name="outputnode") # Flip gradient table flip_table = pe.Node(interface=flipTable(),name='flip_table') flip_table.inputs.table = config.b_vectors flip_table.inputs.flipping_axis = config.flip_table_axis flip_table.inputs.delimiter = ' ' flip_table.inputs.header_lines = 0 flip_table.inputs.orientation = 'h' fsl_node = pe.Node(interface=fsl.BEDPOSTX(),name='BEDPOSTX') fsl_node.inputs.bvals = config.b_values fsl_node.inputs.burn_period = config.burn_period fsl_node.inputs.fibres = config.fibres_per_voxel fsl_node.inputs.jumps = config.jumps fsl_node.inputs.sampling = config.sampling fsl_node.inputs.weight = config.weight flow.connect([ (inputnode,fsl_node,[("diffusion_resampled","dwi")]), (inputnode,fsl_node,[("wm_mask_resampled","mask")]), (flip_table,fsl_node,[("table","bvecs")]), (fsl_node,outputnode,[("merged_fsamples","fsamples")]), (fsl_node,outputnode,[("merged_phsamples","phsamples")]), (fsl_node,outputnode,[("merged_thsamples","thsamples")]), ]) return flow
def test_create_bedpostx_pipeline(): fsl_course_dir = os.path.abspath(os.environ['FSL_COURSE_DATA']) mask_file = os.path.join(fsl_course_dir, "fdt2/subj1.bedpostX/nodif_brain_mask.nii.gz") bvecs_file = os.path.join(fsl_course_dir, "fdt2/subj1/bvecs") bvals_file = os.path.join(fsl_course_dir, "fdt2/subj1/bvals") dwi_file = os.path.join(fsl_course_dir, "fdt2/subj1/data.nii.gz") z_min = 62 z_size = 2 slice_mask = pe.Node(fsl.ExtractROI(x_min=0, x_size=-1, y_min=0, y_size=-1, z_min=z_min, z_size=z_size), name="slice_mask") slice_mask.inputs.in_file = mask_file slice_dwi = pe.Node(fsl.ExtractROI(x_min=0, x_size=-1, y_min=0, y_size=-1, z_min=z_min, z_size=z_size), name="slice_dwi") slice_dwi.inputs.in_file = dwi_file nipype_bedpostx = create_bedpostx_pipeline("nipype_bedpostx") nipype_bedpostx.inputs.inputnode.bvecs = bvecs_file nipype_bedpostx.inputs.inputnode.bvals = bvals_file nipype_bedpostx.inputs.xfibres.n_fibres = 1 nipype_bedpostx.inputs.xfibres.fudge = 1 nipype_bedpostx.inputs.xfibres.burn_in = 0 nipype_bedpostx.inputs.xfibres.n_jumps = 1 nipype_bedpostx.inputs.xfibres.sample_every = 1 nipype_bedpostx.inputs.xfibres.cnlinear = True nipype_bedpostx.inputs.xfibres.seed = 0 with warnings.catch_warnings(): warnings.simplefilter("ignore") original_bedpostx = pe.Node(interface=fsl.BEDPOSTX(), name="original_bedpostx") original_bedpostx.inputs.bvecs = bvecs_file original_bedpostx.inputs.bvals = bvals_file original_bedpostx.inputs.environ['FSLPARALLEL'] = "" original_bedpostx.inputs.n_fibres = 1 original_bedpostx.inputs.fudge = 1 original_bedpostx.inputs.burn_in = 0 original_bedpostx.inputs.n_jumps = 1 original_bedpostx.inputs.sample_every = 1 original_bedpostx.inputs.seed = 0 test_f1 = pe.Node(util.AssertEqual(), name="mean_f1_test") pipeline = pe.Workflow(name="test_bedpostx") pipeline.base_dir = tempfile.mkdtemp(prefix="nipype_test_bedpostx_") pipeline.connect([ (slice_mask, original_bedpostx, [("roi_file", "mask")]), (slice_mask, nipype_bedpostx, [("roi_file", "inputnode.mask")]), (slice_dwi, original_bedpostx, [("roi_file", "dwi")]), (slice_dwi, nipype_bedpostx, [("roi_file", "inputnode.dwi")]), (nipype_bedpostx, test_f1, [(("outputnode.mean_fsamples", list_to_filename), "volume1")]), (original_bedpostx, test_f1, [("mean_fsamples", "volume2")]), ]) pipeline.run(plugin='Linear') shutil.rmtree(pipeline.base_dir)
def test_create_bedpostx_pipeline(): fsl_course_dir = os.path.abspath('fsl_course_data') mask_file = os.path.join(fsl_course_dir, "fdt/subj1.bedpostX/nodif_brain_mask.nii.gz") bvecs_file = os.path.join(fsl_course_dir, "fdt/subj1/bvecs") bvals_file = os.path.join(fsl_course_dir, "fdt/subj1/bvals") dwi_file = os.path.join(fsl_course_dir, "fdt/subj1/data.nii.gz") nipype_bedpostx = create_bedpostx_pipeline("nipype_bedpostx") nipype_bedpostx.inputs.inputnode.dwi = dwi_file nipype_bedpostx.inputs.inputnode.mask = mask_file nipype_bedpostx.inputs.inputnode.bvecs = bvecs_file nipype_bedpostx.inputs.inputnode.bvals = bvals_file nipype_bedpostx.inputs.xfibres.n_fibres = 2 nipype_bedpostx.inputs.xfibres.fudge = 1 nipype_bedpostx.inputs.xfibres.burn_in = 1000 nipype_bedpostx.inputs.xfibres.n_jumps = 1250 nipype_bedpostx.inputs.xfibres.sample_every = 25 with warnings.catch_warnings(): warnings.simplefilter("ignore") original_bedpostx = pe.Node(interface=fsl.BEDPOSTX(), name="original_bedpostx") original_bedpostx.inputs.dwi = dwi_file original_bedpostx.inputs.mask = mask_file original_bedpostx.inputs.bvecs = bvecs_file original_bedpostx.inputs.bvals = bvals_file original_bedpostx.inputs.environ['FSLPARALLEL'] = "" original_bedpostx.inputs.fibres = 2 original_bedpostx.inputs.weight = 1 original_bedpostx.inputs.burn_period = 1000 original_bedpostx.inputs.jumps = 1250 original_bedpostx.inputs.sampling = 25 test_f1 = pe.Node(util.AssertEqual(), name="mean_f1_test") test_f2 = pe.Node(util.AssertEqual(), name="mean_f2_test") test_th1 = pe.Node(util.AssertEqual(), name="mean_th1_test") test_th2 = pe.Node(util.AssertEqual(), name="mean_th2_test") test_ph1 = pe.Node(util.AssertEqual(), name="mean_ph1_test") test_ph2 = pe.Node(util.AssertEqual(), name="mean_ph2_test") pipeline = pe.Workflow(name="test_bedpostx") pipeline.base_dir = tempfile.mkdtemp(prefix="nipype_test_bedpostx_") def pickFirst(l): return l[0] def pickSecond(l): return l[1] pipeline.connect([ (nipype_bedpostx, test_f1, [(("outputnode.mean_fsamples", pickFirst), "volume1")]), (nipype_bedpostx, test_f2, [(("outputnode.mean_fsamples", pickSecond), "volume1")]), (nipype_bedpostx, test_th1, [(("outputnode.mean_thsamples", pickFirst), "volume1")]), (nipype_bedpostx, test_th2, [(("outputnode.mean_thsamples", pickSecond), "volume1")]), (nipype_bedpostx, test_ph1, [(("outputnode.mean_phsamples", pickFirst), "volume1")]), (nipype_bedpostx, test_ph2, [(("outputnode.mean_phsamples", pickSecond), "volume1")]), (original_bedpostx, test_f1, [(("mean_fsamples", pickFirst), "volume2") ]), (original_bedpostx, test_f2, [(("mean_fsamples", pickSecond), "volume2")]), (original_bedpostx, test_th1, [(("mean_thsamples", pickFirst), "volume2")]), (original_bedpostx, test_th2, [(("mean_thsamples", pickSecond), "volume2")]), (original_bedpostx, test_ph1, [(("mean_phsamples", pickFirst), "volume2")]), (original_bedpostx, test_ph2, [(("mean_phsamples", pickSecond), "volume2")]) ]) pipeline.run(plugin='Linear') shutil.rmtree(pipeline.base_dir)