Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[ENH]: Add support for native space #252

Merged
merged 13 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changes/newsfragments/252.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add ``native_t1w`` parameter to :class:`.DataladAOMICID1000`, :class:`.DataladAOMICPIOP1`, :class:`.DataladAOMICPIOP2`, enabling fetching of T1w data in subject-native space by `Synchon Mandal`_
1 change: 1 addition & 0 deletions docs/changes/newsfragments/252.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for subject-native space by `Synchon Mandal`_ and `Fede Raimondo`_
29 changes: 28 additions & 1 deletion junifer/datagrabber/aomic/id1000.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ class DataladAOMICID1000(PatternDataladDataGrabber):
"probseg_WM", "DWI"} or a list of the options, optional
AOMIC data types. If None, all available data types are selected.
(default None).
native_t1w : bool, optional
Whether to use T1w in native space (default False).

"""

def __init__(
self,
datadir: Union[str, Path, None] = None,
types: Union[str, List[str], None] = None,
native_t1w: bool = False,
) -> None:
# The patterns
patterns = {
Expand Down Expand Up @@ -84,6 +87,27 @@ def __init__(
"sub-{subject}_desc-preproc_dwi.nii.gz"
),
}
# Use native T1w assets
self.native_t1w = False
if native_t1w:
self.native_t1w = True
patterns.update(
{
"T1w": (
"derivatives/fmriprep/sub-{subject}/anat/"
"sub-{subject}_desc-preproc_T1w.nii.gz"
),
"T1w_mask": (
"derivatives/fmriprep/sub-{subject}/anat/"
"sub-{subject}_desc-brain_mask.nii.gz"
),
"Warp": (
"derivatives/fmriprep/sub-{subject}/anat/"
"sub-{subject}_from-MNI152NLin2009cAsym_to-T1w_"
"mode-image_xfm.h5"
),
}
)
# Set default types
if types is None:
types = list(patterns.keys())
Expand Down Expand Up @@ -126,5 +150,8 @@ def get_item(self, subject: str) -> Dict:
if out.get("T1w"):
out["T1w"]["mask_item"] = "T1w_mask"
# Add space information
out["T1w"].update({"space": "native"})
if self.native_t1w:
out["T1w"].update({"space": "native"})
else:
out["T1w"].update({"space": "MNI152NLin2009cAsym"})
return out
29 changes: 28 additions & 1 deletion junifer/datagrabber/aomic/piop1.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class DataladAOMICPIOP1(PatternDataladDataGrabber):
"gstroop", "workingmemory"} or list of the options, optional
AOMIC PIOP1 task sessions. If None, all available task sessions are
selected (default None).
native_t1w : bool, optional
Whether to use T1w in native space (default False).

"""

Expand All @@ -42,6 +44,7 @@ def __init__(
datadir: Union[str, Path, None] = None,
types: Union[str, List[str], None] = None,
tasks: Union[str, List[str], None] = None,
native_t1w: bool = False,
) -> None:
# Declare all tasks
all_tasks = [
Expand Down Expand Up @@ -114,6 +117,27 @@ def __init__(
"sub-{subject}_desc-preproc_dwi.nii.gz"
),
}
# Use native T1w assets
self.native_t1w = False
if native_t1w:
self.native_t1w = True
patterns.update(
{
"T1w": (
"derivatives/fmriprep/sub-{subject}/anat/"
"sub-{subject}_desc-preproc_T1w.nii.gz"
),
"T1w_mask": (
"derivatives/fmriprep/sub-{subject}/anat/"
"sub-{subject}_desc-brain_mask.nii.gz"
),
"Warp": (
"derivatives/fmriprep/sub-{subject}/anat/"
"sub-{subject}_from-MNI152NLin2009cAsym_to-T1w_"
"mode-image_xfm.h5"
),
}
)
# Set default types
if types is None:
types = list(patterns.keys())
Expand Down Expand Up @@ -171,7 +195,10 @@ def get_item(self, subject: str, task: str) -> Dict:
if out.get("T1w"):
out["T1w"]["mask_item"] = "T1w_mask"
# Add space information
out["T1w"].update({"space": "native"})
if self.native_t1w:
out["T1w"].update({"space": "native"})
else:
out["T1w"].update({"space": "MNI152NLin2009cAsym"})
return out

def get_elements(self) -> List:
Expand Down
29 changes: 28 additions & 1 deletion junifer/datagrabber/aomic/piop2.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class DataladAOMICPIOP2(PatternDataladDataGrabber):
or list of the options, optional
AOMIC PIOP2 task sessions. If None, all available task sessions are
selected (default None).
native_t1w : bool, optional
Whether to use T1w in native space (default False).

"""

Expand All @@ -42,6 +44,7 @@ def __init__(
datadir: Union[str, Path, None] = None,
types: Union[str, List[str], None] = None,
tasks: Union[str, List[str], None] = None,
native_t1w: bool = False,
) -> None:
# Declare all tasks
all_tasks = [
Expand Down Expand Up @@ -111,6 +114,27 @@ def __init__(
"sub-{subject}_desc-preproc_dwi.nii.gz"
),
}
# Use native T1w assets
self.native_t1w = False
if native_t1w:
self.native_t1w = True
patterns.update(
{
"T1w": (
"derivatives/fmriprep/sub-{subject}/anat/"
"sub-{subject}_desc-preproc_T1w.nii.gz"
),
"T1w_mask": (
"derivatives/fmriprep/sub-{subject}/anat/"
"sub-{subject}_desc-brain_mask.nii.gz"
),
"Warp": (
"derivatives/fmriprep/sub-{subject}/anat/"
"sub-{subject}_from-MNI152NLin2009cAsym_to-T1w_"
"mode-image_xfm.h5"
),
}
)
# Set default types
if types is None:
types = list(patterns.keys())
Expand Down Expand Up @@ -171,5 +195,8 @@ def get_item(self, subject: str, task: str) -> Dict:
if out.get("T1w"):
out["T1w"]["mask_item"] = "T1w_mask"
# Add space information
out["T1w"].update({"space": "native"})
if self.native_t1w:
out["T1w"].update({"space": "native"})
else:
out["T1w"].update({"space": "MNI152NLin2009cAsym"})
return out
12 changes: 10 additions & 2 deletions junifer/datagrabber/hcp1200/hcp1200.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,17 @@ def __init__(
)
suffix = "_hp2000_clean" if ica_fix else ""
# The types of data
types = ["BOLD"]
types = ["BOLD", "T1w", "Warp"]
# The patterns
patterns = {
"BOLD": (
"{subject}/MNINonLinear/Results/"
"{task}_{phase_encoding}/"
"{task}_{phase_encoding}"
f"{suffix}.nii.gz"
)
),
"T1w": "{subject}/T1w/T1w_acpc_dc_restore.nii.gz",
"Warp": "{subject}/MNINonLinear/xfms/standard2acpc_dc.nii.gz",
}
# The replacements
replacements = ["subject", "task", "phase_encoding"]
Expand Down Expand Up @@ -147,6 +149,12 @@ def get_item(self, subject: str, task: str, phase_encoding: str) -> Dict:
out = super().get_item(
subject=subject, task=new_task, phase_encoding=phase_encoding
)
# Add space for BOLD data type
if "BOLD" in out:
out["BOLD"].update({"space": "MNI152NLin6Asym"})
# Add space for T1w data type
if "T1w" in out:
out["T1w"].update({"space": "native"})
return out

def get_elements(self) -> List:
Expand Down
4 changes: 4 additions & 0 deletions junifer/datareader/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ def _fit_transform(
params = {}
# For each type of data, try to read it
for type_ in input.keys():
# Skip Warp data type
if type_ == "Warp":
continue

# Check for malformed datagrabber specification
if "path" not in input[type_]:
warn_with_log(
Expand Down