From 2ab869f7ca224f2d34d5cf5f6719ecb01c51fb15 Mon Sep 17 00:00:00 2001 From: Jon Clucas Date: Fri, 27 Jan 2023 13:45:10 -0500 Subject: [PATCH] :necktie: Strip space and res from atlas keys --- CPAC/resources/templates/BIDS_identifiers.tsv | 8 +++--- CPAC/utils/bids_utils.py | 26 +++++++++++++++++++ CPAC/utils/datasource.py | 4 +++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/CPAC/resources/templates/BIDS_identifiers.tsv b/CPAC/resources/templates/BIDS_identifiers.tsv index 09c68f790f..168dd9d87b 100644 --- a/CPAC/resources/templates/BIDS_identifiers.tsv +++ b/CPAC/resources/templates/BIDS_identifiers.tsv @@ -21,10 +21,10 @@ /ndmg_atlases/label/Human/HarvardOxfordcort-maxprob-thr25_space-MNI152NLin6_res-2x2x2.nii.gz HOCPA th25 /ndmg_atlases/label/Human/HarvardOxfordsub-maxprob-thr25_space-MNI152NLin6_res-2x2x2.nii.gz HOSPA th25 /ndmg_atlases/label/Human/Juelich_space-MNI152NLin6_res-2x2x2.nii.gz Juelich -/cpac_templates/Schaefer2018_space-FSLMNI152_res-2mm_desc-200Parcels17NetworksOrder.nii.gz Schaefer2018 p200n17 -/cpac_templates/Schaefer2018_space-FSLMNI152_res-2mm_desc-300Parcels17NetworksOrder.nii.gz Schaefer2018 p300n17 -/cpac_templates/Schaefer2018_space-FSLMNI152_res-2mm_desc-400Parcels17NetworksOrder.nii.gz Schaefer2018 p400n17 -/cpac_templates/Schaefer2018_space-FSLMNI152_res-2mm_desc-1000Parcels17NetworksOrder.nii.gz Schaefer2018 p1000n17 +/ndmg_atlases/label/Human/Schaefer[^_-]*200.*.nii(\.gz){0,1} Schaefer2018 p200n17 +/ndmg_atlases/label/Human/Schaefer[^_-]*300.*.nii(\.gz){0,1} Schaefer2018 p300n17 +/ndmg_atlases/label/Human/Schaefer[^_-]*400.*.nii(\.gz){0,1} Schaefer2018 p400n17 +/ndmg_atlases/label/Human/Schaefer[^_-]*1000.*.nii(\.gz){0,1} Schaefer2018 p1000n17 /ndmg_atlases/label/Human/Yeo-7_space-MNI152NLin6_res-2x2x2.nii.gz Yeo 7 /ndmg_atlases/label/Human/Yeo-7-liberal_space-MNI152NLin6_res-2x2x2.nii.gz Yeo 7liberal /ndmg_atlases/label/Human/Yeo-17_space-MNI152NLin6_res-2x2x2.nii.gz Yeo 17 diff --git a/CPAC/utils/bids_utils.py b/CPAC/utils/bids_utils.py index 9ef5bf30b3..9af01bb879 100755 --- a/CPAC/utils/bids_utils.py +++ b/CPAC/utils/bids_utils.py @@ -198,6 +198,32 @@ def bids_match_entities(file_list, entities, suffix): return matches +def bids_remove_entity(name, key): + """Remove an entity from a BIDS string by key + + Parameters + ---------- + name : str + BIDS string to remove entity from + key : str + BIDS key of entity to remove + + Returns + ------- + str + BIDS name with entity removed + + Examples + -------- + >>> bids_remove_entity('atlas-Yeo_space-MNI152NLin6_res-2x2x2', 'space') + 'atlas-Yeo_res-2x2x2' + >>> bids_remove_entity('atlas-Yeo_space-MNI152NLin6_res-2x2x2', 'res') + 'atlas-Yeo_space-MNI152NLin6' + """ + return '_'.join(entity for entity in bids_entities_from_filename(name) + if not entity.startswith(f'{key.rstrip("-")}-')) + + def bids_retrieve_params(bids_config_dict, f_dict, dbg=False): """ diff --git a/CPAC/utils/datasource.py b/CPAC/utils/datasource.py index ca4082b810..299f8026e3 100644 --- a/CPAC/utils/datasource.py +++ b/CPAC/utils/datasource.py @@ -24,6 +24,7 @@ from CPAC.resources.templates.lookup_table import format_identifier, \ lookup_identifier from CPAC.utils import function +from CPAC.utils.bids_utils import bids_remove_entity from CPAC.utils.interfaces.function import Function from CPAC.utils.utils import get_scan_params @@ -1031,6 +1032,9 @@ def create_roi_mask_dataflow(masks, wf_name='datasource_roi_mask'): if base_file.endswith(ext) ][0] + for key in ['res', 'space']: + base_name = bids_remove_entity(base_name, key) + except IndexError: # pylint: disable=raise-missing-from raise ValueError('Error in spatial_map_dataflow: File '