def QA_workflow(c, prep_c, name='QA'): """ Workflow that generates a Quality Assurance json """ import nipype.pipeline.engine as pe import nipype.interfaces.utility as util from nipype.interfaces.freesurfer import ApplyVolTransform from nipype.interfaces import freesurfer as fs from nipype.interfaces.io import FreeSurferSource from scripts.u0a14c5b5899911e1bca80023dfa375f2.QA_utils import (tsnr_roi, art_output) from ..utils.reportsink.io import JSONSink # Define Workflow workflow = pe.Workflow(name=name) datagrabber = c.datagrabber.create_dataflow() infosource = datagrabber.get_node('subject_id_iterable') #workflow.connect(infosource, 'subject_id', inputspec, 'subject_id') art_info = pe.MapNode( util.Function(input_names=['art_file', 'intensity_file', 'stats_file'], output_names=['table', 'out', 'intensity_plot'], function=art_output), name='art_output', iterfield=["art_file", "intensity_file", "stats_file"]) #fssource = pe.Node(interface = FreeSurferSource(),name='fssource') #fssource.inputs.subjects_dir = c.surf_dir roidevplot = tsnr_roi(plot=False, name='tsnr_stddev_roi', roi=['all'], onsets=False) roidevplot.inputs.inputspec.TR = c.TR roisnrplot = tsnr_roi(plot=False, name='SNR_roi', roi=['all'], onsets=False) roisnrplot.inputs.inputspec.TR = c.TR #workflow.connect(fssource, ('aparc_aseg', pickaparc), roisnrplot, 'inputspec.aparc_aseg') #workflow.connect(fssource, ('aparc_aseg', pickaparc), roidevplot, 'inputspec.aparc_aseg') workflow.connect(infosource, 'subject_id', roidevplot, 'inputspec.subject') workflow.connect(infosource, 'subject_id', roisnrplot, 'inputspec.subject') workflow.connect(infosource, ("subject_id", myfssource, c.surf_dir), roisnrplot, "inputspec.aparc_aseg") workflow.connect(infosource, ("subject_id", myfssource, c.surf_dir), roidevplot, "inputspec.aparc_aseg") tablecombine = pe.MapNode(util.Function(input_names=['roidev', 'roisnr'], output_names=['combined_table'], function=combine_table), name='combinetable', iterfield=['roidev', 'roisnr']) #workflow.connect(infosource,'subject_id',fssource,'subject_id') #workflow.connect(inputspec,'sd',fssource,'subjects_dir') #fssource.inputs.subjects_dir = c.surf_dir roisnrplot.inputs.inputspec.sd = c.surf_dir roidevplot.inputs.inputspec.sd = c.surf_dir workflow.connect(datagrabber, 'datagrabber.art_intensity', art_info, 'intensity_file') workflow.connect(datagrabber, 'datagrabber.art_stats', art_info, 'stats_file') workflow.connect(datagrabber, 'datagrabber.outlier_files', art_info, 'art_file') workflow.connect(datagrabber, 'datagrabber.reg_file', roidevplot, 'inputspec.reg_file') workflow.connect(datagrabber, 'datagrabber.tsnr_stddev', roidevplot, 'inputspec.tsnr_file') #workflow.connect(fssource,('aparc_aseg',pickaparc),roidevplot,'inputspec.aparc_aseg') workflow.connect(roidevplot, 'outputspec.roi_table', tablecombine, 'roidev') workflow.connect(datagrabber, 'datagrabber.reg_file', roisnrplot, 'inputspec.reg_file') workflow.connect(datagrabber, 'datagrabber.tsnr', roisnrplot, 'inputspec.tsnr_file') workflow.connect(roisnrplot, 'outputspec.roi_table', tablecombine, 'roisnr') js = pe.Node(interface=JSONSink(), name="jsoner") workflow.connect(tablecombine, "combined_table", js, "SNR_table") workflow.connect(art_info, "table", js, "art") workflow.connect(art_info, "out", js, "outliers") workflow.connect(datagrabber, ("datagrabber.mincost", getmincost), js, "mincost") js.inputs.norm_thresh = prep_c.norm_thresh js.inputs.z_thresh = prep_c.z_thresh return workflow
def QA_workflow(QAc, c=foo, name='QA'): """ Workflow that generates a Quality Assurance Report Parameters ---------- name : name of workflow Inputs ------ inputspec.subject_id : Subject id inputspec.config_params : configuration parameters to print in PDF (in the form of a 2D List) inputspec.in_file : original functional run inputspec.art_file : art outlier file inputspec.reg_file : bbregister file inputspec.tsnr_detrended : detrended image inputspec.tsnr : signal-to-noise ratio image inputspec.tsnr_mean : mean image inputspec.tsnr_stddev : standard deviation image inputspec.ADnorm : norm components file from art inputspec.TR : repetition time of acquisition inputspec.sd : freesurfer subjects directory """ import nipype.pipeline.engine as pe import nipype.interfaces.utility as util from nipype.interfaces.freesurfer import ApplyVolTransform from nipype.interfaces import freesurfer as fs from nipype.interfaces.io import FreeSurferSource from scripts.u0a14c5b5899911e1bca80023dfa375f2.QA_utils import ( plot_ADnorm, tsdiffana, tsnr_roi, combine_table, art_output, plot_motion, plot_ribbon, plot_anat, overlay_new, overlay_dB, spectrum_ts_table) from ..utils.reportsink.io import ReportSink # Define Workflow workflow = pe.Workflow(name=name) inputspec = pe.Node(interface=util.IdentityInterface(fields=[ 'subject_id', 'config_params', 'in_file', 'art_file', 'motion_plots', 'reg_file', 'tsnr', 'tsnr_detrended', 'tsnr_stddev', 'ADnorm', 'TR', 'sd' ]), name='inputspec') infosource = pe.Node(util.IdentityInterface(fields=['subject_id']), name='subject_names') if QAc.test_mode: infosource.iterables = ('subject_id', [QAc.subjects[0]]) else: infosource.iterables = ('subject_id', QAc.subjects) datagrabber = preproc_datagrabber(c) datagrabber.inputs.node_type = c.motion_correct_node orig_datagrabber = get_dataflow(c) workflow.connect(infosource, 'subject_id', datagrabber, 'subject_id') workflow.connect(infosource, 'subject_id', orig_datagrabber, 'subject_id') workflow.connect(orig_datagrabber, 'func', inputspec, 'in_file') workflow.connect(infosource, 'subject_id', inputspec, 'subject_id') workflow.connect(datagrabber, ('outlier_files', sort), inputspec, 'art_file') workflow.connect(datagrabber, ('reg_file', sort), inputspec, 'reg_file') workflow.connect(datagrabber, ('tsnr', sort), inputspec, 'tsnr') workflow.connect(datagrabber, ('tsnr_stddev', sort), inputspec, 'tsnr_stddev') workflow.connect(datagrabber, ('tsnr_detrended', sort), inputspec, 'tsnr_detrended') workflow.connect(datagrabber, ('art_norm', sort), inputspec, 'ADnorm') inputspec.inputs.TR = c.TR inputspec.inputs.sd = c.surf_dir # Define Nodes plot_m = pe.MapNode(util.Function(input_names=['motion_parameters'], output_names=['fname_t', 'fname_r'], function=plot_motion), name="motion_plots", iterfield=['motion_parameters']) workflow.connect(datagrabber, ('motion_parameters', sort), plot_m, 'motion_parameters') #workflow.connect(plot_m, 'fname',inputspec,'motion_plots') tsdiff = pe.MapNode(util.Function(input_names=['img'], output_names=['out_file'], function=tsdiffana), name='tsdiffana', iterfield=["img"]) art_info = pe.MapNode( util.Function(input_names=['art_file', 'intensity_file', 'stats_file'], output_names=['table', 'out', 'intensity_plot'], function=art_output), name='art_output', iterfield=["art_file", "intensity_file", "stats_file"]) fssource = pe.Node(interface=FreeSurferSource(), name='fssource') plotribbon = pe.Node(util.Function(input_names=['Brain'], output_names=['images'], function=plot_ribbon), name="plot_ribbon") workflow.connect(fssource, 'ribbon', plotribbon, 'Brain') plotanat = pe.Node(util.Function(input_names=['brain'], output_names=['images'], function=plot_anat), name="plot_anat") plotmask = plotanat.clone('plot_mask') workflow.connect(datagrabber, 'mask', plotmask, 'brain') roidevplot = tsnr_roi(plot=False, name='tsnr_stddev_roi', roi=['all'], onsets=False) roidevplot.inputs.inputspec.TR = c.TR roisnrplot = tsnr_roi(plot=False, name='SNR_roi', roi=['all'], onsets=False) roisnrplot.inputs.inputspec.TR = c.TR workflow.connect(fssource, ('aparc_aseg', pickfirst), roisnrplot, 'inputspec.aparc_aseg') workflow.connect(fssource, ('aparc_aseg', pickfirst), roidevplot, 'inputspec.aparc_aseg') workflow.connect(infosource, 'subject_id', roidevplot, 'inputspec.subject') workflow.connect(infosource, 'subject_id', roisnrplot, 'inputspec.subject') tablecombine = pe.MapNode(util.Function( input_names=['roidev', 'roisnr', 'imagetable'], output_names=['imagetable'], function=combine_table), name='combinetable', iterfield=['roidev', 'roisnr', 'imagetable']) adnormplot = pe.MapNode(util.Function( input_names=['ADnorm', 'TR', 'norm_thresh', 'out'], output_names=['plot'], function=plot_ADnorm), name='ADnormplot', iterfield=['ADnorm', 'out']) adnormplot.inputs.norm_thresh = c.norm_thresh workflow.connect(art_info, 'out', adnormplot, 'out') convert = pe.Node(interface=fs.MRIConvert(), name='converter') voltransform = pe.MapNode(interface=ApplyVolTransform(), name='register', iterfield=['source_file']) overlaynew = pe.MapNode(util.Function( input_names=['stat_image', 'background_image', 'threshold', "dB"], output_names=['fnames'], function=overlay_dB), name='overlay_new', iterfield=['stat_image']) overlaynew.inputs.dB = False overlaynew.inputs.threshold = 20 overlaymask = pe.MapNode(util.Function( input_names=['stat_image', 'background_image', 'threshold'], output_names=['fnames'], function=overlay_new), name='overlay_mask', iterfield=['stat_image']) overlaymask.inputs.threshold = 0.5 workflow.connect(convert, 'out_file', overlaymask, 'background_image') overlaymask2 = overlaymask.clone('acompcor_image') workflow.connect(convert, 'out_file', overlaymask2, 'background_image') workflow.connect(datagrabber, 'tcompcor', overlaymask, 'stat_image') workflow.connect(datagrabber, 'acompcor', overlaymask2, 'stat_image') workflow.connect(datagrabber, ('mean_image', sort), plotanat, 'brain') ts_and_spectra = spectrum_ts_table() timeseries_segstats = tsnr_roi(plot=False, name='timeseries_roi', roi=['all'], onsets=False) workflow.connect(inputspec, 'tsnr_detrended', timeseries_segstats, 'inputspec.tsnr_file') workflow.connect(inputspec, 'reg_file', timeseries_segstats, 'inputspec.reg_file') workflow.connect(infosource, 'subject_id', timeseries_segstats, 'inputspec.subject') workflow.connect(fssource, ('aparc_aseg', pickfirst), timeseries_segstats, 'inputspec.aparc_aseg') timeseries_segstats.inputs.inputspec.TR = c.TR ts_and_spectra.inputs.inputspec.tr = c.TR workflow.connect(timeseries_segstats, 'outputspec.roi_file', ts_and_spectra, 'inputspec.stats_file') write_rep = pe.Node(interface=ReportSink(orderfields=[ 'Introduction', 'in_file', 'config_params', 'Art_Detect', 'Global_Intensity', 'Mean_Functional', 'Ribbon', 'Mask', 'motion_plot_translations', 'motion_plot_rotations', 'tsdiffana', 'ADnorm', 'A_CompCor', 'T_CompCor', 'TSNR_Images', 'tsnr_roi_table' ]), name='report_sink') write_rep.inputs.Introduction = "Quality Assurance Report for fMRI preprocessing." write_rep.inputs.base_directory = os.path.join(QAc.sink_dir) write_rep.inputs.report_name = "Preprocessing_Report" write_rep.inputs.json_sink = QAc.json_sink workflow.connect(infosource, 'subject_id', write_rep, 'container') workflow.connect(plotanat, 'images', write_rep, "Mean_Functional") write_rep.inputs.table_as_para = False # Define Inputs convert.inputs.out_type = 'niigz' convert.inputs.in_type = 'mgz' # Define Connections workflow.connect(inputspec, 'TR', adnormplot, 'TR') workflow.connect(inputspec, 'subject_id', fssource, 'subject_id') workflow.connect(inputspec, 'sd', fssource, 'subjects_dir') workflow.connect(inputspec, 'in_file', write_rep, 'in_file') workflow.connect(datagrabber, 'art_intensity', art_info, 'intensity_file') workflow.connect(datagrabber, 'art_stats', art_info, 'stats_file') workflow.connect(inputspec, 'art_file', art_info, 'art_file') workflow.connect(art_info, ('table', to1table), write_rep, 'Art_Detect') workflow.connect(ts_and_spectra, 'outputspec.imagetable', tablecombine, 'imagetable') workflow.connect(art_info, 'intensity_plot', write_rep, 'Global_Intensity') workflow.connect(plot_m, 'fname_t', write_rep, 'motion_plot_translations') workflow.connect(plot_m, 'fname_r', write_rep, 'motion_plot_rotations') workflow.connect(inputspec, 'in_file', tsdiff, 'img') workflow.connect(tsdiff, "out_file", write_rep, "tsdiffana") workflow.connect(inputspec, ('config_params', totable), write_rep, 'config_params') workflow.connect(inputspec, 'reg_file', roidevplot, 'inputspec.reg_file') workflow.connect(inputspec, 'tsnr_stddev', roidevplot, 'inputspec.tsnr_file') workflow.connect(roidevplot, 'outputspec.roi_table', tablecombine, 'roidev') workflow.connect(inputspec, 'reg_file', roisnrplot, 'inputspec.reg_file') workflow.connect(inputspec, 'tsnr', roisnrplot, 'inputspec.tsnr_file') workflow.connect(roisnrplot, 'outputspec.roi_table', tablecombine, 'roisnr') workflow.connect(tablecombine, ('imagetable', to1table), write_rep, 'tsnr_roi_table') workflow.connect(inputspec, 'ADnorm', adnormplot, 'ADnorm') workflow.connect(adnormplot, 'plot', write_rep, 'ADnorm') workflow.connect(fssource, 'orig', convert, 'in_file') workflow.connect(convert, 'out_file', voltransform, 'target_file') workflow.connect(inputspec, 'reg_file', voltransform, 'reg_file') workflow.connect(inputspec, 'tsnr', voltransform, 'source_file') workflow.connect(plotribbon, 'images', write_rep, 'Ribbon') workflow.connect(voltransform, 'transformed_file', overlaynew, 'stat_image') workflow.connect(convert, 'out_file', overlaynew, 'background_image') workflow.connect(overlaynew, 'fnames', write_rep, 'TSNR_Images') workflow.connect(overlaymask, 'fnames', write_rep, 'T_CompCor') workflow.connect(overlaymask2, 'fnames', write_rep, 'A_CompCor') workflow.connect(plotmask, 'images', write_rep, 'Mask') workflow.write_graph() return workflow
def QA_workflow(QAc,c=foo, name='QA'): """ Workflow that generates a Quality Assurance Report Parameters ---------- name : name of workflow Inputs ------ inputspec.subject_id : inputspec.config_params : inputspec.in_file : inputspec.art_file : inputspec.motion_plots : inputspec.reg_file : inputspec.tsnr_detrended : inputspec.tsnr : inputspec.tsnr_mean : inputspec.tsnr_stddev : inputspec.ADnorm : inputspec.TR : inputspec.sd : freesurfer subjects directory """ import nipype.pipeline.engine as pe import nipype.interfaces.utility as util from nipype.interfaces.freesurfer import ApplyVolTransform from nipype.interfaces import freesurfer as fs from nipype.interfaces.io import FreeSurferSource from scripts.u0a14c5b5899911e1bca80023dfa375f2.QA_utils import (plot_ADnorm, tsdiffana, tsnr_roi, combine_table, art_output, plot_motion, plot_ribbon, plot_anat, overlay_new, overlay_dB, spectrum_ts_table) from ..utils.reportsink.io import ReportSink # Define Workflow workflow =pe.Workflow(name=name) inputspec = pe.Node(interface=util.IdentityInterface(fields=['subject_id', 'config_params', 'in_file', 'art_file', 'motion_plots', 'reg_file', 'tsnr', 'tsnr_detrended', 'tsnr_stddev', 'ADnorm', 'TR', 'sd']), name='inputspec') infosource = pe.Node(util.IdentityInterface(fields=['subject_id']), name='subject_names') if QAc.test_mode: infosource.iterables = ('subject_id', [QAc.subjects[0]]) else: infosource.iterables = ('subject_id', QAc.subjects) datagrabber = preproc_datagrabber(c) datagrabber.inputs.node_type = c.motion_correct_node orig_datagrabber = get_dataflow(c) workflow.connect(infosource, 'subject_id', datagrabber, 'subject_id') workflow.connect(infosource, 'subject_id', orig_datagrabber, 'subject_id') workflow.connect(orig_datagrabber, 'func', inputspec, 'in_file') workflow.connect(infosource, 'subject_id', inputspec, 'subject_id') workflow.connect(datagrabber, ('outlier_files',sort), inputspec, 'art_file') workflow.connect(datagrabber, ('reg_file', sort), inputspec, 'reg_file') workflow.connect(datagrabber, ('tsnr',sort), inputspec, 'tsnr') workflow.connect(datagrabber, ('tsnr_stddev',sort), inputspec, 'tsnr_stddev') workflow.connect(datagrabber, ('tsnr_detrended',sort), inputspec, 'tsnr_detrended') workflow.connect(datagrabber, ('art_norm',sort), inputspec, 'ADnorm') inputspec.inputs.TR = c.TR inputspec.inputs.sd = c.surf_dir # Define Nodes plot_m = pe.MapNode(util.Function(input_names=['motion_parameters'], output_names=['fname_t','fname_r'], function=plot_motion), name="motion_plots", iterfield=['motion_parameters']) workflow.connect(datagrabber,('motion_parameters', sort),plot_m,'motion_parameters') #workflow.connect(plot_m, 'fname',inputspec,'motion_plots') tsdiff = pe.MapNode(util.Function(input_names = ['img'], output_names = ['out_file'], function=tsdiffana), name='tsdiffana', iterfield=["img"]) art_info = pe.MapNode(util.Function(input_names = ['art_file','intensity_file','stats_file'], output_names = ['table','out','intensity_plot'], function=art_output), name='art_output', iterfield=["art_file","intensity_file","stats_file"]) fssource = pe.Node(interface = FreeSurferSource(),name='fssource') plotribbon = pe.Node(util.Function(input_names=['Brain'], output_names=['images'], function=plot_ribbon), name="plot_ribbon") workflow.connect(fssource, 'ribbon', plotribbon, 'Brain') plotanat = pe.Node(util.Function(input_names=['brain'], output_names=['images'], function=plot_anat), name="plot_anat") plotmask = plotanat.clone('plot_mask') workflow.connect(datagrabber,'mask', plotmask,'brain') roidevplot = tsnr_roi(plot=False,name='tsnr_stddev_roi',roi=['all'],onsets=False) roidevplot.inputs.inputspec.TR = c.TR roisnrplot = tsnr_roi(plot=False,name='SNR_roi',roi=['all'],onsets=False) roisnrplot.inputs.inputspec.TR = c.TR workflow.connect(fssource, ('aparc_aseg', pickfirst), roisnrplot, 'inputspec.aparc_aseg') workflow.connect(fssource, ('aparc_aseg', pickfirst), roidevplot, 'inputspec.aparc_aseg') workflow.connect(infosource, 'subject_id', roidevplot, 'inputspec.subject') workflow.connect(infosource, 'subject_id', roisnrplot, 'inputspec.subject') tablecombine = pe.MapNode(util.Function(input_names = ['roidev', 'roisnr', 'imagetable'], output_names = ['imagetable'], function = combine_table), name='combinetable', iterfield=['roidev','roisnr','imagetable']) adnormplot = pe.MapNode(util.Function(input_names = ['ADnorm','TR','norm_thresh','out'], output_names = ['plot'], function=plot_ADnorm), name='ADnormplot', iterfield=['ADnorm','out']) adnormplot.inputs.norm_thresh = c.norm_thresh workflow.connect(art_info,'out',adnormplot,'out') convert = pe.Node(interface=fs.MRIConvert(),name='converter') voltransform = pe.MapNode(interface=ApplyVolTransform(),name='register',iterfield=['source_file']) overlaynew = pe.MapNode(util.Function(input_names=['stat_image','background_image','threshold',"dB"], output_names=['fnames'], function=overlay_dB), name='overlay_new', iterfield=['stat_image']) overlaynew.inputs.dB = False overlaynew.inputs.threshold = 20 overlaymask = pe.MapNode(util.Function(input_names=['stat_image','background_image','threshold'], output_names=['fnames'], function=overlay_new), name='overlay_mask',iterfield=['stat_image']) overlaymask.inputs.threshold = 0.5 workflow.connect(convert,'out_file', overlaymask,'background_image') overlaymask2 = overlaymask.clone('acompcor_image') workflow.connect(convert,'out_file', overlaymask2,'background_image') workflow.connect(datagrabber,'tcompcor',overlaymask,'stat_image') workflow.connect(datagrabber,'acompcor',overlaymask2,'stat_image') workflow.connect(datagrabber, ('mean_image', sort), plotanat, 'brain') ts_and_spectra = spectrum_ts_table() timeseries_segstats = tsnr_roi(plot=False,name='timeseries_roi',roi=['all'],onsets=False) workflow.connect(inputspec,'tsnr_detrended', timeseries_segstats,'inputspec.tsnr_file') workflow.connect(inputspec,'reg_file', timeseries_segstats,'inputspec.reg_file') workflow.connect(infosource, 'subject_id', timeseries_segstats, 'inputspec.subject') workflow.connect(fssource, ('aparc_aseg', pickfirst), timeseries_segstats, 'inputspec.aparc_aseg') timeseries_segstats.inputs.inputspec.TR = c.TR ts_and_spectra.inputs.inputspec.tr = c.TR workflow.connect(timeseries_segstats,'outputspec.roi_file',ts_and_spectra, 'inputspec.stats_file') write_rep = pe.Node(interface=ReportSink(orderfields=['Introduction', 'in_file', 'config_params', 'Art_Detect', 'Global_Intensity', 'Mean_Functional', 'Ribbon', 'Mask', 'motion_plot_translations', 'motion_plot_rotations', 'tsdiffana', 'ADnorm', 'A_CompCor', 'T_CompCor', 'TSNR_Images', 'tsnr_roi_table']), name='report_sink') write_rep.inputs.Introduction = "Quality Assurance Report for fMRI preprocessing." write_rep.inputs.base_directory = os.path.join(QAc.sink_dir) write_rep.inputs.report_name = "Preprocessing_Report" write_rep.inputs.json_sink = QAc.json_sink workflow.connect(infosource,'subject_id',write_rep,'container') workflow.connect(plotanat, 'images', write_rep, "Mean_Functional") write_rep.inputs.table_as_para=False # Define Inputs convert.inputs.out_type = 'niigz' convert.inputs.in_type = 'mgz' # Define Connections workflow.connect(inputspec,'TR',adnormplot,'TR') workflow.connect(inputspec,'subject_id',fssource,'subject_id') workflow.connect(inputspec,'sd',fssource,'subjects_dir') workflow.connect(inputspec,'in_file',write_rep,'in_file') workflow.connect(datagrabber,'art_intensity',art_info,'intensity_file') workflow.connect(datagrabber,'art_stats',art_info,'stats_file') workflow.connect(inputspec,'art_file',art_info,'art_file') workflow.connect(art_info,('table',to1table), write_rep,'Art_Detect') workflow.connect(ts_and_spectra,'outputspec.imagetable',tablecombine, 'imagetable') workflow.connect(art_info,'intensity_plot',write_rep,'Global_Intensity') workflow.connect(plot_m, 'fname_t',write_rep,'motion_plot_translations') workflow.connect(plot_m, 'fname_r',write_rep,'motion_plot_rotations') workflow.connect(inputspec,'in_file',tsdiff,'img') workflow.connect(tsdiff,"out_file",write_rep,"tsdiffana") workflow.connect(inputspec,('config_params',totable), write_rep,'config_params') workflow.connect(inputspec,'reg_file',roidevplot,'inputspec.reg_file') workflow.connect(inputspec,'tsnr_stddev',roidevplot,'inputspec.tsnr_file') workflow.connect(roidevplot,'outputspec.roi_table',tablecombine,'roidev') workflow.connect(inputspec,'reg_file',roisnrplot,'inputspec.reg_file') workflow.connect(inputspec,'tsnr',roisnrplot,'inputspec.tsnr_file') workflow.connect(roisnrplot,'outputspec.roi_table',tablecombine,'roisnr') workflow.connect(tablecombine, ('imagetable',to1table), write_rep, 'tsnr_roi_table') workflow.connect(inputspec,'ADnorm',adnormplot,'ADnorm') workflow.connect(adnormplot,'plot',write_rep,'ADnorm') workflow.connect(fssource,'orig',convert,'in_file') workflow.connect(convert,'out_file',voltransform,'target_file') workflow.connect(inputspec,'reg_file',voltransform,'reg_file') workflow.connect(inputspec,'tsnr',voltransform, 'source_file') workflow.connect(plotribbon, 'images', write_rep, 'Ribbon') workflow.connect(voltransform,'transformed_file', overlaynew,'stat_image') workflow.connect(convert,'out_file', overlaynew,'background_image') workflow.connect(overlaynew, 'fnames', write_rep, 'TSNR_Images') workflow.connect(overlaymask, 'fnames', write_rep, 'T_CompCor') workflow.connect(overlaymask2, 'fnames', write_rep, 'A_CompCor') workflow.connect(plotmask,'images',write_rep,'Mask') workflow.write_graph() return workflow
def QA_workflow(c, prep_c,name='QA'): """ Workflow that generates a Quality Assurance json """ import nipype.pipeline.engine as pe import nipype.interfaces.utility as util from nipype.interfaces.freesurfer import ApplyVolTransform from nipype.interfaces import freesurfer as fs from nipype.interfaces.io import FreeSurferSource from scripts.u0a14c5b5899911e1bca80023dfa375f2.QA_utils import (tsnr_roi, art_output) from ..utils.reportsink.io import JSONSink # Define Workflow workflow =pe.Workflow(name=name) datagrabber = c.datagrabber.create_dataflow() infosource = datagrabber.get_node('subject_id_iterable') #workflow.connect(infosource, 'subject_id', inputspec, 'subject_id') art_info = pe.MapNode(util.Function(input_names = ['art_file','intensity_file','stats_file'], output_names = ['table','out','intensity_plot'], function=art_output), name='art_output', iterfield=["art_file","intensity_file","stats_file"]) #fssource = pe.Node(interface = FreeSurferSource(),name='fssource') #fssource.inputs.subjects_dir = c.surf_dir roidevplot = tsnr_roi(plot=False,name='tsnr_stddev_roi',roi=['all'],onsets=False) roidevplot.inputs.inputspec.TR = c.TR roisnrplot = tsnr_roi(plot=False,name='SNR_roi',roi=['all'],onsets=False) roisnrplot.inputs.inputspec.TR = c.TR #workflow.connect(fssource, ('aparc_aseg', pickaparc), roisnrplot, 'inputspec.aparc_aseg') #workflow.connect(fssource, ('aparc_aseg', pickaparc), roidevplot, 'inputspec.aparc_aseg') workflow.connect(infosource, 'subject_id', roidevplot, 'inputspec.subject') workflow.connect(infosource, 'subject_id', roisnrplot, 'inputspec.subject') workflow.connect(infosource,("subject_id", myfssource, c.surf_dir),roisnrplot,"inputspec.aparc_aseg") workflow.connect(infosource,("subject_id", myfssource, c.surf_dir),roidevplot,"inputspec.aparc_aseg") tablecombine = pe.MapNode(util.Function(input_names = ['roidev', 'roisnr'], output_names = ['combined_table'], function = combine_table), name='combinetable', iterfield=['roidev','roisnr']) #workflow.connect(infosource,'subject_id',fssource,'subject_id') #workflow.connect(inputspec,'sd',fssource,'subjects_dir') #fssource.inputs.subjects_dir = c.surf_dir roisnrplot.inputs.inputspec.sd = c.surf_dir roidevplot.inputs.inputspec.sd = c.surf_dir workflow.connect(datagrabber,'datagrabber.art_intensity',art_info,'intensity_file') workflow.connect(datagrabber,'datagrabber.art_stats',art_info,'stats_file') workflow.connect(datagrabber,'datagrabber.outlier_files',art_info,'art_file') workflow.connect(datagrabber,'datagrabber.reg_file',roidevplot,'inputspec.reg_file') workflow.connect(datagrabber,'datagrabber.tsnr_stddev',roidevplot,'inputspec.tsnr_file') #workflow.connect(fssource,('aparc_aseg',pickaparc),roidevplot,'inputspec.aparc_aseg') workflow.connect(roidevplot,'outputspec.roi_table',tablecombine,'roidev') workflow.connect(datagrabber,'datagrabber.reg_file',roisnrplot,'inputspec.reg_file') workflow.connect(datagrabber,'datagrabber.tsnr',roisnrplot,'inputspec.tsnr_file') workflow.connect(roisnrplot,'outputspec.roi_table',tablecombine,'roisnr') js = pe.Node(interface=JSONSink(),name="jsoner") workflow.connect(tablecombine,"combined_table",js,"SNR_table") workflow.connect(art_info,"table",js,"art") workflow.connect(art_info,"out",js,"outliers") workflow.connect(datagrabber,("datagrabber.mincost",getmincost),js,"mincost") js.inputs.norm_thresh = prep_c.norm_thresh js.inputs.z_thresh = prep_c.z_thresh return workflow