Skip to content

Commit

Permalink
👔 Strip space and res from atlas keys
Browse files Browse the repository at this point in the history
  • Loading branch information
shnizzedy committed Jan 27, 2023
1 parent 91054ac commit 2ab869f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
8 changes: 4 additions & 4 deletions CPAC/resources/templates/BIDS_identifiers.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions CPAC/utils/bids_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
4 changes: 4 additions & 0 deletions CPAC/utils/datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 '
Expand Down

0 comments on commit 2ab869f

Please sign in to comment.