Skip to content

Commit

Permalink
Merge pull request #271 from madisoth/enh/t2-vol-out
Browse files Browse the repository at this point in the history
ENH: Add preprocessed T2w volume to outputs
  • Loading branch information
mgxd authored Jan 18, 2023
2 parents 5b20166 + 0e2861f commit 737e62c
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 31 deletions.
1 change: 1 addition & 0 deletions .circleci/bcp_anat_outputs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_space-MNIInfant_cohort-1_dseg.nii.gz
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_space-MNIInfant_cohort-1_label-CSF_probseg.nii.gz
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_space-MNIInfant_cohort-1_label-GM_probseg.nii.gz
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_space-MNIInfant_cohort-1_label-WM_probseg.nii.gz
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_space-T1w_desc-preproc_T2w.nii.gz
1 change: 1 addition & 0 deletions .circleci/bcp_full_outputs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_space-MNIInfant_cohort-1_dseg.nii.gz
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_space-MNIInfant_cohort-1_label-CSF_probseg.nii.gz
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_space-MNIInfant_cohort-1_label-GM_probseg.nii.gz
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_space-MNIInfant_cohort-1_label-WM_probseg.nii.gz
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_space-T1w_desc-preproc_T2w.nii.gz
sub-01/ses-1mo/fmap
sub-01/ses-1mo/fmap/sub-01_ses-1mo_run-001_fmapid-auto00000_desc-coeff_fieldmap.nii.gz
sub-01/ses-1mo/fmap/sub-01_ses-1mo_run-001_fmapid-auto00000_desc-epi_fieldmap.nii.gz
Expand Down
86 changes: 55 additions & 31 deletions nibabies/workflows/anatomical/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ def init_infant_anat_wf(
"""
from nipype.interfaces.ants.base import Info as ANTsInfo
from niworkflows.engine.workflows import LiterateWorkflow as Workflow
from sdcflows.workflows.ancillary import (
init_brainextraction_wf as init_sdc_brain_extraction_wf,
)

from ...utils.misc import fix_multi_source_name
from .brain_extraction import (
Expand Down Expand Up @@ -214,25 +217,26 @@ def init_infant_anat_wf(
if precomp_mask:
precomp_mask_wf = init_precomputed_mask_wf(omp_nthreads=omp_nthreads)
precomp_mask_wf.inputs.inputnode.t1w_mask = precomp_mask

else:
brain_extraction_wf = init_infant_brain_extraction_wf(
age_months=age_months,
ants_affine_init=ants_affine_init,
skull_strip_template=skull_strip_template.space,
template_specs=skull_strip_template.spec,
omp_nthreads=omp_nthreads,
sloppy=sloppy,
debug="registration" in config.execution.debug,
)
coregistration_wf = init_coregistration_wf(
omp_nthreads=omp_nthreads,
sloppy=sloppy,
debug="registration" in config.execution.debug,
)
coreg_report_wf = init_coreg_report_wf(
output_dir=output_dir,
sdc_brain_extraction_wf = init_sdc_brain_extraction_wf(
name="sdc_brain_extraction_wf",
)
brain_extraction_wf = init_infant_brain_extraction_wf(
age_months=age_months,
ants_affine_init=ants_affine_init,
skull_strip_template=skull_strip_template.space,
template_specs=skull_strip_template.spec,
omp_nthreads=omp_nthreads,
sloppy=sloppy,
debug="registration" in config.execution.debug,
)
coregistration_wf = init_coregistration_wf(
omp_nthreads=omp_nthreads,
sloppy=sloppy,
debug="registration" in config.execution.debug,
)
coreg_report_wf = init_coreg_report_wf(
output_dir=output_dir,
)
t1w_preproc_wf = precomp_mask_wf if precomp_mask else coregistration_wf

# Segmentation - initial implementation should be simple: JLF
Expand Down Expand Up @@ -285,6 +289,9 @@ def init_infant_anat_wf(
("outputnode.t1w_mask", "inputnode.t1w_mask"),
("outputnode.t1w_preproc", "inputnode.t1w_preproc"),
]),
(coregistration_wf, anat_derivatives_wf, [
("outputnode.t2w_preproc", "inputnode.t2w_preproc")
]),
(t1w_preproc_wf, outputnode, [
("outputnode.t1w_preproc", "anat_preproc"),
("outputnode.t1w_brain", "anat_brain"),
Expand All @@ -296,36 +303,50 @@ def init_infant_anat_wf(
wf.connect([
(t1w_preproc_wf, anat_seg_wf, [("outputnode.t1w_brain", "inputnode.anat_brain")]),
])

wf.connect([
(inputnode, t2w_template_wf, [("t2w", "inputnode.in_files")]),
])
if precomp_mask:
wf.connect([
(t1w_template_wf, precomp_mask_wf, [
("outputnode.out_file", "inputnode.t1w"),
]),
(t2w_template_wf, sdc_brain_extraction_wf, [
("outputnode.out_file", "inputnode.in_file"),
]),
(sdc_brain_extraction_wf, coregistration_wf, [
("outputnode.out_file", "inputnode.in_t2w_preproc"),
("outputnode.out_mask", "inputnode.in_mask"),
("outputnode.out_probseg", "inputnode.in_probmap"),
]),
])
else:
wf.connect([
(inputnode, t2w_template_wf, [("t2w", "inputnode.in_files")]),
(t2w_template_wf, brain_extraction_wf, [
("outputnode.out_file", "inputnode.in_t2w"),
]),
(t1w_template_wf, coregistration_wf, [
("outputnode.out_file", "inputnode.in_t1w"),
]),
(brain_extraction_wf, coregistration_wf, [
("outputnode.t2w_preproc", "inputnode.in_t2w_preproc"),
("outputnode.out_mask", "inputnode.in_mask"),
("outputnode.out_probmap", "inputnode.in_probmap"),
]),
(inputnode, coreg_report_wf, [
("t1w", "inputnode.source_file"),
]),
(t1w_preproc_wf, coreg_report_wf, [
("outputnode.t1w_preproc", "inputnode.t1w_preproc"),
("outputnode.t2w_preproc", "inputnode.t2w_preproc"),
("outputnode.t1w_mask", "inputnode.in_mask"),
]),
])
wf.connect([
(t1w_template_wf, coregistration_wf, [
("outputnode.out_file", "inputnode.in_t1w"),
]),

(inputnode, coreg_report_wf, [
("t1w", "inputnode.source_file"),
]),
(t1w_preproc_wf, coreg_report_wf, [
("outputnode.t1w_preproc", "inputnode.t1w_preproc"),
("outputnode.t1w_mask", "inputnode.in_mask"),
]),
(coregistration_wf, coreg_report_wf, [
("outputnode.t2w_preproc", "inputnode.t2w_preproc")
]),
])

wf.connect([
# reports
Expand All @@ -350,6 +371,9 @@ def init_infant_anat_wf(
("outputnode.valid_list", "inputnode.source_files"),
("outputnode.realign_xfms", "inputnode.t1w_ref_xfms"),
]),
(t2w_template_wf, anat_derivatives_wf, [
("outputnode.valid_list", "inputnode.t2w_source_files"),
]),
(anat_norm_wf, anat_derivatives_wf, [
("outputnode.template", "inputnode.template"),
("outputnode.anat2std_xfm", "inputnode.anat2std_xfm"),
Expand Down
16 changes: 16 additions & 0 deletions nibabies/workflows/anatomical/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ def init_anat_derivatives_wf(
FreeSurfer's aseg segmentation, in native T1w space
t1w_fs_aparc
FreeSurfer's aparc+aseg segmentation, in native T1w space
t2w_source_files
List of input T2w images
t2w_preproc
The T2w image in T1w space.
"""
from niworkflows.interfaces.nibabel import ApplyMask
from niworkflows.interfaces.utility import KeySelect
Expand Down Expand Up @@ -341,6 +345,8 @@ def init_anat_derivatives_wf(
"morphometrics",
"t1w_fs_aseg",
"t1w_fs_aparc",
"t2w_source_files",
"t2w_preproc",
]
),
name="inputnode",
Expand Down Expand Up @@ -369,6 +375,14 @@ def init_anat_derivatives_wf(
run_without_submitting=True,
)

ds_t2w_preproc = pe.Node(
DerivativesDataSink(
data_dtype="i2", base_directory=output_dir, space="T1w", desc="preproc", compress=True
),
name="ds_t2w_preproc",
run_without_submitting=True,
)

ds_t1w_tpms = pe.Node(
DerivativesDataSink(base_directory=output_dir, suffix="probseg", compress=True),
name="ds_t1w_tpms",
Expand All @@ -381,6 +395,8 @@ def init_anat_derivatives_wf(
(inputnode, raw_sources, [('source_files', 'in_files')]),
(inputnode, ds_t1w_preproc, [('t1w_preproc', 'in_file'),
('source_files', 'source_file')]),
(inputnode, ds_t2w_preproc, [('t2w_preproc', 'in_file'),
('t2w_source_files', 'source_file')]),
(inputnode, ds_t1w_mask, [('t1w_mask', 'in_file'),
('source_files', 'source_file')]),
(inputnode, ds_t1w_tpms, [('t1w_tpms', 'in_file'),
Expand Down

0 comments on commit 737e62c

Please sign in to comment.