Skip to content

Commit

Permalink
Make collect_data work for T1w+T2w nibabies derivatives (#1234)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsalo authored Aug 16, 2024
1 parent 1b8077a commit 7a8f9ba
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
9 changes: 7 additions & 2 deletions xcp_d/data/io_spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ queries:
datatype: anat
desc: null
extension: .nii.gz
space: null
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
Expand All @@ -33,7 +36,9 @@ queries:
datatype: anat
desc: preproc
extension: .nii.gz
space: null
space:
- null
- T2w
suffix: T1w
# native T2w-space or T1w-space, preprocessed T2w file
t2w:
Expand Down
27 changes: 27 additions & 0 deletions xcp_d/utils/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,33 @@ def collect_data(
t2w_files = layout.get(return_type="file", subject=participant_label, **queries["t2w"])
if not t1w_files and not t2w_files:
raise FileNotFoundError("No T1w or T2w files found.")
elif t1w_files and t2w_files:
LOGGER.warning("Both T1w and T1w found. Checking for T1w-space T2w.")
temp_query = queries["t2w"].copy()
temp_query["space"] = "T1w"
temp_t2w_files = layout.get(return_type="file", subject=participant_label, **temp_query)
if not temp_t2w_files:
LOGGER.warning("No T1w-space T2w found. Checking for T2w-space T1w.")
temp_query = queries["t1w"].copy()
temp_query["space"] = "T2w"
temp_t1w_files = layout.get(
return_type="file",
subject=participant_label,
**temp_query,
)
queries["t1w"]["space"] = "T2w"
if not temp_t1w_files:
LOGGER.warning("No T2w-space T1w found. 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]
else:
LOGGER.warning("T2w-space T1w found. Processing anatomical images in T2w space.")
else:
LOGGER.warning("T1w-space T2w found. Processing anatomical images in T1w space.")
queries["t2w"]["space"] = "T1w"
queries["t1w"]["space"] = ["T1w", None]
elif t2w_files and not t1w_files:
LOGGER.warning("T2w found, but no T1w. Enabling T2w-only processing.")
queries["template_to_anat_xfm"]["to"] = "T2w"
Expand Down

0 comments on commit 7a8f9ba

Please sign in to comment.