diff --git a/xcp_d/data/io_spec.yaml b/xcp_d/data/io_spec.yaml index 8fbedd9de..63feb0917 100644 --- a/xcp_d/data/io_spec.yaml +++ b/xcp_d/data/io_spec.yaml @@ -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 @@ -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: diff --git a/xcp_d/utils/bids.py b/xcp_d/utils/bids.py index f89136af8..2a737b491 100644 --- a/xcp_d/utils/bids.py +++ b/xcp_d/utils/bids.py @@ -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"