def qap_anatomical_spatial_workflow(workflow, resource_pool, config, report=False): # resource pool should have: # anatomical_reorient # qap_head_mask # anatomical_gm_mask # anatomical_wm_mask # anatomical_csf_mask import os import sys import nipype.interfaces.io as nio import nipype.pipeline.engine as pe import nipype.interfaces.utility as niu import nipype.algorithms.misc as nam from qap_workflows_utils import qap_anatomical_spatial from qap.viz.interfaces import PlotMosaic if "qap_head_mask" not in resource_pool.keys(): from qap_workflows import qap_mask_workflow workflow, resource_pool = qap_mask_workflow(workflow, resource_pool, config) if ( ("anatomical_gm_mask" not in resource_pool.keys()) or ("anatomical_wm_mask" not in resource_pool.keys()) or ("anatomical_csf_mask" not in resource_pool.keys()) ): from anatomical_preproc import segmentation_workflow workflow, resource_pool = segmentation_workflow(workflow, resource_pool, config) if "anatomical_reorient" not in resource_pool.keys(): from anatomical_preproc import anatomical_reorient_workflow workflow, resource_pool = anatomical_reorient_workflow(workflow, resource_pool, config) spatial = pe.Node( niu.Function( input_names=[ "anatomical_reorient", "head_mask_path", "anatomical_gm_mask", "anatomical_wm_mask", "anatomical_csf_mask", "subject_id", "session_id", "scan_id", "site_name", ], output_names=["qc"], function=qap_anatomical_spatial, ), name="qap_anatomical_spatial", ) # Subject infos spatial.inputs.subject_id = config["subject_id"] spatial.inputs.session_id = config["session_id"] spatial.inputs.scan_id = config["scan_id"] if "site_name" in config.keys(): spatial.inputs.site_name = config["site_name"] if len(resource_pool["anatomical_reorient"]) == 2: node, out_file = resource_pool["anatomical_reorient"] workflow.connect(node, out_file, spatial, "anatomical_reorient") else: spatial.inputs.anatomical_reorient = resource_pool["anatomical_reorient"] if len(resource_pool["qap_head_mask"]) == 2: node, out_file = resource_pool["qap_head_mask"] workflow.connect(node, out_file, spatial, "head_mask_path") else: spatial.inputs.head_mask_path = resource_pool["qap_head_mask"] if len(resource_pool["anatomical_gm_mask"]) == 2: node, out_file = resource_pool["anatomical_gm_mask"] workflow.connect(node, out_file, spatial, "anatomical_gm_mask") else: spatial.inputs.anatomical_gm_mask = resource_pool["anatomical_gm_mask"] if len(resource_pool["anatomical_wm_mask"]) == 2: node, out_file = resource_pool["anatomical_wm_mask"] workflow.connect(node, out_file, spatial, "anatomical_wm_mask") else: spatial.inputs.anatomical_wm_mask = resource_pool["anatomical_wm_mask"] if len(resource_pool["anatomical_csf_mask"]) == 2: node, out_file = resource_pool["anatomical_csf_mask"] workflow.connect(node, out_file, spatial, "anatomical_csf_mask") else: spatial.inputs.anatomical_csf_mask = resource_pool["anatomical_csf_mask"] if config.get("write_report", False): plot = pe.Node(PlotMosaic(), name="plot_mosaic") plot.inputs.subject = config["subject_id"] metadata = [config["session_id"], config["scan_id"]] if "site_name" in config.keys(): metadata.append(config["site_name"]) plot.inputs.metadata = metadata plot.inputs.title = "Anatomical reoriented" if len(resource_pool["anatomical_reorient"]) == 2: node, out_file = resource_pool["anatomical_reorient"] workflow.connect(node, out_file, plot, "in_file") else: plot.inputs.in_file = resource_pool["anatomical_reorient"] # Enable this if we want masks # if len(resource_pool['qap_head_mask']) == 2: # node, out_file = resource_pool['qap_head_mask'] # workflow.connect(node, out_file, plot, 'in_mask') # else: # plot.inputs.in_mask = resource_pool['qap_head_mask'] resource_pool["qap_mosaic"] = (plot, "out_file") out_csv = op.join(config["output_directory"], "qap_anatomical_spatial.csv") spatial_to_csv = pe.Node(nam.AddCSVRow(in_file=out_csv), name="qap_anatomical_spatial_to_csv") workflow.connect(spatial, "qc", spatial_to_csv, "_outputs") resource_pool["qap_anatomical_spatial"] = (spatial_to_csv, "csv_file") return workflow, resource_pool
def qap_anatomical_spatial_workflow(workflow, resource_pool, config): # resource pool should have: # anatomical_reorient # qap_head_mask # anatomical_gm_mask # anatomical_wm_mask # anatomical_csf_mask import os import sys import nipype.interfaces.io as nio import nipype.pipeline.engine as pe import nipype.interfaces.utility as util from qap_workflows_utils import qap_anatomical_spatial, write_to_csv if "qap_head_mask" not in resource_pool.keys(): from qap_workflows import qap_mask_workflow workflow, resource_pool = qap_mask_workflow(workflow, resource_pool, config) if ( ("anatomical_gm_mask" not in resource_pool.keys()) or ("anatomical_wm_mask" not in resource_pool.keys()) or ("anatomical_csf_mask" not in resource_pool.keys()) ): from anatomical_preproc import segmentation_workflow workflow, resource_pool = segmentation_workflow(workflow, resource_pool, config) if "anatomical_reorient" not in resource_pool.keys(): from anatomical_preproc import anatomical_reorient_workflow workflow, resource_pool = anatomical_reorient_workflow(workflow, resource_pool, config) spatial = pe.Node( util.Function( input_names=[ "anatomical_reorient", "head_mask_path", "anatomical_gm_mask", "anatomical_wm_mask", "anatomical_csf_mask", "subject_id", "session_id", "scan_id", "site_name", ], output_names=["qc"], function=qap_anatomical_spatial, ), name="qap_anatomical_spatial", ) spatial_to_csv = pe.Node( util.Function(input_names=["sub_qap_dict"], output_names=["outfile"], function=write_to_csv), name="qap_anatomical_spatial_to_csv", ) if len(resource_pool["anatomical_reorient"]) == 2: node, out_file = resource_pool["anatomical_reorient"] workflow.connect(node, out_file, spatial, "anatomical_reorient") else: spatial.inputs.anatomical_reorient = resource_pool["anatomical_reorient"] if len(resource_pool["qap_head_mask"]) == 2: node, out_file = resource_pool["qap_head_mask"] workflow.connect(node, out_file, spatial, "head_mask_path") else: spatial.inputs.head_mask_path = resource_pool["qap_head_mask"] if len(resource_pool["anatomical_gm_mask"]) == 2: node, out_file = resource_pool["anatomical_gm_mask"] workflow.connect(node, out_file, spatial, "anatomical_gm_mask") else: spatial.inputs.anatomical_gm_mask = resource_pool["anatomical_gm_mask"] if len(resource_pool["anatomical_wm_mask"]) == 2: node, out_file = resource_pool["anatomical_wm_mask"] workflow.connect(node, out_file, spatial, "anatomical_wm_mask") else: spatial.inputs.anatomical_wm_mask = resource_pool["anatomical_wm_mask"] if len(resource_pool["anatomical_csf_mask"]) == 2: node, out_file = resource_pool["anatomical_csf_mask"] workflow.connect(node, out_file, spatial, "anatomical_csf_mask") else: spatial.inputs.anatomical_csf_mask = resource_pool["anatomical_csf_mask"] # Subject infos spatial.inputs.subject_id = config["subject_id"] spatial.inputs.session_id = config["session_id"] spatial.inputs.scan_id = config["scan_id"] if "site_name" in config.keys(): spatial.inputs.site_name = config["site_name"] workflow.connect(spatial, "qc", spatial_to_csv, "sub_qap_dict") resource_pool["qap_anatomical_spatial"] = (spatial_to_csv, "outfile") return workflow, resource_pool
def qap_anatomical_spatial_workflow(workflow, resource_pool, config, report=False): # resource pool should have: # anatomical_reorient # qap_head_mask # anatomical_gm_mask # anatomical_wm_mask # anatomical_csf_mask import os import sys import nipype.interfaces.io as nio import nipype.pipeline.engine as pe import nipype.interfaces.utility as niu import nipype.algorithms.misc as nam from qap_workflows_utils import qap_anatomical_spatial from qap.viz.interfaces import PlotMosaic if 'qap_head_mask' not in resource_pool.keys(): from qap_workflows import qap_mask_workflow workflow, resource_pool = \ qap_mask_workflow(workflow, resource_pool, config) if ('anatomical_gm_mask' not in resource_pool.keys()) or \ ('anatomical_wm_mask' not in resource_pool.keys()) or \ ('anatomical_csf_mask' not in resource_pool.keys()): from anatomical_preproc import segmentation_workflow workflow, resource_pool = \ segmentation_workflow(workflow, resource_pool, config) if 'anatomical_reorient' not in resource_pool.keys(): from anatomical_preproc import anatomical_reorient_workflow workflow, resource_pool = \ anatomical_reorient_workflow(workflow, resource_pool, config) spatial = pe.Node(niu.Function(input_names=[ 'anatomical_reorient', 'head_mask_path', 'anatomical_gm_mask', 'anatomical_wm_mask', 'anatomical_csf_mask', 'subject_id', 'session_id', 'scan_id', 'site_name' ], output_names=['qc'], function=qap_anatomical_spatial), name='qap_anatomical_spatial') # Subject infos spatial.inputs.subject_id = config['subject_id'] spatial.inputs.session_id = config['session_id'] spatial.inputs.scan_id = config['scan_id'] if 'site_name' in config.keys(): spatial.inputs.site_name = config['site_name'] if len(resource_pool['anatomical_reorient']) == 2: node, out_file = resource_pool['anatomical_reorient'] workflow.connect(node, out_file, spatial, 'anatomical_reorient') else: spatial.inputs.anatomical_reorient = \ resource_pool['anatomical_reorient'] if len(resource_pool['qap_head_mask']) == 2: node, out_file = resource_pool['qap_head_mask'] workflow.connect(node, out_file, spatial, 'head_mask_path') else: spatial.inputs.head_mask_path = resource_pool['qap_head_mask'] if len(resource_pool['anatomical_gm_mask']) == 2: node, out_file = resource_pool['anatomical_gm_mask'] workflow.connect(node, out_file, spatial, 'anatomical_gm_mask') else: spatial.inputs.anatomical_gm_mask = \ resource_pool['anatomical_gm_mask'] if len(resource_pool['anatomical_wm_mask']) == 2: node, out_file = resource_pool['anatomical_wm_mask'] workflow.connect(node, out_file, spatial, 'anatomical_wm_mask') else: spatial.inputs.anatomical_wm_mask = \ resource_pool['anatomical_wm_mask'] if len(resource_pool['anatomical_csf_mask']) == 2: node, out_file = resource_pool['anatomical_csf_mask'] workflow.connect(node, out_file, spatial, 'anatomical_csf_mask') else: spatial.inputs.anatomical_csf_mask = \ resource_pool['anatomical_csf_mask'] if config.get('write_report', False): plot = pe.Node(PlotMosaic(), name='plot_mosaic') plot.inputs.subject = config['subject_id'] metadata = [config['session_id'], config['scan_id']] if 'site_name' in config.keys(): metadata.append(config['site_name']) plot.inputs.metadata = metadata plot.inputs.title = 'Anatomical reoriented' if len(resource_pool['anatomical_reorient']) == 2: node, out_file = resource_pool['anatomical_reorient'] workflow.connect(node, out_file, plot, 'in_file') else: plot.inputs.in_file = resource_pool['anatomical_reorient'] # Enable this if we want masks # if len(resource_pool['qap_head_mask']) == 2: # node, out_file = resource_pool['qap_head_mask'] # workflow.connect(node, out_file, plot, 'in_mask') # else: # plot.inputs.in_mask = resource_pool['qap_head_mask'] resource_pool['qap_mosaic'] = (plot, 'out_file') out_csv = op.join(config['output_directory'], 'qap_anatomical_spatial.csv') spatial_to_csv = pe.Node(nam.AddCSVRow(in_file=out_csv), name='qap_anatomical_spatial_to_csv') workflow.connect(spatial, 'qc', spatial_to_csv, '_outputs') resource_pool['qap_anatomical_spatial'] = (spatial_to_csv, 'csv_file') return workflow, resource_pool