Skip to content

Commit

Permalink
Stop ingressing anatomical-space tissue segmentation file (PennLINC#1190
Browse files Browse the repository at this point in the history
)
  • Loading branch information
tsalo authored Sep 4, 2024
1 parent 8598d05 commit 940bd1d
Show file tree
Hide file tree
Showing 19 changed files with 5 additions and 109 deletions.
3 changes: 1 addition & 2 deletions docs/outputs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Atlases are written out to the ``atlases`` subfolder, following BEP038.
Anatomical Outputs
******************

Anatomical outputs consist of anatomical preprocessed T1w/T2w and segmentation images in MNI space.
Anatomical outputs consist of anatomical preprocessed T1w and/or T2w images in MNI space.

.. code-block::
Expand All @@ -116,7 +116,6 @@ Anatomical outputs consist of anatomical preprocessed T1w/T2w and segmentation i
anat/
<source_entities>_space-MNI152NLin6Asym_desc-preproc_T1w.nii.gz
<source_entities>_space-MNI152NLin6Asym_desc-preproc_T2w.nii.gz
<source_entities>_space-MNI152NLin6Asym_dseg.nii.gz
Surface mesh files
Expand Down
3 changes: 0 additions & 3 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,6 @@ We recommend NOT setting the datatype, suffix, or file extension in the filter f
``"t2w"`` selects a native T1w-space, preprocessed T2w file.
If a T1w file is not available, this file will be in T2w space.

``"anat_dseg"`` selects a segmentation file in the same space as the BOLD data.
This file is not used for anything.

``"anat_brainmask"`` selects an anatomically-derived brain mask in the same space as the BOLD data.
This file is used (1) to estimate head radius for FD calculation and
(2) to calculate coregistration quality metrics.
Expand Down
3 changes: 1 addition & 2 deletions docs/workflows.rst
Original file line number Diff line number Diff line change
Expand Up @@ -872,8 +872,7 @@ Second, XCP-D outputs processed BOLD data, including denoised unsmoothed and smo
MNI152NLin2009cAsym and fsLR-32k spaces, parcellated time series, functional connectivity matrices,
and ALFF and ReHo (smoothed and unsmoothed).

Third, the anatomical data (processed T1w processed and segmentation files) are copied from
fMRIPrep.
Third, the anatomical data (processed T1w and/or T2w files) are copied from fMRIPrep.
If both images are not in MNI152NLin6Asym space, they are resampled to MNI space.
The fMRIPrep surfaces (gifti files) in each subject are also resampled to standard space
(fsLR-32K).
Expand Down
10 changes: 0 additions & 10 deletions xcp_d/data/io_spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@ queries:
desc: brain
extension: .nii.gz
suffix: mask
# native anatomical-space dseg file
anat_dseg:
datatype: anat
desc: null
extension: .nii.gz
space:
- T1w
- T2w
- null
suffix: dseg
# transform from native anatomical (T1w or T2w) space to same standard space as BOLD
# "to" entity will be set later
anat_to_template_xfm:
Expand Down
7 changes: 0 additions & 7 deletions xcp_d/ingression/ukbiobank.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,6 @@ def convert_ukb_to_bids_single_subject(in_dir, out_dir, sub_id, ses_id):
f"{subses_ents}_space-{VOLSPACE}_desc-brain_mask.nii.gz",
)
)
# Use the brain mask as the "aparcaseg" dseg too.
copy_dictionary[warp_brainmask_to_std_results.outputs.out_file].append(
os.path.join(
anat_dir_bids,
f"{subses_ents}_space-{VOLSPACE}_desc-aparcaseg_dseg.nii.gz",
)
)

# Warp the reference file to MNI space.
warp_boldref_to_std = ApplyWarp(
Expand Down
1 change: 0 additions & 1 deletion xcp_d/ingression/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def collect_anatomical_files(anat_dir_orig, anat_dir_bids, base_anatomical_ents)
"T1w.nii.gz": "desc-preproc_T1w.nii.gz",
"brainmask_fs.nii.gz": "desc-brain_mask.nii.gz",
"ribbon.nii.gz": "desc-ribbon_T1w.nii.gz",
"aparc+aseg.nii.gz": "desc-aparcaseg_dseg.nii.gz",
}
copy_dictionary = {}

Expand Down
14 changes: 0 additions & 14 deletions xcp_d/interfaces/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,6 @@ class _ConvertTo32InputSpec(BaseInterfaceInputSpec):
mandatory=False,
usedefault=True,
)
anat_dseg = traits.Either(
None,
File(exists=True),
desc="T1-space segmentation file",
mandatory=False,
usedefault=True,
)


class _ConvertTo32OutputSpec(TraitedSpec):
Expand Down Expand Up @@ -104,12 +97,6 @@ class _ConvertTo32OutputSpec(TraitedSpec):
desc="T2-weighted anatomical file",
mandatory=False,
)
anat_dseg = traits.Either(
None,
File(exists=True),
desc="T1-space segmentation file",
mandatory=False,
)


class ConvertTo32(SimpleInterface):
Expand All @@ -124,7 +111,6 @@ def _run_interface(self, runtime):
self._results["bold_mask"] = downcast_to_32(self.inputs.bold_mask)
self._results["t1w"] = downcast_to_32(self.inputs.t1w)
self._results["t2w"] = downcast_to_32(self.inputs.t2w)
self._results["anat_dseg"] = downcast_to_32(self.inputs.anat_dseg)

return runtime

Expand Down
5 changes: 0 additions & 5 deletions xcp_d/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ def ds001419_data(datasets):
anat_dir,
"sub-01_space-MNI152NLin2009cAsym_res-2_desc-preproc_T1w.nii.gz",
)
files["anat_dseg"] = os.path.join(anat_dir, "sub-01_desc-aseg_dseg.nii.gz")

return files

Expand Down Expand Up @@ -182,10 +181,6 @@ def pnc_data(datasets):
"res-2_desc-preproc_T1w.nii.gz"
),
)
files["anat_dseg"] = os.path.join(
anat_dir,
"sub-1648798153_ses-PNC1_acq-refaced_desc-aseg_dseg.nii.gz",
)

return files

Expand Down
1 change: 0 additions & 1 deletion xcp_d/tests/data/test_ds001419_cifti_outputs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ sub-01
sub-01.html
sub-01/anat
sub-01/anat/sub-01_space-MNI152NLin2009cAsym_desc-preproc_T1w.nii.gz
sub-01/anat/sub-01_space-MNI152NLin2009cAsym_dseg.nii.gz
sub-01/func
sub-01/func/sub-01_task-imagery_desc-abcc_qc.hdf5
sub-01/func/sub-01_task-imagery_desc-filtered_motion.json
Expand Down
1 change: 0 additions & 1 deletion xcp_d/tests/data/test_ds001419_nifti_outputs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ sub-01
sub-01.html
sub-01/anat
sub-01/anat/sub-01_space-MNI152NLin2009cAsym_desc-preproc_T1w.nii.gz
sub-01/anat/sub-01_space-MNI152NLin2009cAsym_dseg.nii.gz
sub-01/func
sub-01/func/sub-01_task-imagery_desc-filtered_motion.json
sub-01/func/sub-01_task-imagery_desc-filtered_motion.tsv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ sub-01
sub-01.html
sub-01/anat
sub-01/anat/sub-01_space-MNI152NLin2009cAsym_desc-preproc_T1w.nii.gz
sub-01/anat/sub-01_space-MNI152NLin2009cAsym_dseg.nii.gz
sub-01/func
sub-01/func/sub-01_task-mixedgamblestask_run-1_desc-abcc_qc.hdf5
sub-01/func/sub-01_task-mixedgamblestask_run-1_desc-preproc_design.json
Expand Down
1 change: 0 additions & 1 deletion xcp_d/tests/data/test_nibabies_outputs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ sub-01.html
sub-01/ses-1mo
sub-01/ses-1mo/anat
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_space-MNIInfant_cohort-1_desc-preproc_T1w.nii.gz
sub-01/ses-1mo/anat/sub-01_ses-1mo_run-001_space-MNIInfant_cohort-1_dseg.nii.gz
sub-01/ses-1mo/func
sub-01/ses-1mo/func/sub-01_ses-1mo_task-rest_acq-PA_run-001_desc-abcc_qc.hdf5
sub-01/ses-1mo/func/sub-01_ses-1mo_task-rest_acq-PA_run-001_desc-preproc_design.json
Expand Down
1 change: 0 additions & 1 deletion xcp_d/tests/data/test_pnc_cifti_outputs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ sub-1648798153.html
sub-1648798153/ses-PNC1
sub-1648798153/ses-PNC1/anat
sub-1648798153/ses-PNC1/anat/sub-1648798153_ses-PNC1_acq-refaced_space-MNI152NLin6Asym_desc-preproc_T1w.nii.gz
sub-1648798153/ses-PNC1/anat/sub-1648798153_ses-PNC1_acq-refaced_space-MNI152NLin6Asym_dseg.nii.gz
sub-1648798153/ses-PNC1/anat/sub-1648798153_ses-PNC1_acq-refaced_space-fsLR_den-32k_hemi-L_desc-hcp_inflated.surf.gii
sub-1648798153/ses-PNC1/anat/sub-1648798153_ses-PNC1_acq-refaced_space-fsLR_den-32k_hemi-L_desc-hcp_midthickness.surf.gii
sub-1648798153/ses-PNC1/anat/sub-1648798153_ses-PNC1_acq-refaced_space-fsLR_den-32k_hemi-L_desc-hcp_vinflated.surf.gii
Expand Down
1 change: 0 additions & 1 deletion xcp_d/tests/data/test_pnc_cifti_t2wonly_outputs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ sub-1648798153.html
sub-1648798153/ses-PNC1
sub-1648798153/ses-PNC1/anat
sub-1648798153/ses-PNC1/anat/sub-1648798153_ses-PNC1_acq-refaced_space-MNI152NLin6Asym_desc-preproc_T2w.nii.gz
sub-1648798153/ses-PNC1/anat/sub-1648798153_ses-PNC1_acq-refaced_space-MNI152NLin6Asym_dseg.nii.gz
sub-1648798153/ses-PNC1/anat/sub-1648798153_ses-PNC1_acq-refaced_space-fsLR_den-32k_hemi-L_desc-hcp_inflated.surf.gii
sub-1648798153/ses-PNC1/anat/sub-1648798153_ses-PNC1_acq-refaced_space-fsLR_den-32k_hemi-L_desc-hcp_midthickness.surf.gii
sub-1648798153/ses-PNC1/anat/sub-1648798153_ses-PNC1_acq-refaced_space-fsLR_den-32k_hemi-L_desc-hcp_vinflated.surf.gii
Expand Down
1 change: 0 additions & 1 deletion xcp_d/tests/data/test_ukbiobank_outputs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ sub-0000001
sub-0000001.html
sub-0000001/ses-01
sub-0000001/ses-01/anat
sub-0000001/ses-01/anat/sub-0000001_ses-01_space-MNI152NLin6Asym_desc-aparcaseg_dseg.nii.gz
sub-0000001/ses-01/anat/sub-0000001_ses-01_space-MNI152NLin6Asym_desc-preproc_T1w.nii.gz
sub-0000001/ses-01/func
sub-0000001/ses-01/func/sub-0000001_ses-01_task-rest_desc-filtered_motion.json
Expand Down
5 changes: 0 additions & 5 deletions xcp_d/tests/test_workflows_anatomical.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ def test_postprocess_anat_wf(ds001419_data, tmp_path_factory):

anat_to_template_xfm = ds001419_data["anat_to_template_xfm"]
t1w = ds001419_data["t1w"]
anat_dseg = ds001419_data["anat_dseg"]
t2w = os.path.join(tmpdir, "sub-01_desc-preproc_T2w.nii.gz") # pretend t1w is t2w
shutil.copyfile(t1w, t2w)

Expand All @@ -119,7 +118,6 @@ def test_postprocess_anat_wf(ds001419_data, tmp_path_factory):

wf.inputs.inputnode.anat_to_template_xfm = anat_to_template_xfm
wf.inputs.inputnode.t1w = t1w
wf.inputs.inputnode.anat_dseg = anat_dseg
wf.inputs.inputnode.t2w = t2w
wf.base_dir = tmpdir
wf_res = wf.run()
Expand All @@ -132,6 +130,3 @@ def test_postprocess_anat_wf(ds001419_data, tmp_path_factory):

out_t2w = wf_nodes["postprocess_anat_wf.ds_t2w_std"].get_output("out_file")
assert os.path.isfile(out_t2w), os.listdir(out_anat_dir)

out_anat_dseg = wf_nodes["postprocess_anat_wf.ds_anat_dseg_std"].get_output("out_file")
assert os.path.isfile(out_anat_dseg), os.listdir(out_anat_dir)
8 changes: 0 additions & 8 deletions xcp_d/utils/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ def collect_data(
# HCP/DCAN data have anats only in standard space
queries["t1w"]["space"] = "MNI152NLin6Asym"
queries["t2w"]["space"] = "MNI152NLin6Asym"
queries["anat_dseg"]["desc"] = "aparcaseg"
queries["anat_dseg"]["space"] = "MNI152NLin6Asym"
queries["anat_brainmask"]["space"] = "MNI152NLin6Asym"

queries["bold"]["extension"] = ".dtseries.nii" if (file_format == "cifti") else ".nii.gz"
Expand Down Expand Up @@ -299,14 +297,10 @@ def collect_data(
queries["t1w"]["space"] = ["T1w", None]
queries["template_to_anat_xfm"]["to"] = "T1w"
queries["anat_to_template_xfm"]["from"] = "T1w"
# Nibabies may include space-T1w for some derivatives
queries["anat_dseg"]["space"] = ["T1w", None]
else:
LOGGER.info("Performing T2w-only processing.")
queries["template_to_anat_xfm"]["to"] = "T2w"
queries["anat_to_template_xfm"]["from"] = "T2w"
# Nibabies may include space-T2w for some derivatives
queries["anat_dseg"]["space"] = ["T2w", None]
else:
LOGGER.warning("T2w-space T1w found. Processing anatomical images in T2w space.")
else:
Expand All @@ -317,8 +311,6 @@ def collect_data(
LOGGER.warning("T2w found, but no T1w. Enabling T2w-only processing.")
queries["template_to_anat_xfm"]["to"] = "T2w"
queries["anat_to_template_xfm"]["from"] = "T2w"
# Nibabies may include space-T2w for some derivatives
queries["anat_dseg"]["space"] = ["T2w", None]

# Search for the files.
subj_data = {
Expand Down
43 changes: 2 additions & 41 deletions xcp_d/workflows/anatomical/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ def init_postprocess_anat_wf(
t2w : :obj:`str` or None
Path to the preprocessed T2w file.
This file may be in standard space or native T1w space.
anat_dseg : :obj:`str`
Path to the T1w segmentation file.
%(anat_to_template_xfm)s
We need to use MNI152NLin6Asym for the template.
template : :obj:`str`
Expand All @@ -87,7 +85,6 @@ def init_postprocess_anat_wf(
fields=[
"t1w",
"t2w",
"anat_dseg",
"anat_to_template_xfm",
"template",
],
Expand All @@ -110,19 +107,6 @@ def init_postprocess_anat_wf(
)
inputnode.inputs.template = template_file

ds_anat_dseg_std = pe.Node(
DerivativesDataSink(
base_directory=output_dir,
space=target_space,
cohort=cohort,
extension=".nii.gz",
),
name="ds_anat_dseg_std",
run_without_submitting=False,
)

workflow.connect([(inputnode, ds_anat_dseg_std, [("anat_dseg", "source_file")])])

if t1w_available:
ds_t1w_std = pe.Node(
DerivativesDataSink(
Expand Down Expand Up @@ -156,45 +140,22 @@ def init_postprocess_anat_wf(
]) # fmt:skip

if input_type in ("dcan", "hcp", "ukb"):
# Assume that the T1w, T1w segmentation, and T2w files are in standard space,
# Assume that the T1w and T2w files are in standard space,
# but don't have the "space" entity, for the "dcan" and "hcp" derivatives.
# This is a bug, and the converted filenames are inaccurate, so we have this
# workaround in place.
workflow.connect([(inputnode, ds_anat_dseg_std, [("anat_dseg", "in_file")])])

if t1w_available:
workflow.connect([(inputnode, ds_t1w_std, [("t1w", "in_file")])])

if t2w_available:
workflow.connect([(inputnode, ds_t2w_std, [("t2w", "in_file")])])

else:
out = (
["T1w"] if t1w_available else [] + ["T2w"] if t2w_available else [] + ["segmentation"]
)
out = ["T1w"] if t1w_available else [] + ["T2w"] if t2w_available else []
workflow.__desc__ = f"""\
Native-space {list_to_str(out)} images were transformed to {target_space} space at 1 mm3
resolution.
"""
warp_anat_dseg_to_template = pe.Node(
ApplyTransforms(
num_threads=2,
interpolation="GenericLabel",
input_image_type=3,
dimension=3,
),
name="warp_anat_dseg_to_template",
mem_gb=2,
n_procs=omp_nthreads,
)
workflow.connect([
(inputnode, warp_anat_dseg_to_template, [
("anat_dseg", "input_image"),
("anat_to_template_xfm", "transforms"),
("template", "reference_image"),
]),
(warp_anat_dseg_to_template, ds_anat_dseg_std, [("output_image", "in_file")]),
]) # fmt:skip

if t1w_available:
# Warp the native T1w-space T1w, T1w segmentation, and T2w files to standard space.
Expand Down
5 changes: 1 addition & 4 deletions xcp_d/workflows/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ def init_single_subject_wf(subject_id: str):
"t1w",
"t2w", # optional
"anat_brainmask", # used to estimate head radius and for QC metrics
"anat_dseg",
"template_to_anat_xfm", # not used by cifti workflow
"anat_to_template_xfm",
# mesh files
Expand All @@ -181,7 +180,6 @@ def init_single_subject_wf(subject_id: str):
inputnode.inputs.t1w = subj_data["t1w"]
inputnode.inputs.t2w = subj_data["t2w"]
inputnode.inputs.anat_brainmask = subj_data["anat_brainmask"]
inputnode.inputs.anat_dseg = subj_data["anat_dseg"]
inputnode.inputs.template_to_anat_xfm = subj_data["template_to_anat_xfm"]
inputnode.inputs.anat_to_template_xfm = subj_data["anat_to_template_xfm"]

Expand Down Expand Up @@ -291,7 +289,6 @@ def init_single_subject_wf(subject_id: str):
(inputnode, postprocess_anat_wf, [
("t1w", "inputnode.t1w"),
("t2w", "inputnode.t2w"),
("anat_dseg", "inputnode.anat_dseg"),
("anat_to_template_xfm", "inputnode.anat_to_template_xfm"),
]),
]) # fmt:skip
Expand Down Expand Up @@ -467,7 +464,7 @@ def init_single_subject_wf(subject_id: str):
t2w_available=t2w_available,
n_runs=n_runs,
exact_scans=exact_scans,
name=f"{config.workflow.file_format}_postprocess_{run_counter}_wf",
name=f"postprocess_{run_counter}_wf",
)
run_counter += 1

Expand Down

0 comments on commit 940bd1d

Please sign in to comment.