Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rabies/analysis_pkg/diagnosis_pkg/diagnosis_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def plot_freqs(ax,timeseries, TR, frame_mask):

from scipy.signal import welch
fs = 1/TR
N = timeseries.shape[0]
N = timeseries_.shape[0]
# N//4 : proxy to scale the resolution of the filter to the number of data points
# minimum of 130 to be able to detect frequency spikes in the spectrum
nperseg = max(N // 4, 130)
Expand Down
2 changes: 1 addition & 1 deletion rabies/confound_correction_pkg/main_wf.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ def read_preproc_workflow(preproc_output, nativespace_analysis, preprocess_opts)

node_dict = get_workflow_dict(preproc_workflow_file)

match_targets = {'input_bold':['main_wf.input_bold', 'selected_file'],
match_targets = {'input_bold':['main_wf.select_input_bold', 'selected_file'],
'commonspace_mask':['main_wf.bold_main_wf.mask_commonspace_trans_wf.brain_mask_resample', 'resampled_file'],
'motion_params_csv':['main_wf.bold_main_wf.estimate_motion_node', 'motion_params_csv'],
'FD_csv':['main_wf.bold_main_wf.estimate_motion_node', 'FD_csv'],
Expand Down
22 changes: 10 additions & 12 deletions rabies/preprocess_pkg/bold_main_wf.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ def init_bold_main_wf(opts, output_folder, number_functional_scans, inho_cor_onl

**Outputs**

input_bold
The provided input BOLD file
bold_ref
Initial EPI median volume subsequently used as 3D reference EPI volume
motcorr_params
Expand Down Expand Up @@ -113,14 +111,14 @@ def init_bold_main_wf(opts, output_folder, number_functional_scans, inho_cor_onl
workflow = pe.Workflow(name=name)

inputnode = pe.Node(niu.IdentityInterface(
fields=['bold', 'inho_cor_anat', 'inho_cor_mask', 'coreg_anat', 'coreg_mask',
fields=['bold_file', 'inho_cor_anat', 'inho_cor_mask', 'coreg_anat', 'coreg_mask',
'anat_to_commonspace_transform_list','anat_to_commonspace_inverse_list',
'commonspace_to_anat_transform_list','commonspace_to_anat_inverse_list',
'commonspace_ref']),
name="inputnode")

outputnode = pe.Node(niu.IdentityInterface(
fields=['input_bold', 'bold_ref', 'motcorr_params', 'init_denoise', 'denoise_mask', 'corrected_EPI',
fields=['bold_ref', 'motcorr_params', 'init_denoise', 'denoise_mask', 'corrected_EPI',
'output_warped_bold', 'bold_to_anat_affine', 'bold_to_anat_warp', 'bold_to_anat_inverse_warp',
'native_bold', 'native_bold_ref', 'native_brain_mask', 'native_WM_mask', 'native_CSF_mask', 'native_vascular_mask',
'motion_params_csv', 'FD_voxelwise', 'pos_voxelwise', 'FD_csv', 'commonspace_bold', 'commonspace_mask',
Expand Down Expand Up @@ -181,12 +179,12 @@ def init_bold_main_wf(opts, output_folder, number_functional_scans, inho_cor_onl
function=apply_despike),
name='despike')
workflow.connect([
(inputnode, despike, [('bold', 'in_file')]),
(inputnode, despike, [('bold_file', 'in_file')]),
(despike, boldbuffer, [('out_file', 'bold_file')]),
])
else:
workflow.connect([
(inputnode, boldbuffer, [('bold', 'bold_file')]),
(inputnode, boldbuffer, [('bold_file', 'bold_file')]),
])

if opts.detect_dummy:
Expand Down Expand Up @@ -237,7 +235,7 @@ def remove_dummy(bold_file):
(inputnode, inho_cor_wf, [
('inho_cor_anat', 'inputnode.anat_ref'),
('inho_cor_mask', 'inputnode.anat_mask'),
('bold', 'inputnode.name_source'),
('bold_file', 'inputnode.name_source'),
]),
(template_inputnode, inho_cor_wf, [
("template_anat", "template_inputnode.template_anat"),
Expand Down Expand Up @@ -409,7 +407,7 @@ def transforms_buffernode(bold_to_commonspace_transform_list, bold_to_commonspac
('corrected_EPI', 'corrected_EPI'),
]),
(inputnode, estimate_motion_node, [
('bold', 'boldspace_bold'),
('bold_file', 'boldspace_bold'),
]),
(bold_hmc_wf, estimate_motion_node, [
('outputnode.motcorr_params', 'motcorr_params'),
Expand Down Expand Up @@ -438,7 +436,7 @@ def transforms_buffernode(bold_to_commonspace_transform_list, bold_to_commonspac

workflow.connect([
(inputnode, boldspace_brain_mask, [
('bold', 'name_source'),
('bold_file', 'name_source'),
]),
(transitionnode, boldspace_brain_mask, [
('bold_ref', 'ref_file'),
Expand Down Expand Up @@ -510,10 +508,10 @@ def transforms_buffernode(bold_to_commonspace_transform_list, bold_to_commonspac
(bold_hmc_wf, bold_native_trans_wf, [
('outputnode.motcorr_params', 'inputnode.motcorr_params')]),
(inputnode, bold_native_trans_wf, [
('bold', 'inputnode.name_source'),
('bold_file', 'inputnode.name_source'),
]),
(inputnode, mask_native_trans_wf, [
('bold', 'inputnode.name_source'),
('bold_file', 'inputnode.name_source'),
]),
(bold_native_trans_wf, mask_native_trans_wf, [
('outputnode.bold_ref','inputnode.ref_file'),
Expand Down Expand Up @@ -544,7 +542,7 @@ def transforms_buffernode(bold_to_commonspace_transform_list, bold_to_commonspac
(bold_hmc_wf, bold_commonspace_trans_wf, [
('outputnode.motcorr_params', 'inputnode.motcorr_params')]),
(inputnode, bold_commonspace_trans_wf, [
('bold', 'inputnode.name_source'),
('bold_file', 'inputnode.name_source'),
('commonspace_ref', 'inputnode.ref_file'),
]),
(bold_commonspace_trans_wf, outputnode, [
Expand Down
59 changes: 18 additions & 41 deletions rabies/preprocess_pkg/main_wf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import pathlib
from nipype.pipeline import engine as pe
from nipype.interfaces import utility as niu
from nipype.interfaces.io import DataSink
Expand Down Expand Up @@ -30,9 +29,6 @@ def init_main_wf(data_dir_path, output_folder, opts, name='main_wf'):

**Outputs**


input_bold
Input EPIs to the preprocessing
commonspace_resampled_template
the anatomical commonspace template after initial resampling
anat_preproc
Expand Down Expand Up @@ -100,7 +96,7 @@ def init_main_wf(data_dir_path, output_folder, opts, name='main_wf'):

# set output node
outputnode = pe.Node(niu.IdentityInterface(
fields=['input_bold', 'commonspace_resampled_template', 'anat_preproc', 'initial_bold_ref', 'inho_cor_bold', 'bold_to_anat_affine',
fields=['commonspace_resampled_template', 'anat_preproc', 'initial_bold_ref', 'inho_cor_bold', 'bold_to_anat_affine',
'bold_to_anat_warp', 'bold_to_anat_inverse_warp', 'inho_cor_bold_warped2anat', 'native_bold', 'native_bold_ref', 'motion_params_csv',
'FD_voxelwise', 'pos_voxelwise', 'FD_csv', 'native_brain_mask', 'native_WM_mask', 'native_CSF_mask', 'native_vascular_mask',
'commonspace_bold', 'commonspace_mask', 'commonspace_WM_mask', 'commonspace_CSF_mask', 'commonspace_vascular_mask',
Expand Down Expand Up @@ -178,38 +174,25 @@ def init_main_wf(data_dir_path, output_folder, opts, name='main_wf'):
'''
MATCHING INPUTS TO MAIN ITERABLES
'''
format_bold_node = pe.Node(Function(input_names=['scan_info', 'run', 'joined_scan_info', 'joined_run', 'joined_file_list'],
output_names=['selected_file'],
function=match_iterables),
name='format_bold')

input_bold_node = pe.Node(Function(input_names=['scan_info', 'run', 'joined_scan_info', 'joined_run', 'joined_file_list'],
select_input_bold_node = pe.Node(Function(input_names=['scan_info', 'run', 'joined_scan_info', 'joined_run', 'joined_file_list'],
output_names=['selected_file'],
function=match_iterables),
name='input_bold')

name='select_input_bold')
workflow.connect([
(prep_input_wf, format_bold_node, [
("outputnode.prep_bold_list", "joined_file_list"),
("outputnode.joined_scan_info", "joined_scan_info"),
]),
(main_split, format_bold_node, [
("scan_info", "scan_info"),
]),
(prep_input_wf, input_bold_node, [
(prep_input_wf, select_input_bold_node, [
("outputnode.input_bold_list", "joined_file_list"),
("outputnode.joined_scan_info", "joined_scan_info"),
]),
(main_split, input_bold_node, [
(main_split, select_input_bold_node, [
("scan_info", "scan_info"),
]),
])

if opts.bold_only:
format_bold_node.inputs.run = None
input_bold_node.inputs.run = None
format_bold_node.inputs.joined_run = None
input_bold_node.inputs.joined_run = None
select_input_bold_node.inputs.run = None
select_input_bold_node.inputs.joined_run = None
else:
run_split = pe.Node(niu.IdentityInterface(fields=['run', 'split_name']),
name="run_split")
Expand All @@ -220,16 +203,10 @@ def init_main_wf(data_dir_path, output_folder, opts, name='main_wf'):
(main_split, run_split, [
("split_name", "split_name"),
]),
(prep_input_wf, format_bold_node, [
("outputnode.joined_run", "joined_run"),
]),
(run_split, format_bold_node, [
("run", "run"),
]),
(prep_input_wf, input_bold_node, [
(prep_input_wf, select_input_bold_node, [
("outputnode.joined_run", "joined_run"),
]),
(run_split, input_bold_node, [
(run_split, select_input_bold_node, [
("run", "run"),
]),
])
Expand Down Expand Up @@ -341,8 +318,8 @@ def init_main_wf(data_dir_path, output_folder, opts, name='main_wf'):

# MAIN WORKFLOW STRUCTURE #######################################################
workflow.connect([
(format_bold_node, bold_main_wf, [
("selected_file", "inputnode.bold"),
(select_input_bold_node, bold_main_wf, [
("selected_file", "inputnode.bold_file"),
]),
(resample_template_node, template_diagnosis, [
("registration_template", "anat_template"),
Expand Down Expand Up @@ -393,13 +370,13 @@ def init_main_wf(data_dir_path, output_folder, opts, name='main_wf'):
("outputnode.corrected_EPI", "final_denoise"),
("outputnode.denoise_mask", "warped_mask"),
]),
(input_bold_node, bold_inho_cor_diagnosis,
(select_input_bold_node, bold_inho_cor_diagnosis,
[("selected_file", "name_source")]),
(bold_main_wf, temporal_diagnosis, [
("outputnode.motion_params_csv", "motion_params_csv"),
("outputnode.FD_csv", "FD_csv"),
]),
(input_bold_node, temporal_diagnosis,
(select_input_bold_node, temporal_diagnosis,
[("selected_file", "name_source")]),
(temporal_diagnosis, outputnode, [
("tSNR_filename", "tSNR_filename"),
Expand Down Expand Up @@ -491,8 +468,8 @@ def init_main_wf(data_dir_path, output_folder, opts, name='main_wf'):
("registration_template", "template_inputnode.template_anat"),
("registration_mask", "template_inputnode.template_mask"),
]),
(format_bold_node, inho_cor_bold_main_wf, [
("selected_file", "inputnode.bold"),
(select_input_bold_node, inho_cor_bold_main_wf, [
("selected_file", "inputnode.bold_file"),
]),
(EPI_target_buffer, inho_cor_bold_main_wf, [
("EPI_template", "inputnode.inho_cor_anat"),
Expand Down Expand Up @@ -522,7 +499,7 @@ def init_main_wf(data_dir_path, output_folder, opts, name='main_wf'):
preprocess_visual_QC.PlotOverlap(), name='PlotOverlap_EPI2Anat')
PlotOverlap_EPI2Anat_node.inputs.out_dir = output_folder+'/preprocess_QC_report/EPI2Anat'
workflow.connect([
(input_bold_node, PlotOverlap_EPI2Anat_node,
(select_input_bold_node, PlotOverlap_EPI2Anat_node,
[("selected_file", "name_source")]),
(anat_inho_cor_wf, PlotOverlap_EPI2Anat_node,
[("outputnode.corrected", "fixed")]),
Expand All @@ -533,7 +510,7 @@ def init_main_wf(data_dir_path, output_folder, opts, name='main_wf'):

# fill the datasinks
workflow.connect([
(input_bold_node, bold_datasink, [
(select_input_bold_node, bold_datasink, [
("selected_file", "input_bold"),
]),
(outputnode, motion_datasink, [
Expand Down
Loading