From 7319c93f515b6eece874228d3f9f4f09f471dc28 Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Thu, 17 Dec 2020 16:54:13 -0500 Subject: [PATCH 1/6] Add mask_file arg to T2SMap. --- fmriprep/interfaces/multiecho.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fmriprep/interfaces/multiecho.py b/fmriprep/interfaces/multiecho.py index 25fb12ec7..be0078e08 100644 --- a/fmriprep/interfaces/multiecho.py +++ b/fmriprep/interfaces/multiecho.py @@ -38,9 +38,14 @@ class T2SMapInputSpec(CommandLineInputSpec): mandatory=True, minlen=3, desc='echo times') + mask_file = File(argstr='--mask', + position=3, + mandatory=False, + desc='mask file', + exists=True) fittype = traits.Enum('curvefit', 'loglin', argstr='--fittype %s', - position=3, + position=4, usedefault=True, desc=('Desired fitting method: ' '"loglin" means that a linear model is fit ' From 50d64f810e401b94fe6251a2a988c7cfc5dabc6f Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Thu, 17 Dec 2020 16:54:33 -0500 Subject: [PATCH 2/6] Add mask_file to init_bold_t2s_wf. --- fmriprep/workflows/bold/t2s.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fmriprep/workflows/bold/t2s.py b/fmriprep/workflows/bold/t2s.py index d9648aa85..9b5cd4bc3 100644 --- a/fmriprep/workflows/bold/t2s.py +++ b/fmriprep/workflows/bold/t2s.py @@ -49,6 +49,8 @@ def init_bold_t2s_wf(echo_times, mem_gb, omp_nthreads, ------ bold_file list of individual echo files + mask_file + a binary mask to apply to the BOLD files Outputs ------- @@ -70,7 +72,7 @@ def init_bold_t2s_wf(echo_times, mem_gb, omp_nthreads, The optimally combined time series was carried forward as the *preprocessed BOLD*. """ - inputnode = pe.Node(niu.IdentityInterface(fields=['bold_file']), name='inputnode') + inputnode = pe.Node(niu.IdentityInterface(fields=['bold_file', 'mask_file']), name='inputnode') outputnode = pe.Node(niu.IdentityInterface(fields=['bold']), name='outputnode') @@ -79,7 +81,7 @@ def init_bold_t2s_wf(echo_times, mem_gb, omp_nthreads, t2smap_node = pe.Node(T2SMap(echo_times=list(echo_times)), name='t2smap_node') workflow.connect([ - (inputnode, t2smap_node, [('bold_file', 'in_files')]), + (inputnode, t2smap_node, [('bold_file', 'in_files'), ('mask_file', 'mask_file')]), (t2smap_node, outputnode, [('optimal_comb', 'bold')]), ]) From 68539b94634bb60208c4cb64e70894284b0e1c3f Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Thu, 17 Dec 2020 16:55:08 -0500 Subject: [PATCH 3/6] Skull-strip only first echo and use that mask. --- fmriprep/workflows/bold/base.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/fmriprep/workflows/bold/base.py b/fmriprep/workflows/bold/base.py index 37c4d43cb..f69232cb2 100644 --- a/fmriprep/workflows/bold/base.py +++ b/fmriprep/workflows/bold/base.py @@ -421,9 +421,9 @@ def init_func_preproc_wf(bold_file): inputnode.inputs.bold_file = ref_file # Replace reference w first echo join_echos = pe.JoinNode( - niu.IdentityInterface(fields=['bold_files', 'skullstripped_bold_files']), + niu.IdentityInterface(fields=['bold_files']), joinsource=('meepi_echos' if run_stc is True else 'boldbuffer'), - joinfield=['bold_files', 'skullstripped_bold_files'], + joinfield=['bold_files'], name='join_echos' ) @@ -539,12 +539,12 @@ def init_func_preproc_wf(bold_file): ('outputnode.bold', 'bold_files')]), (join_echos, final_boldref_wf, [ ('bold_files', 'inputnode.bold_file')]), - (bold_bold_trans_wf, skullstrip_bold_wf, [ - ('outputnode.bold', 'inputnode.in_file')]), - (skullstrip_bold_wf, join_echos, [ - ('outputnode.skull_stripped_file', 'skullstripped_bold_files')]), + (join_echos, skullstrip_bold_wf, [ + (('bold_files', pop_file), 'inputnode.in_file')]), + (skullstrip_bold_wf, bold_t2s_wf, [ + ('outputnode.mask_file', 'inputnode.mask_file')]), (join_echos, bold_t2s_wf, [ - ('skullstripped_bold_files', 'inputnode.bold_file')]), + ('bold_files', 'inputnode.bold_file')]), (bold_t2s_wf, bold_confounds_wf, [ ('outputnode.bold', 'inputnode.bold')]), (bold_t2s_wf, split_opt_comb, [ From 1254b9146c31dececc8eda7fa8891b308b872798 Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Thu, 17 Dec 2020 17:06:04 -0500 Subject: [PATCH 4/6] Use mask from bold_sdc_wf instead of skullstrip_wf. --- fmriprep/workflows/bold/base.py | 10 +++------- fmriprep/workflows/bold/t2s.py | 6 +++--- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/fmriprep/workflows/bold/base.py b/fmriprep/workflows/bold/base.py index f69232cb2..0666ea9d4 100644 --- a/fmriprep/workflows/bold/base.py +++ b/fmriprep/workflows/bold/base.py @@ -413,9 +413,6 @@ def init_func_preproc_wf(bold_file): # MULTI-ECHO EPI DATA ############################################# if multiecho: # instantiate relevant interfaces, imports - from niworkflows.func.util import init_skullstrip_bold_wf - skullstrip_bold_wf = init_skullstrip_bold_wf(name='skullstrip_bold_wf') - split_opt_comb = bold_split.clone(name='split_opt_comb') inputnode.inputs.bold_file = ref_file # Replace reference w first echo @@ -539,10 +536,9 @@ def init_func_preproc_wf(bold_file): ('outputnode.bold', 'bold_files')]), (join_echos, final_boldref_wf, [ ('bold_files', 'inputnode.bold_file')]), - (join_echos, skullstrip_bold_wf, [ - (('bold_files', pop_file), 'inputnode.in_file')]), - (skullstrip_bold_wf, bold_t2s_wf, [ - ('outputnode.mask_file', 'inputnode.mask_file')]), + # use same mask used by bold_bold_trans_wf + (bold_sdc_wf, bold_t2s_wf, [ + ('outputnode.epi_mask', 'inputnode.bold_mask')]), (join_echos, bold_t2s_wf, [ ('bold_files', 'inputnode.bold_file')]), (bold_t2s_wf, bold_confounds_wf, [ diff --git a/fmriprep/workflows/bold/t2s.py b/fmriprep/workflows/bold/t2s.py index 9b5cd4bc3..49488f677 100644 --- a/fmriprep/workflows/bold/t2s.py +++ b/fmriprep/workflows/bold/t2s.py @@ -49,7 +49,7 @@ def init_bold_t2s_wf(echo_times, mem_gb, omp_nthreads, ------ bold_file list of individual echo files - mask_file + bold_mask a binary mask to apply to the BOLD files Outputs @@ -72,7 +72,7 @@ def init_bold_t2s_wf(echo_times, mem_gb, omp_nthreads, The optimally combined time series was carried forward as the *preprocessed BOLD*. """ - inputnode = pe.Node(niu.IdentityInterface(fields=['bold_file', 'mask_file']), name='inputnode') + inputnode = pe.Node(niu.IdentityInterface(fields=['bold_file', 'bold_mask']), name='inputnode') outputnode = pe.Node(niu.IdentityInterface(fields=['bold']), name='outputnode') @@ -81,7 +81,7 @@ def init_bold_t2s_wf(echo_times, mem_gb, omp_nthreads, t2smap_node = pe.Node(T2SMap(echo_times=list(echo_times)), name='t2smap_node') workflow.connect([ - (inputnode, t2smap_node, [('bold_file', 'in_files'), ('mask_file', 'mask_file')]), + (inputnode, t2smap_node, [('bold_file', 'in_files'), ('bold_mask', 'mask_file')]), (t2smap_node, outputnode, [('optimal_comb', 'bold')]), ]) From 0e40835cee445c280a25ce8fe8421890a0eb87dc Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Thu, 17 Dec 2020 17:13:19 -0500 Subject: [PATCH 5/6] Use bold_bold_trans_wf instead. I didn't realize that the bold_bold_trans_wf included the mask as an output too. Still need to select the first one, although the mask should be the same across echoes. --- fmriprep/workflows/bold/base.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fmriprep/workflows/bold/base.py b/fmriprep/workflows/bold/base.py index 0666ea9d4..f210c364b 100644 --- a/fmriprep/workflows/bold/base.py +++ b/fmriprep/workflows/bold/base.py @@ -536,9 +536,9 @@ def init_func_preproc_wf(bold_file): ('outputnode.bold', 'bold_files')]), (join_echos, final_boldref_wf, [ ('bold_files', 'inputnode.bold_file')]), - # use same mask used by bold_bold_trans_wf - (bold_sdc_wf, bold_t2s_wf, [ - ('outputnode.epi_mask', 'inputnode.bold_mask')]), + # use reference image mask used by bold_bold_trans_wf + (bold_bold_trans_wf, bold_t2s_wf, [ + (('outputnode.bold_mask', pop_file), 'inputnode.bold_mask')]), (join_echos, bold_t2s_wf, [ ('bold_files', 'inputnode.bold_file')]), (bold_t2s_wf, bold_confounds_wf, [ From cd88ca6aad9f8c4386144af3c3e607e5422ac13c Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Thu, 17 Dec 2020 17:34:59 -0500 Subject: [PATCH 6/6] Update fmriprep/workflows/bold/t2s.py Co-authored-by: Oscar Esteban --- fmriprep/workflows/bold/t2s.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fmriprep/workflows/bold/t2s.py b/fmriprep/workflows/bold/t2s.py index 49488f677..280923ca1 100644 --- a/fmriprep/workflows/bold/t2s.py +++ b/fmriprep/workflows/bold/t2s.py @@ -81,7 +81,8 @@ def init_bold_t2s_wf(echo_times, mem_gb, omp_nthreads, t2smap_node = pe.Node(T2SMap(echo_times=list(echo_times)), name='t2smap_node') workflow.connect([ - (inputnode, t2smap_node, [('bold_file', 'in_files'), ('bold_mask', 'mask_file')]), + (inputnode, t2smap_node, [('bold_file', 'in_files'), + ('bold_mask', 'mask_file')]), (t2smap_node, outputnode, [('optimal_comb', 'bold')]), ])