diff --git a/src/fmripost_aroma/data/io_spec.json b/src/fmripost_aroma/data/io_spec.json index 8b635a7..d75a6bf 100644 --- a/src/fmripost_aroma/data/io_spec.json +++ b/src/fmripost_aroma/data/io_spec.json @@ -1,4 +1,5 @@ { + "name": "aroma", "queries": { "raw": { "bold_raw": { @@ -151,8 +152,8 @@ }, "entities": [ { - "name": "datatype", - "pattern": "[/\\\\]+(anat|func)[/\\\\]+" + "name": "fmapid", + "pattern": "fmapid-([a-zA-Z0-9]+)" }, { "name": "cohort", @@ -172,7 +173,7 @@ "pattern": "(?:^|_)thresh-([a-zA-Z0-9]+)" } ], - "patterns": [ + "default_path_patterns": [ "sub-{subject}[/ses-{session}]/{datatype|func}/sub-{subject}[_ses-{session}]_task-{task}[_acq-{acquisition}][_ce-{ceagent}][_rec-{reconstruction}][_run-{run}][_echo-{echo}][_part-{part}][_space-{space}][_res-{res}][_desc-{desc}]_{suffix}.{extension|nii.gz}", "sub-{subject}[/ses-{session}]/{datatype|func}/sub-{subject}[_ses-{session}]_task-{task}[_acq-{acquisition}][_ce-{ceagent}][_rec-{reconstruction}][_run-{run}][_echo-{echo}][_part-{part}][_space-{space}][_res-{res}][_stat-{statistic}][_desc-{desc}]_{suffix}.{extension|nii.gz}", "sub-{subject}[/ses-{session}]/{datatype|func}/sub-{subject}[_ses-{session}]_task-{task}[_acq-{acquisition}][_ce-{ceagent}][_rec-{reconstruction}][_run-{run}][_echo-{echo}][_part-{part}][_space-{space}][_res-{res}][_stat-{statistic}][_desc-{desc}]_{suffix}.{extension|tsv}", diff --git a/src/fmripost_aroma/interfaces/bids.py b/src/fmripost_aroma/interfaces/bids.py index d90ead0..e36e0e3 100644 --- a/src/fmripost_aroma/interfaces/bids.py +++ b/src/fmripost_aroma/interfaces/bids.py @@ -31,4 +31,4 @@ class DerivativesDataSink(BaseDerivativesDataSink): _allowed_entities = set(config_entities) _config_entities = config_entities _config_entities_dict = merged_entities - _file_patterns = fmripost_aroma_spec['patterns'] + _file_patterns = fmripost_aroma_spec['default_path_patterns'] diff --git a/src/fmripost_aroma/utils/bids.py b/src/fmripost_aroma/utils/bids.py index df4104e..c694ee8 100644 --- a/src/fmripost_aroma/utils/bids.py +++ b/src/fmripost_aroma/utils/bids.py @@ -98,6 +98,7 @@ def collect_derivatives( if not entities: entities = {} + _spec = None if spec is None or patterns is None: _spec = json.loads(load_data.readable('io_spec.json').read_text()) @@ -105,7 +106,13 @@ def collect_derivatives( spec = _spec['queries'] if patterns is None: - patterns = _spec['patterns'] + patterns = _spec['default_path_patterns'] + + _spec.pop('queries') + + config = ['bids', 'derivatives'] + if _spec: + config = ['bids', 'derivatives', _spec] # Search for derivatives data derivs_cache = defaultdict(list, {}) @@ -114,7 +121,7 @@ def collect_derivatives( if isinstance(layout, Path): layout = BIDSLayout( layout, - config=['bids', 'derivatives'], + config=config, validate=False, ) diff --git a/src/fmripost_aroma/workflows/base.py b/src/fmripost_aroma/workflows/base.py index c60a29f..0499058 100644 --- a/src/fmripost_aroma/workflows/base.py +++ b/src/fmripost_aroma/workflows/base.py @@ -179,6 +179,7 @@ def init_single_subject_wf(subject_id: str): if config.execution.derivatives: # Raw dataset + derivatives dataset config.loggers.workflow.info('Raw+derivatives workflow mode enabled') + # Just build a list of BOLD files right now subject_data = collect_derivatives( raw_dataset=config.execution.layout, derivatives_dataset=None, @@ -191,6 +192,7 @@ def init_single_subject_wf(subject_id: str): else: # Derivatives dataset only config.loggers.workflow.info('Derivatives-only workflow mode enabled') + # Just build a list of BOLD files right now subject_data = collect_derivatives( raw_dataset=None, derivatives_dataset=config.execution.layout, @@ -304,6 +306,23 @@ def init_single_run_wf(bold_file): entities = extract_entities(bold_file) + # Attempt to extract the associated fmap ID + fmapid = None + all_fmapids = config.execution.layout.get_fmapids( + subject=entities['subject'], + session=entities.get('session', None), + ) + if all_fmapids: + fmap_file = config.execution.layout.get_nearest( + bold_file, + to=all_fmapids, + suffix='xfm', + extension='.txt', + strict=False, + **{'from': 'boldref'}, + ) + fmapid = config.execution.layout.get_file(fmap_file).entities['to'] + functional_cache = defaultdict(list, {}) if config.execution.derivatives: # Collect native-space derivatives and transforms @@ -311,7 +330,7 @@ def init_single_run_wf(bold_file): raw_dataset=config.execution.layout, derivatives_dataset=None, entities=entities, - fieldmap_id=None, + fieldmap_id=fmapid, allow_multiple=False, spaces=None, ) @@ -322,7 +341,7 @@ def init_single_run_wf(bold_file): raw_dataset=None, derivatives_dataset=deriv_dir, entities=entities, - fieldmap_id=None, + fieldmap_id=fmapid, allow_multiple=False, spaces=spaces, ), @@ -347,7 +366,7 @@ def init_single_run_wf(bold_file): raw_dataset=None, derivatives_dataset=config.execution.layout, entities=entities, - fieldmap_id=None, + fieldmap_id=fmapid, allow_multiple=False, spaces=spaces, ),