outfields=info.keys()), name='datasource') datasource.inputs.template = "%s/%s" datasource.inputs.base_directory = data_path datasource.inputs.field_template = dict(pet_image='data/%s/%s_%s.nii.gz', roi_image='data/%s/%s.nii.gz', t1_image='data/%s/%s.nii.gz') datasource.inputs.template_args = info datasource.inputs.sort_filelist = True datasink = pe.Node(interface=nio.DataSink(), name="datasink") datasink.inputs.base_directory = output_dir datasink.overwrite = True petquant = create_pet_quantification_wf("example_petquant") workflow = pe.Workflow(name='ex_petquant') workflow.base_dir = output_dir workflow.connect([(infosource, datasource, [('subject_id', 'subject_id')])]) workflow.connect([(infosource, petquant, [('subject_id', 'inputnode.subject_id')])]) workflow.connect([(datasource, petquant, [('pet_image', 'inputnode.pet')])]) workflow.connect([(datasource, petquant, [('roi_image', 'inputnode.rois')])]) workflow.connect([(datasource, petquant, [('t1_image', 'inputnode.t1')])]) workflow.connect([(petquant, datasink, [ ("outputnode.out_files", "@subject_id.out_files"), ("outputnode.corrected_pet_to_t1", "@subject_id.corrected_pet_to_t1"), ("outputnode.pet_results_npz", "@subject_id.pet_results_npz"),
def create_dmn_pipeline_step1(name="dmn_step1", scale_by_glycemia=True, manual_seg_rois=False): inputfields = [ "subjects_dir", "subject_id", "dwi", "bvecs", "bvals", "fdgpet", "dose", "weight", "delay", "glycemie", "scan_time" ] if manual_seg_rois: inputfields.append("manual_seg_rois") inputnode = pe.Node(interface=util.IdentityInterface(fields=inputfields), name="inputnode") outputnode = pe.Node( interface=util.IdentityInterface( fields=[ # Outputs from the DWI workflow "single_fiber_mask", "fa", "rgb_fa", "md", "mode", "t1", "t1_brain", "wm_mask", "term_mask", "aparc_aseg", "tissue_class_files", "gm_prob", "wm_prob", "csf_prob", # Outputs from registration and labelling "rois", "rois_to_dwi", "wmmask_to_dwi", "termmask_to_dwi", "dwi_to_t1_matrix", "highres_t1_to_dwi_matrix", # Outputs from the PET workflow after SUV calculation "SUV_corrected_pet_to_t1", "AIF_corrected_pet_to_t1", "pet_results_npz", "pet_results_mat", "orig_pet_to_t1", # T1 in DWI space for reference "t1_to_dwi", "single_fiber_mask_cortex_only", ]), name="outputnode") t1_to_dwi = pe.Node(interface=fsl.ApplyXfm(), name='t1_to_dwi') termmask_to_dwi = t1_to_dwi.clone("termmask_to_dwi") compute_cmr_glc_interface = util.Function( input_names=[ "subject_id", "in_file", "dose", "weight", "delay", "glycemie", "scan_time" ], output_names=["out_file", "cax2", "mecalc", "denom"], function=CMR_glucose) compute_AIF_PET = pe.Node(interface=compute_cmr_glc_interface, name='compute_AIF_PET') compute_SUV_interface = util.Function(input_names=[ "subject_id", "in_file", "dose", "weight", "delay", "scan_time", "isotope", 'height', "glycemie" ], output_names=["out_file"], function=calculate_SUV) compute_SUV_norm_glycemia = pe.Node(interface=compute_SUV_interface, name='compute_SUV_norm_glycemia') scale_PVC_matrix_interface = util.Function( input_names=[ "subject_id", "in_file", "dose", "weight", "delay", "scan_time", "isotope", 'height', "glycemie", "scale_SUV_by_glycemia" ], output_names=["out_npz", "out_matlab_mat"], function=scale_PVC_matrix_fn) scale_PVC_matrix = pe.Node(interface=scale_PVC_matrix_interface, name='scale_PVC_matrix') scale_PVC_matrix.inputs.scale_SUV_by_glycemia = scale_by_glycemia single_fiber_mask_cortex_only = pe.Node( interface=fsl.MultiImageMaths(), name='single_fiber_mask_cortex_only') single_fiber_mask_cortex_only.inputs.op_string = "-mul %s" dtiproc = damaged_brain_dti_processing("dtiproc") reg_label = create_reg_and_label_wf("reg_label", manual_seg_rois) petquant = create_pet_quantification_wf("petquant", segment_t1=False) workflow = pe.Workflow(name=name) workflow.base_output_dir = name workflow.connect([(inputnode, dtiproc, [("subjects_dir", "inputnode.subjects_dir"), ("subject_id", "inputnode.subject_id"), ("dwi", "inputnode.dwi"), ("bvecs", "inputnode.bvecs"), ("bvals", "inputnode.bvals")])]) workflow.connect([(inputnode, reg_label, [("subject_id", "inputnode.subject_id")])]) if manual_seg_rois: workflow.connect([(inputnode, reg_label, [ ("manual_seg_rois", "inputnode.manual_seg_rois") ])]) workflow.connect([(dtiproc, reg_label, [ ("outputnode.wm_mask", "inputnode.wm_mask"), ("outputnode.term_mask", "inputnode.termination_mask"), ("outputnode.fa", "inputnode.fa"), ("outputnode.aparc_aseg", "inputnode.aparc_aseg"), ])]) workflow.connect([(reg_label, t1_to_dwi, [("outputnode.t1_to_dwi_matrix", "in_matrix_file")])]) workflow.connect([(dtiproc, t1_to_dwi, [("outputnode.t1", "in_file")])]) workflow.connect([(dtiproc, t1_to_dwi, [("outputnode.fa", "reference")])]) workflow.connect([(inputnode, t1_to_dwi, [ (('subject_id', add_subj_name_to_T1_dwi), 'out_file') ])]) workflow.connect([(reg_label, termmask_to_dwi, [("outputnode.t1_to_dwi_matrix", "in_matrix_file")])]) workflow.connect([(dtiproc, termmask_to_dwi, [("outputnode.term_mask", "in_file")])]) workflow.connect([(dtiproc, termmask_to_dwi, [("outputnode.fa", "reference")])]) workflow.connect([(inputnode, single_fiber_mask_cortex_only, [ (('subject_id', add_subj_name_to_cortex_sfmask), 'out_file') ])]) workflow.connect([(termmask_to_dwi, single_fiber_mask_cortex_only, [("out_file", "operand_files")])]) workflow.connect([(dtiproc, single_fiber_mask_cortex_only, [("outputnode.single_fiber_mask", "in_file")])]) workflow.connect([(inputnode, compute_SUV_norm_glycemia, [ ("subject_id", "subject_id"), ("dose", "dose"), ("weight", "weight"), ("delay", "delay"), ("scan_time", "scan_time"), ])]) if scale_by_glycemia == True: workflow.connect([(inputnode, compute_SUV_norm_glycemia, [("glycemie", "glycemie")])]) # This is for the arterial input function approximation for the FDG uptake workflow.connect([(inputnode, compute_AIF_PET, [ ("subject_id", "subject_id"), ("dose", "dose"), ("weight", "weight"), ("delay", "delay"), ("glycemie", "glycemie"), ("scan_time", "scan_time"), ])]) workflow.connect([(inputnode, scale_PVC_matrix, [ ("subject_id", "subject_id"), ("dose", "dose"), ("weight", "weight"), ("delay", "delay"), ("glycemie", "glycemie"), ("scan_time", "scan_time"), ])]) workflow.connect([(dtiproc, petquant, [ (('outputnode.tissue_class_files', select_GM), 'inputnode.gm_mask') ])]) workflow.connect([(dtiproc, petquant, [ ("outputnode.t1", "inputnode.t1"), ("outputnode.wm_prob", "inputnode.wm_prob"), ("outputnode.gm_prob", "inputnode.gm_prob"), ("outputnode.csf_prob", "inputnode.csf_prob"), ])]) workflow.connect([(inputnode, petquant, [("fdgpet", "inputnode.pet")])]) workflow.connect([(inputnode, petquant, [("subject_id", "inputnode.subject_id")])]) if manual_seg_rois: workflow.connect([(inputnode, petquant, [("manual_seg_rois", "inputnode.rois")])]) else: workflow.connect([(reg_label, petquant, [("outputnode.rois", "inputnode.rois")])]) workflow.connect([(petquant, compute_AIF_PET, [("outputnode.corrected_pet_to_t1", "in_file")])]) workflow.connect([(petquant, compute_SUV_norm_glycemia, [("outputnode.corrected_pet_to_t1", "in_file")])]) workflow.connect([(petquant, scale_PVC_matrix, [("outputnode.pet_results_npz", "in_file")])]) ''' Connect outputnode ''' workflow.connect([(t1_to_dwi, outputnode, [("out_file", "t1_to_dwi")])]) workflow.connect([(dtiproc, outputnode, [ ("outputnode.t1", "t1"), ("outputnode.wm_prob", "wm_prob"), ("outputnode.gm_prob", "gm_prob"), ("outputnode.csf_prob", "csf_prob"), ("outputnode.single_fiber_mask", "single_fiber_mask"), ("outputnode.fa", "fa"), ("outputnode.rgb_fa", "rgb_fa"), ("outputnode.md", "md"), ("outputnode.mode", "mode"), ("outputnode.t1_brain", "t1_brain"), ("outputnode.wm_mask", "wm_mask"), ("outputnode.term_mask", "term_mask"), ("outputnode.aparc_aseg", "aparc_aseg"), ("outputnode.tissue_class_files", "tissue_class_files"), ])]) workflow.connect([(reg_label, outputnode, [ ("outputnode.rois_to_dwi", "rois_to_dwi"), ("outputnode.wmmask_to_dwi", "wmmask_to_dwi"), ("outputnode.termmask_to_dwi", "termmask_to_dwi"), ("outputnode.dwi_to_t1_matrix", "dwi_to_t1_matrix"), ("outputnode.highres_t1_to_dwi_matrix", "highres_t1_to_dwi_matrix"), ])]) if manual_seg_rois: workflow.connect([(inputnode, outputnode, [("manual_seg_rois", "rois") ])]) else: workflow.connect([(reg_label, outputnode, [("outputnode.rois", "rois") ])]) workflow.connect([(compute_AIF_PET, outputnode, [("out_file", "SUV_corrected_pet_to_t1")])]) workflow.connect([(compute_SUV_norm_glycemia, outputnode, [("out_file", "AIF_corrected_pet_to_t1")])]) workflow.connect([(petquant, outputnode, [("outputnode.orig_pet_to_t1", "orig_pet_to_t1")])]) workflow.connect([(scale_PVC_matrix, outputnode, [("out_npz", "pet_results_npz")])]) workflow.connect([(scale_PVC_matrix, outputnode, [("out_matlab_mat", "pet_results_mat")])]) workflow.connect([(single_fiber_mask_cortex_only, outputnode, [("out_file", "single_fiber_mask_cortex_only")])]) return workflow
outfields=info.keys()), name='datasource') datasource.inputs.template = "%s/%s" datasource.inputs.base_directory = data_path datasource.inputs.field_template = dict(pet_image='data/%s/%s_%s.nii.gz', roi_image='data/%s/%s.nii.gz', t1_image='data/%s/%s.nii.gz') datasource.inputs.template_args = info datasource.inputs.sort_filelist = True datasink = pe.Node(interface=nio.DataSink(), name="datasink") datasink.inputs.base_directory = output_dir datasink.overwrite = True petquant = create_pet_quantification_wf("example_petquant") workflow = pe.Workflow(name='ex_petquant') workflow.base_dir = output_dir workflow.connect([(infosource, datasource, [('subject_id', 'subject_id')])]) workflow.connect( [(infosource, petquant, [('subject_id', 'inputnode.subject_id')])]) workflow.connect([(datasource, petquant, [('pet_image', 'inputnode.pet')])]) workflow.connect([(datasource, petquant, [('roi_image', 'inputnode.rois')])]) workflow.connect([(datasource, petquant, [('t1_image', 'inputnode.t1')])]) workflow.connect( [(petquant, datasink, [("outputnode.out_files", "@subject_id.out_files"), ("outputnode.corrected_pet_to_t1", "@subject_id.corrected_pet_to_t1"),