Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Collect and apply field maps #79

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
7 changes: 4 additions & 3 deletions src/fmripost_aroma/data/io_spec.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"name": "aroma",
"queries": {
"raw": {
"bold_raw": {
Expand Down Expand Up @@ -152,8 +153,8 @@
},
"entities": [
{
"name": "datatype",
"pattern": "[/\\\\]+(anat|func)[/\\\\]+"
"name": "fmapid",
"pattern": "fmapid-([a-zA-Z0-9]+)"
},
{
"name": "cohort",
Expand All @@ -173,7 +174,7 @@
"pattern": "(?:^|_)thresh-([a-zA-Z0-9]+)"
}
],
"patterns": [
"default_path_patterns": [
"sub-{subject}[/ses-{session}]/{datatype<func>|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<bold|boldref|dseg|mask>}.{extension<nii|nii.gz|json>|nii.gz}",
"sub-{subject}[/ses-{session}]/{datatype<func>|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<components|mixing>}.{extension<nii|nii.gz|json>|nii.gz}",
"sub-{subject}[/ses-{session}]/{datatype<func>|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<components|mixing>}.{extension<tsv|json>|tsv}",
Expand Down
2 changes: 1 addition & 1 deletion src/fmripost_aroma/interfaces/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
11 changes: 9 additions & 2 deletions src/fmripost_aroma/utils/bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,21 @@ 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())

if spec is None:
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, {})
Expand All @@ -114,7 +121,7 @@ def collect_derivatives(
if isinstance(layout, Path):
layout = BIDSLayout(
layout,
config=['bids', 'derivatives'],
config=config,
validate=False,
)

Expand Down
25 changes: 22 additions & 3 deletions src/fmripost_aroma/workflows/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
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,
Expand All @@ -191,6 +192,7 @@
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,
Expand Down Expand Up @@ -304,14 +306,31 @@

entities = extract_entities(bold_file)

# Attempt to extract the associated fmap ID
fmapid = None
all_fmapids = config.execution.layout.get_fmapids(

Check warning on line 311 in src/fmripost_aroma/workflows/base.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L310-L311

Added lines #L310 - L311 were not covered by tests
subject=entities['subject'],
session=entities.get('session', None),
)
if all_fmapids:
fmap_file = config.execution.layout.get_nearest(

Check warning on line 316 in src/fmripost_aroma/workflows/base.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L316

Added line #L316 was not covered by tests
bold_file,
to=all_fmapids,
suffix='xfm',
extension='.txt',
strict=False,
**{'from': 'boldref'},
)
fmapid = config.execution.layout.get_file(fmap_file).entities['to']

Check warning on line 324 in src/fmripost_aroma/workflows/base.py

View check run for this annotation

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L324

Added line #L324 was not covered by tests

functional_cache = defaultdict(list, {})
if config.execution.derivatives:
# Collect native-space derivatives and transforms
functional_cache = collect_derivatives(
raw_dataset=config.execution.layout,
derivatives_dataset=None,
entities=entities,
fieldmap_id=None,
fieldmap_id=fmapid,
allow_multiple=False,
spaces=None,
)
Expand All @@ -322,7 +341,7 @@
raw_dataset=None,
derivatives_dataset=deriv_dir,
entities=entities,
fieldmap_id=None,
fieldmap_id=fmapid,
allow_multiple=False,
spaces=spaces,
),
Expand All @@ -347,7 +366,7 @@
raw_dataset=None,
derivatives_dataset=config.execution.layout,
entities=entities,
fieldmap_id=None,
fieldmap_id=fmapid,
allow_multiple=False,
spaces=spaces,
),
Expand Down