From 51542c7543476838079bf7e1c6c7a7745fa13660 Mon Sep 17 00:00:00 2001 From: jkroell <63234626+jkroell@users.noreply.github.com> Date: Wed, 23 Oct 2024 10:35:50 +0200 Subject: [PATCH 01/15] Add Datagrabber and cofound adaptation for cat processed HCP-Aging --- .../datagrabber/hcp_Aging_confounds_cat.py | 409 ++++++++++++++++++ 1 file changed, 409 insertions(+) create mode 100644 juni_farm/datagrabber/hcp_Aging_confounds_cat.py diff --git a/juni_farm/datagrabber/hcp_Aging_confounds_cat.py b/juni_farm/datagrabber/hcp_Aging_confounds_cat.py new file mode 100644 index 0000000..2efdc05 --- /dev/null +++ b/juni_farm/datagrabber/hcp_Aging_confounds_cat.py @@ -0,0 +1,409 @@ +"""Provide a datagrabber for CAT-processed confounds in the HCP dataset.""" + +# Authors: Leonard Sasse +# License: AGPL + +from itertools import product +from pathlib import Path +from typing import Dict, List, Union +import warnings + +from junifer.api.decorators import register_datagrabber +from junifer.datagrabber import PatternDataGrabber +from junifer.datagrabber import ( + DataladDataGrabber, + HCP1200, + MultipleDataGrabber, + PatternDataladDataGrabber, +) +from junifer.utils import raise_error + + +def get_cat_to_fmriprep_mapping(): + """Map variables in CAT output to fmriprep variables. + + Returns + ------- + dict + keys (CAT variables) and values (corresponding fMRIprep variables). + + """ + # overarching variables + terms_cat = ["WM", "CSF", "GS"] + terms_fmriprep = ["white_matter", "csf", "global_signal"] + + mapping = {} + + for cat, fmriprep in zip(terms_cat, terms_fmriprep): + mapping[cat] = fmriprep + mapping[f"{cat}^2"] = f"{fmriprep}_power2" + + # take care of motion parameters + # TODO: Felix' dataset uses rigid body parameters 1 to 6 but i am not sure + # which number (1-6) correspnds to translations and rotations (and x, y, z) + # respectively; for regular confound removal this should not matter + # because all confounds will be selected and used in the regression + # but will be good to have this implemented correctly anyways + motion_terms_fmriprep = ["rot", "trans"] + motion_directions = ["x", "y", "z"] + for i_iter, (term, direction) in enumerate( + product(motion_terms_fmriprep, motion_directions) + ): + mapping[f"RP.{i_iter+1}"] = f"{term}_{direction}" + mapping[f"RP^2.{i_iter+1}"] = f"{term}_{direction}_power2" + mapping[f"DRP.{i_iter+1}"] = f"{term}_{direction}_derivative1" + mapping[f"DRP^2.{i_iter+1}"] = f"{term}_{direction}_derivative1_power2" + + return mapping + + +@register_datagrabber +class HCPCATConfounds(PatternDataladDataGrabber): + """Concrete implementation for CAT-processed HCP confounds. + + Parameters + ---------- + datadir : str or Path, optional + The directory where the datalad dataset will be cloned. + tasks : {"REST1", "REST2", "CARIT", "FACENAME", "VISMOTOR"} or list of the options, optional + HCP task sessions. If None, all available task sessions are selected + (default None). + phase_encodings : {"LR", "RL"} or list of the options, optional + HCP phase encoding directions. If None, both will be used + (default None). + **kwargs + Keyword arguments passed to superclass. + + """ + + def __init__( + self, + datadir: Union[str, Path] = None, + tasks: Union[str, List[str], None] = None, + phase_encodings: Union[str, List[str], None] = None, + **kwargs, + ) -> None: + """Initialise the class.""" + # All tasks + all_tasks = [ + "REST1", + "REST2", + "CARIT", + "FACENAME", + "VISMOTOR", + ] + # Set default tasks + if tasks is None: + self.tasks: List[str] = all_tasks + # Convert single task into list + else: + if not isinstance(tasks, List): + tasks = [tasks] + + # Check for invalid task(s) + for task in tasks: + if task not in all_tasks: + raise_error( + f"'{task}' is not a valid HCP-A fMRI task input. " + f"Valid task values can be any or all of {all_tasks}." + ) + self.tasks: List[str] = tasks + + # All phase encodings + all_phase_encodings = ["AP", "PA"] + # Set phase encodings + if phase_encodings is None: + phase_encodings = all_phase_encodings + # Convert single phase encoding into list + if isinstance(phase_encodings, str): + phase_encodings = [phase_encodings] + # Check for invalid phase encoding(s) + for pe in phase_encodings: + if pe not in all_phase_encodings: + raise_error( + f"'{pe}' is not a valid HCP-A phase encoding. " + "Valid phase encoding can be any or all of " + f"{all_phase_encodings}." + ) + + # The types of data + types = ["BOLD"] + # The patterns + patterns = { + "BOLD": { + "confounds": { + "pattern": ( + "sub-{subject}/sub-{subject}_task-{task}" + "{phase_encoding}_desc-confounds_timeseries.tsv" + ), + "format": "adhoc", + "mappings": { + "fmriprep": get_cat_to_fmriprep_mapping(), + }, + }, + }, + } + # The replacements + replacements = [ + "subject", + "task", + "phase_encoding", + ] + uri = ( + "ria+file:///data/project/cat_preprocessed/" + "dataladstore#~HCP-A_conf" + ) + super().__init__( + types=types, + datadir=datadir, + uri=uri, + patterns=patterns, + replacements=replacements, + confounds_format="adhoc", + **kwargs, + ) + self.phase_encodings = phase_encodings + + def get_item(self, subject: str, task: str, phase_encoding: str) -> Dict: + """Index one element in the dataset. + + Parameters + ---------- + subject : str + The subject ID. + task : {"REST1", "REST2", "SOCIAL", "WM", "RELATIONAL", "EMOTION", \ + "LANGUAGE", "GAMBLING", "MOTOR"} + The task. + phase_encoding : {"LR", "RL"} + The phase encoding. + + Returns + ------- + out : dict + Dictionary of paths for each type of data required for the + specified element. + """ + # Resting task + if "REST" in task: + new_task = f"rfMRI{task}" + new_phase_encoding = f"{phase_encoding}hp2000clean" + else: + new_task = f"tfMRI{task}" + new_phase_encoding = phase_encoding + + return super().get_item( + subject=subject, task=new_task, phase_encoding=new_phase_encoding + ) + + def get_elements(self) -> List: + """Implement fetching list of elements in the dataset. + + Returns + ------- + list + The list of elements in the dataset. + """ + # there are some .git folders in the dataset that will be picked up + # if we dont check whether "sub" is in name. + subjects = [ + x.name.split("-")[1] + for x in self.datadir.iterdir() + if x.is_dir() and "sub" in x.name + ] + elems = [] + for subject, task, phase_encoding in product( + subjects, self.tasks, self.phase_encodings + ): + elems.append((subject, task, phase_encoding)) + + return elems + +@register_datagrabber +class HCPAging(PatternDataGrabber): + """Concrete implementation for HCP Aging dataset. + + Parameters + ---------- + datadir : str or Path, optional + The directory where the datalad dataset will be cloned. + tasks : {"REST1", "REST2", "CARIT", "FACENAME", "VISMOTOR"} + or list of the options, optional + HCP aging task sessions. If None, all available task sessions + are selected (default None). + phase_encodings : {"AP", "PA"} or list of the options, optional + HCP aging phase encoding directions. If None, both will be used + (default None). + **kwargs + Keyword arguments passed to superclass. + + """ + + def __init__( + self, + datadir: Union[str, Path] = None, + tasks: Union[str, List[str], None] = None, + phase_encodings: Union[str, List[str], None] = None, + **kwargs, + ) -> None: + """Initialise the class.""" + # all tasks + + all_tasks = ["REST1", "REST2", "CARIT", "FACENAME", "VISMOTOR"] + patterns = { + "BOLD": ( + "{subject}_V1_MR/MNINonLinear/" + "Results/{task}_{phase_encoding}/" + "{task}_{phase_encoding}_hp0_clean.nii.gz" + ) + } + types = list(patterns.keys()) + + # Set default tasks + if tasks is None: + self.tasks: List[str] = all_tasks + # Convert single task into list + else: + if not isinstance(tasks, List): + tasks = [tasks] + + # Check for invalid task(s) + for task in tasks: + if task not in all_tasks: + raise_error( + f"'{task}' is not a valid HCP-Aging fMRI task input. " + f"Valid task values can be any or all of {all_tasks}." + ) + self.tasks: List[str] = tasks + + # All phase encodings + all_phase_encodings = ["AP", "PA"] + + # Set phase encodings + if phase_encodings is None: + phase_encodings = all_phase_encodings + + # Convert single phase encoding into list + if isinstance(phase_encodings, str): + phase_encodings = [phase_encodings] + + # Check for invalid phase encoding(s) + for pe in phase_encodings: + if pe not in all_phase_encodings: + raise_error( + f"'{pe}' is not a valid HCP-Aging phase encoding. " + "Valid phase encoding can be any or all of " + f"{all_phase_encodings}." + ) + + self.phase_encodings = phase_encodings + + # The replacements + replacements = ["subject", "task", "phase_encoding"] + super().__init__( + types=types, + datadir=datadir, + patterns=patterns, + replacements=replacements, + confounds_format="adhoc", + ) + + def get_item(self, subject: str, task: str, phase_encoding: str) -> Dict: + """Index one element in the dataset. + + Parameters + ---------- + subject : str + The subject ID. + tasks : {"REST1", "REST2", "CARIT", "FACENAME", "VISMOTOR"} + The task. + phase_encoding : {"PA", "AP"} + The phase encoding. + + Returns + ------- + out : dict + Dictionary of paths for each type of data required for the + specified element. + """ + # Resting task + if "REST" in task: + new_task = f"rfMRI_{task}" + else: + new_task = f"tfMRI_{task}" + + out = super().get_item( + subject=subject, task=new_task, phase_encoding=phase_encoding + ) + return out + + def get_elements(self) -> List: + """Implement fetching list of elements in the dataset. + + Returns + ------- + list + The list of elements in the dataset. + """ + subjects = [ + x.name.split("_")[0] + for x in self.datadir.iterdir() + if "V1_MR" in x.name + ] + + return [ + (sub, task, phase_encoding) + for sub, task, phase_encoding in product( + subjects, self.tasks, self.phase_encodings + ) + ] + + @property + def skip_file_check(self) -> bool: + """Skip file check existence.""" + return True + +@register_datagrabber +class DataladHCPAging(DataladDataGrabber, HCPAging): + """Concrete implementation for datalad-based HCP Aging dataset. + + Parameters + ---------- + datadir : str or Path, optional + The directory where the datalad dataset will be cloned. + tasks : {"REST1", "REST2", "CARIT", "FACENAME", "VISMOTOR"} + or list of the options, optional + HCP aging task sessions. If None, all available task sessions + are selected (default None). + phase_encodings : {"AP", "PA"} or list of the options, optional + HCP aging phase encoding directions. If None, both will be used + (default None). + **kwargs + Keyword arguments passed to superclass. + + """ + + def __init__( + self, + datadir: Union[str, Path, None] = None, + tasks: Union[str, List[str], None] = None, + phase_encodings: Union[str, List[str], None] = None, + ) -> None: + """Initialise the class.""" + uri = ( + "ria+http://hcp-a.ds.inm7.de" + "#431e4eb7-72c3-423d-b402-84ede40c03a2" + ) + + super().__init__( + datadir=datadir, + tasks=tasks, + phase_encodings=phase_encodings, + uri=uri, + ) + + +if __name__ == "__main__": + with DataladHCPAging() as dg: + elems = dg.get_elements() + test_data = dg[elems[0]] + print(test_data) \ No newline at end of file From 349e3ad062f64d63202236ac2f957ffb319a0211 Mon Sep 17 00:00:00 2001 From: jkroell <63234626+jkroell@users.noreply.github.com> Date: Thu, 24 Oct 2024 10:13:00 +0200 Subject: [PATCH 02/15] Update hcp_aging.py --- juni_farm/datagrabber/hcp_aging.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/juni_farm/datagrabber/hcp_aging.py b/juni_farm/datagrabber/hcp_aging.py index afc9cc1..a5d8e8e 100644 --- a/juni_farm/datagrabber/hcp_aging.py +++ b/juni_farm/datagrabber/hcp_aging.py @@ -1,6 +1,6 @@ """Provide a datagrabber for the HCP Aging dataset.""" -# Authors: Leonard Sasse +# Authors: Leonard Sasse , Jean-Philippe Kroell # License: AGPL from itertools import product From ca28ef662e5c9daaba781128b853260fbd960e79 Mon Sep 17 00:00:00 2001 From: jkroell <63234626+jkroell@users.noreply.github.com> Date: Thu, 24 Oct 2024 10:24:04 +0200 Subject: [PATCH 03/15] Update hcp_aging.py --- juni_farm/datagrabber/hcp_aging.py | 250 ++++++++++++++++++++++++++++- 1 file changed, 249 insertions(+), 1 deletion(-) diff --git a/juni_farm/datagrabber/hcp_aging.py b/juni_farm/datagrabber/hcp_aging.py index a5d8e8e..34a031a 100644 --- a/juni_farm/datagrabber/hcp_aging.py +++ b/juni_farm/datagrabber/hcp_aging.py @@ -12,6 +12,204 @@ from junifer.datagrabber import PatternDataGrabber from junifer.utils import raise_error +def get_cat_to_fmriprep_mapping(): + """Map variables in CAT output to fmriprep variables. + + Returns + ------- + dict + keys (CAT variables) and values (corresponding fMRIprep variables). + + """ + # overarching variables + terms_cat = ["WM", "CSF", "GS"] + terms_fmriprep = ["white_matter", "csf", "global_signal"] + + mapping = {} + + for cat, fmriprep in zip(terms_cat, terms_fmriprep): + mapping[cat] = fmriprep + mapping[f"{cat}^2"] = f"{fmriprep}_power2" + + # take care of motion parameters + # TODO: Felix' dataset uses rigid body parameters 1 to 6 but i am not sure + # which number (1-6) correspnds to translations and rotations (and x, y, z) + # respectively; for regular confound removal this should not matter + # because all confounds will be selected and used in the regression + # but will be good to have this implemented correctly anyways + motion_terms_fmriprep = ["rot", "trans"] + motion_directions = ["x", "y", "z"] + for i_iter, (term, direction) in enumerate( + product(motion_terms_fmriprep, motion_directions) + ): + mapping[f"RP.{i_iter+1}"] = f"{term}_{direction}" + mapping[f"RP^2.{i_iter+1}"] = f"{term}_{direction}_power2" + mapping[f"DRP.{i_iter+1}"] = f"{term}_{direction}_derivative1" + mapping[f"DRP^2.{i_iter+1}"] = f"{term}_{direction}_derivative1_power2" + + return mapping + +@register_datagrabber +class HCPAgingCATConfounds(PatternDataladDataGrabber): + """Concrete implementation for CAT-processed HCP confounds. + + Parameters + ---------- + datadir : str or Path, optional + The directory where the datalad dataset will be cloned. + tasks : {"REST1", "REST2", "CARIT", "FACENAME", "VISMOTOR"} or list of the options, optional + HCP task sessions. If None, all available task sessions are selected + (default None). + phase_encodings : {"LR", "RL"} or list of the options, optional + HCP phase encoding directions. If None, both will be used + (default None). + **kwargs + Keyword arguments passed to superclass. + + """ + + def __init__( + self, + datadir: Union[str, Path] = None, + tasks: Union[str, List[str], None] = None, + phase_encodings: Union[str, List[str], None] = None, + **kwargs, + ) -> None: + """Initialise the class.""" + # All tasks + all_tasks = [ + "REST1", + "REST2", + "CARIT", + "FACENAME", + "VISMOTOR", + ] + # Set default tasks + if tasks is None: + self.tasks: List[str] = all_tasks + # Convert single task into list + else: + if not isinstance(tasks, List): + tasks = [tasks] + + # Check for invalid task(s) + for task in tasks: + if task not in all_tasks: + raise_error( + f"'{task}' is not a valid HCP-A fMRI task input. " + f"Valid task values can be any or all of {all_tasks}." + ) + self.tasks: List[str] = tasks + + # All phase encodings + all_phase_encodings = ["AP", "PA"] + # Set phase encodings + if phase_encodings is None: + phase_encodings = all_phase_encodings + # Convert single phase encoding into list + if isinstance(phase_encodings, str): + phase_encodings = [phase_encodings] + # Check for invalid phase encoding(s) + for pe in phase_encodings: + if pe not in all_phase_encodings: + raise_error( + f"'{pe}' is not a valid HCP-A phase encoding. " + "Valid phase encoding can be any or all of " + f"{all_phase_encodings}." + ) + + # The types of data + types = ["BOLD"] + # The patterns + patterns = { + "BOLD": { + "confounds": { + "pattern": ( + "sub-{subject}/sub-{subject}_task-{task}" + "{phase_encoding}_desc-confounds_timeseries.tsv" + ), + "format": "adhoc", + "mappings": { + "fmriprep": get_cat_to_fmriprep_mapping(), + }, + }, + }, + } + # The replacements + replacements = [ + "subject", + "task", + "phase_encoding", + ] + uri = ( + "ria+file:///data/project/cat_preprocessed/" + "dataladstore#~HCP-A_conf" + ) + super().__init__( + types=types, + datadir=datadir, + uri=uri, + patterns=patterns, + replacements=replacements, + confounds_format="adhoc", + **kwargs, + ) + self.phase_encodings = phase_encodings + + def get_item(self, subject: str, task: str, phase_encoding: str) -> Dict: + """Index one element in the dataset. + + Parameters + ---------- + subject : str + The subject ID. + task : {"REST1", "REST2", "SOCIAL", "WM", "RELATIONAL", "EMOTION", \ + "LANGUAGE", "GAMBLING", "MOTOR"} + The task. + phase_encoding : {"LR", "RL"} + The phase encoding. + + Returns + ------- + out : dict + Dictionary of paths for each type of data required for the + specified element. + """ + # Resting task + if "REST" in task: + new_task = f"rfMRI{task}" + new_phase_encoding = f"{phase_encoding}hp2000clean" + else: + new_task = f"tfMRI{task}" + new_phase_encoding = phase_encoding + + return super().get_item( + subject=subject, task=new_task, phase_encoding=new_phase_encoding + ) + + def get_elements(self) -> List: + """Implement fetching list of elements in the dataset. + + Returns + ------- + list + The list of elements in the dataset. + """ + # there are some .git folders in the dataset that will be picked up + # if we dont check whether "sub" is in name. + subjects = [ + x.name.split("-")[1] + for x in self.datadir.iterdir() + if x.is_dir() and "sub" in x.name + ] + elems = [] + for subject, task, phase_encoding in product( + subjects, self.tasks, self.phase_encodings + ): + elems.append((subject, task, phase_encoding)) + + return elems + @register_datagrabber class HCPAging(PatternDataGrabber): @@ -197,9 +395,59 @@ def __init__( uri=uri, ) +@register_datagrabber +class MultipleHCP(MultipleDataGrabber): + """Concrete implementation for HCP Aging data confounds. + + Parameters + ---------- + datadir : str or Path, optional + The directory where the datalad dataset will be cloned. + tasks : {"REST1", "REST2", "CARIT", "FACENAME", "VISMOTOR"} or list of the options, optional + HCP task sessions. If None, all available task sessions are selected + (default None). + phase_encodings : {"AP", "PA"} or list of the options, optional + HCP phase encoding directions. If None, both will be used + (default None). + ica_fix : bool, optional + Whether to retrieve data that was processed with ICA+FIX. + Only "REST1" and "REST2" tasks are available with ICA+FIX (default + False). + **kwargs + Keyword arguments passed to superclass. + + """ + + def __init__( + self, + tasks: Union[str, List[str], None] = None, + phase_encodings: Union[str, List[str], None] = None, + ica_fix: bool = False, + **kwargs, + ): + """Initialise class.""" + with warnings.catch_warnings(): + warnings.filterwarnings( + "ignore", module="junifer.datagrabber.pattern_validation_mixin" + ) + + dg1 = DataladHCPAging( + tasks=tasks, + phase_encodings=phase_encodings, + ica_fix=ica_fix, + **kwargs, + ) + kwargs["partial_pattern_ok"] = True + dg2 = HCPAgingCATConfounds(**kwargs) + super().__init__( + datagrabbers=[dg1, dg2], + **kwargs, + ) + + if __name__ == "__main__": - with DataladHCPAging() as dg: + with MultipleHCP() as dg: elems = dg.get_elements() test_data = dg[elems[0]] print(test_data) From 5683d39f01ef7f0f52a5a46ba90eeb3e0c83e271 Mon Sep 17 00:00:00 2001 From: jkroell <63234626+jkroell@users.noreply.github.com> Date: Thu, 24 Oct 2024 10:26:31 +0200 Subject: [PATCH 04/15] Update hcp_aging.py --- juni_farm/datagrabber/hcp_aging.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/juni_farm/datagrabber/hcp_aging.py b/juni_farm/datagrabber/hcp_aging.py index 34a031a..d71fc98 100644 --- a/juni_farm/datagrabber/hcp_aging.py +++ b/juni_farm/datagrabber/hcp_aging.py @@ -6,10 +6,13 @@ from itertools import product from pathlib import Path from typing import Dict, List, Union - -from junifer.datagrabber.datalad_base import DataladDataGrabber +from junifer.datagrabber import ( + DataladDataGrabber, + HCP1200, + MultipleDataGrabber, + PatternDataladDataGrabber, +) from junifer.api.decorators import register_datagrabber -from junifer.datagrabber import PatternDataGrabber from junifer.utils import raise_error def get_cat_to_fmriprep_mapping(): From f81f84f38a6c7b759d14659daa0e8650c7b50bbc Mon Sep 17 00:00:00 2001 From: jkroell <63234626+jkroell@users.noreply.github.com> Date: Thu, 24 Oct 2024 10:27:36 +0200 Subject: [PATCH 05/15] Update hcp_aging.py --- juni_farm/datagrabber/hcp_aging.py | 1 + 1 file changed, 1 insertion(+) diff --git a/juni_farm/datagrabber/hcp_aging.py b/juni_farm/datagrabber/hcp_aging.py index d71fc98..1d477e2 100644 --- a/juni_farm/datagrabber/hcp_aging.py +++ b/juni_farm/datagrabber/hcp_aging.py @@ -10,6 +10,7 @@ DataladDataGrabber, HCP1200, MultipleDataGrabber, + PatternDataGrabber, PatternDataladDataGrabber, ) from junifer.api.decorators import register_datagrabber From af934c37c9f14c28c9861dd32c0e351581d56006 Mon Sep 17 00:00:00 2001 From: jkroell <63234626+jkroell@users.noreply.github.com> Date: Thu, 24 Oct 2024 10:28:34 +0200 Subject: [PATCH 06/15] Update hcp_aging.py --- juni_farm/datagrabber/hcp_aging.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/juni_farm/datagrabber/hcp_aging.py b/juni_farm/datagrabber/hcp_aging.py index 1d477e2..f81af6b 100644 --- a/juni_farm/datagrabber/hcp_aging.py +++ b/juni_farm/datagrabber/hcp_aging.py @@ -6,6 +6,8 @@ from itertools import product from pathlib import Path from typing import Dict, List, Union +import warnings + from junifer.datagrabber import ( DataladDataGrabber, HCP1200, From ea3087c7285981b2ee915be905af36e69503e2e4 Mon Sep 17 00:00:00 2001 From: jkroell <63234626+jkroell@users.noreply.github.com> Date: Thu, 24 Oct 2024 10:29:46 +0200 Subject: [PATCH 07/15] Update hcp_aging.py --- juni_farm/datagrabber/hcp_aging.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/juni_farm/datagrabber/hcp_aging.py b/juni_farm/datagrabber/hcp_aging.py index f81af6b..5c3318f 100644 --- a/juni_farm/datagrabber/hcp_aging.py +++ b/juni_farm/datagrabber/hcp_aging.py @@ -415,10 +415,6 @@ class MultipleHCP(MultipleDataGrabber): phase_encodings : {"AP", "PA"} or list of the options, optional HCP phase encoding directions. If None, both will be used (default None). - ica_fix : bool, optional - Whether to retrieve data that was processed with ICA+FIX. - Only "REST1" and "REST2" tasks are available with ICA+FIX (default - False). **kwargs Keyword arguments passed to superclass. @@ -428,7 +424,6 @@ def __init__( self, tasks: Union[str, List[str], None] = None, phase_encodings: Union[str, List[str], None] = None, - ica_fix: bool = False, **kwargs, ): """Initialise class.""" @@ -440,7 +435,6 @@ def __init__( dg1 = DataladHCPAging( tasks=tasks, phase_encodings=phase_encodings, - ica_fix=ica_fix, **kwargs, ) kwargs["partial_pattern_ok"] = True From 33b962a6f38b558535805a9d81e99d325a9d0e76 Mon Sep 17 00:00:00 2001 From: jkroell <63234626+jkroell@users.noreply.github.com> Date: Thu, 24 Oct 2024 10:41:40 +0200 Subject: [PATCH 08/15] Update hcp_aging.py --- juni_farm/datagrabber/hcp_aging.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/juni_farm/datagrabber/hcp_aging.py b/juni_farm/datagrabber/hcp_aging.py index 5c3318f..7052f26 100644 --- a/juni_farm/datagrabber/hcp_aging.py +++ b/juni_farm/datagrabber/hcp_aging.py @@ -249,11 +249,12 @@ def __init__( all_tasks = ["REST1", "REST2", "CARIT", "FACENAME", "VISMOTOR"] patterns = { - "BOLD": ( + "BOLD": { + "pattern": ( "{subject}_V1_MR/MNINonLinear/" "Results/{task}_{phase_encoding}/" "{task}_{phase_encoding}_hp0_clean.nii.gz" - ) + )} } types = list(patterns.keys()) From 13964eb04eb0182f3d1e89e305932671eff93f00 Mon Sep 17 00:00:00 2001 From: jkroell <63234626+jkroell@users.noreply.github.com> Date: Thu, 24 Oct 2024 10:44:42 +0200 Subject: [PATCH 09/15] Update hcp_aging.py --- juni_farm/datagrabber/hcp_aging.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/juni_farm/datagrabber/hcp_aging.py b/juni_farm/datagrabber/hcp_aging.py index 7052f26..4f8db73 100644 --- a/juni_farm/datagrabber/hcp_aging.py +++ b/juni_farm/datagrabber/hcp_aging.py @@ -1,4 +1,4 @@ -"""Provide a datagrabber for the HCP Aging dataset.""" +"""Provide a datagrabber for the HCP Aging dataset and its confounds.""" # Authors: Leonard Sasse , Jean-Philippe Kroell # License: AGPL @@ -254,7 +254,8 @@ def __init__( "{subject}_V1_MR/MNINonLinear/" "Results/{task}_{phase_encoding}/" "{task}_{phase_encoding}_hp0_clean.nii.gz" - )} + ), + "space": "MNI152NLin6Asym"} } types = list(patterns.keys()) From a37d8a887540726141a6fcf075916a60065b80c8 Mon Sep 17 00:00:00 2001 From: jkroell <63234626+jkroell@users.noreply.github.com> Date: Thu, 24 Oct 2024 11:36:14 +0200 Subject: [PATCH 10/15] Update hcp_aging.py --- juni_farm/datagrabber/hcp_aging.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/juni_farm/datagrabber/hcp_aging.py b/juni_farm/datagrabber/hcp_aging.py index 4f8db73..7da6398 100644 --- a/juni_farm/datagrabber/hcp_aging.py +++ b/juni_farm/datagrabber/hcp_aging.py @@ -184,7 +184,7 @@ def get_item(self, subject: str, task: str, phase_encoding: str) -> Dict: # Resting task if "REST" in task: new_task = f"rfMRI{task}" - new_phase_encoding = f"{phase_encoding}hp2000clean" + new_phase_encoding = f"{phase_encoding}_hp0_clean" else: new_task = f"tfMRI{task}" new_phase_encoding = phase_encoding From 47bb6414bcb6ded1d3f3c7899c78a175eef86fef Mon Sep 17 00:00:00 2001 From: jkroell <63234626+jkroell@users.noreply.github.com> Date: Thu, 24 Oct 2024 13:14:24 +0200 Subject: [PATCH 11/15] Update hcp_aging.py --- juni_farm/datagrabber/hcp_aging.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/juni_farm/datagrabber/hcp_aging.py b/juni_farm/datagrabber/hcp_aging.py index 7da6398..6f87ecb 100644 --- a/juni_farm/datagrabber/hcp_aging.py +++ b/juni_farm/datagrabber/hcp_aging.py @@ -212,6 +212,11 @@ def get_elements(self) -> List: for subject, task, phase_encoding in product( subjects, self.tasks, self.phase_encodings ): + # for task sessions only PA phase encoding exists, so filter out + # all task data that is AP here + if "REST" not in task and phase_encoding == "AP": + continue + elems.append((subject, task, phase_encoding)) return elems From 866f32653ae2947b92dd7e40040ec69e62dbde40 Mon Sep 17 00:00:00 2001 From: jkroell <63234626+jkroell@users.noreply.github.com> Date: Thu, 24 Oct 2024 13:51:13 +0200 Subject: [PATCH 12/15] Update hcp_aging.py --- juni_farm/datagrabber/hcp_aging.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/juni_farm/datagrabber/hcp_aging.py b/juni_farm/datagrabber/hcp_aging.py index 6f87ecb..adfa897 100644 --- a/juni_farm/datagrabber/hcp_aging.py +++ b/juni_farm/datagrabber/hcp_aging.py @@ -355,13 +355,19 @@ def get_elements(self) -> List: for x in self.datadir.iterdir() if "V1_MR" in x.name ] + elems = [] + for subject, task, phase_encoding in product( + subjects, self.tasks, self.phase_encodings + ): + # for task sessions only PA phase encoding exists, so filter out + # all task data that is AP here + if "REST" not in task and phase_encoding == "AP": + continue + + elems.append((subject, task, phase_encoding)) + + return elems - return [ - (sub, task, phase_encoding) - for sub, task, phase_encoding in product( - subjects, self.tasks, self.phase_encodings - ) - ] @property def skip_file_check(self) -> bool: From ea406c4d5b3e8c6ba82d52095bc3b9ac06a021ed Mon Sep 17 00:00:00 2001 From: jkroell <63234626+jkroell@users.noreply.github.com> Date: Fri, 25 Oct 2024 08:59:57 +0200 Subject: [PATCH 13/15] Update hcp_aging.py --- juni_farm/datagrabber/hcp_aging.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/juni_farm/datagrabber/hcp_aging.py b/juni_farm/datagrabber/hcp_aging.py index adfa897..bfbf76f 100644 --- a/juni_farm/datagrabber/hcp_aging.py +++ b/juni_farm/datagrabber/hcp_aging.py @@ -212,12 +212,12 @@ def get_elements(self) -> List: for subject, task, phase_encoding in product( subjects, self.tasks, self.phase_encodings ): - # for task sessions only PA phase encoding exists, so filter out - # all task data that is AP here - if "REST" not in task and phase_encoding == "AP": - continue + # for task sessions only PA phase encoding exists, so filter out + # all task data that is AP here + if "REST" not in task and phase_encoding == "AP": + continue - elems.append((subject, task, phase_encoding)) + elems.append((subject, task, phase_encoding)) return elems From 132e7a0b3b184da7a1541699a29ecaa71f03e69b Mon Sep 17 00:00:00 2001 From: jkroell <63234626+jkroell@users.noreply.github.com> Date: Fri, 25 Oct 2024 09:07:50 +0200 Subject: [PATCH 14/15] Update hcp_aging.py --- juni_farm/datagrabber/hcp_aging.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/juni_farm/datagrabber/hcp_aging.py b/juni_farm/datagrabber/hcp_aging.py index bfbf76f..c3c83a9 100644 --- a/juni_farm/datagrabber/hcp_aging.py +++ b/juni_farm/datagrabber/hcp_aging.py @@ -415,7 +415,7 @@ def __init__( ) @register_datagrabber -class MultipleHCP(MultipleDataGrabber): +class MultipleHCPAging(MultipleDataGrabber): """Concrete implementation for HCP Aging data confounds. Parameters @@ -460,7 +460,7 @@ def __init__( if __name__ == "__main__": - with MultipleHCP() as dg: + with MultipleHCPAging() as dg: elems = dg.get_elements() test_data = dg[elems[0]] print(test_data) From 35f332a363b4e07f435d56d578198f967682c150 Mon Sep 17 00:00:00 2001 From: jkroell <63234626+jkroell@users.noreply.github.com> Date: Fri, 25 Oct 2024 09:09:15 +0200 Subject: [PATCH 15/15] Update hcp_aging.py --- juni_farm/datagrabber/hcp_aging.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/juni_farm/datagrabber/hcp_aging.py b/juni_farm/datagrabber/hcp_aging.py index c3c83a9..b229437 100644 --- a/juni_farm/datagrabber/hcp_aging.py +++ b/juni_farm/datagrabber/hcp_aging.py @@ -212,12 +212,12 @@ def get_elements(self) -> List: for subject, task, phase_encoding in product( subjects, self.tasks, self.phase_encodings ): - # for task sessions only PA phase encoding exists, so filter out - # all task data that is AP here - if "REST" not in task and phase_encoding == "AP": - continue - - elems.append((subject, task, phase_encoding)) + # for task sessions only PA phase encoding exists, so filter out + # all task data that is AP here + if "REST" not in task and phase_encoding == "AP": + continue + + elems.append((subject, task, phase_encoding)) return elems