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

Apply transforms to raw data when MNI6 derivatives aren't available #58

Merged
merged 12 commits into from
Sep 3, 2024
Prev Previous commit
Next Next commit
Update test_base.py
tsalo committed Aug 29, 2024
commit f7f10da6e92829aa3b071a25e6e172996fb51e01
1 change: 1 addition & 0 deletions src/fmripost_aroma/tests/test_base.py
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ def test_init_ica_aroma_wf(tmp_path_factory):
wf = init_ica_aroma_wf(
bold_file='sub-01_task-rest_bold.nii.gz',
metadata={'RepetitionTime': 2.0},
mem_gb={'resampled': 1},
)
assert wf.name == 'aroma_task_rest_wf'


Unchanged files with check annotations Beta

def init_single_run_wf(bold_file):
"""Set up a single-run workflow for fMRIPost-AROMA."""
from fmriprep.utils.misc import estimate_bold_mem_usage

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

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L282

Added line #L282 was not covered by tests
from nipype.interfaces import utility as niu
from niworkflows.engine.workflows import LiterateWorkflow as Workflow
from fmripost_aroma.workflows.aroma import init_denoise_wf, init_ica_aroma_wf
spaces = config.workflow.spaces
omp_nthreads = config.nipype.omp_nthreads

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

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L290

Added line #L290 was not covered by tests
workflow = Workflow(name=_get_wf_name(bold_file, 'single_run'))
bold_metadata = config.execution.layout.get_metadata(bold_file)
mem_gb = estimate_bold_mem_usage(bold_file)[1]
ica_aroma_wf = init_ica_aroma_wf(bold_file=bold_file, metadata=bold_metadata, mem_gb=mem_gb)

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

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L295-L296

Added lines #L295 - L296 were not covered by tests
entities = extract_entities(bold_file)
functional_cache = defaultdict(list, {})
if config.execution.derivatives:
# Collect native-space derivatives and transforms
functional_cache = collect_derivatives(

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

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L303

Added line #L303 was not covered by tests
raw_dataset=config.execution.layout,
derivatives_dataset=None,
entities=entities,
if ('bold_mni152nlin6asym' not in functional_cache) and ('bold_raw' in functional_cache):
# Resample to MNI152NLin6Asym:res-2, for ICA-AROMA classification
from fmriprep.workflows.bold.apply import init_bold_volumetric_resample_wf
from fmriprep.workflows.bold.stc import init_bold_stc_wf
from niworkflows.interfaces.fixes import FixHeaderApplyTransforms as ApplyTransforms
from niworkflows.interfaces.header import ValidateImage
from templateflow.api import get as get_template

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

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L379-L383

Added lines #L379 - L383 were not covered by tests
validate_bold = pe.Node(

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

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L385

Added line #L385 was not covered by tests
ValidateImage(in_file=functional_cache['bold_raw']),
name='validate_bold',
)
stc_buffer = pe.Node(

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

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L390

Added line #L390 was not covered by tests
niu.IdentityInterface(fields=['bold_file']),
name='stc_buffer',
)
run_stc = ('SliceTiming' in bold_metadata) and 'slicetiming' not in config.workflow.ignore

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

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L394

Added line #L394 was not covered by tests
if run_stc:
bold_stc_wf = init_bold_stc_wf(

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

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L396

Added line #L396 was not covered by tests
mem_gb=mem_gb,
metadata=bold_metadata,
name='resample_stc_wf',
)
# TODO: Grab skip-vols from confounds file
bold_stc_wf.inputs.inputnode.skip_vols = config.workflow.dummy_scans or 0
workflow.connect([

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

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L402-L403

Added lines #L402 - L403 were not covered by tests
(validate_bold, bold_stc_wf, [('out_file', 'inputnode.bold_file')]),
(bold_stc_wf, stc_buffer, [('outputnode.stc_file', 'bold_file')]),
]) # fmt:skip
else:
workflow.connect([(validate_bold, stc_buffer, [('out_file', 'bold_file')])])

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

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L408

Added line #L408 was not covered by tests
mni6_mask = str(

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

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L410

Added line #L410 was not covered by tests
get_template(
'MNI152NLin6Asym',
resolution=2,
)
)
bold_MNI6_wf = init_bold_volumetric_resample_wf(

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

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L420

Added line #L420 was not covered by tests
metadata=bold_metadata,
fieldmap_id=None, # XXX: Ignoring the field map for now
omp_nthreads=omp_nthreads,
jacobian='fmap-jacobian' not in config.workflow.ignore,
name='bold_MNI6_wf',
)
bold_MNI6_wf.inputs.inputnode.bold_file = functional_cache['bold_raw']
bold_MNI6_wf.inputs.inputnode.motion_xfm = functional_cache['hmc']
bold_MNI6_wf.inputs.inputnode.boldref2fmap_xfm = functional_cache['boldref2fmap']
bold_MNI6_wf.inputs.inputnode.boldref2anat_xfm = functional_cache['boldref2anat']
bold_MNI6_wf.inputs.inputnode.anat2std_xfm = functional_cache['anat2mni152nlin6asym']
bold_MNI6_wf.inputs.inputnode.resolution = '02'

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

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L428-L433

Added lines #L428 - L433 were not covered by tests
# use mask as boldref?
bold_MNI6_wf.inputs.inputnode.bold_ref_file = functional_cache['bold_mask_native']
bold_MNI6_wf.inputs.inputnode.target_mask = mni6_mask
bold_MNI6_wf.inputs.inputnode.target_ref_file = mni6_mask

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

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L435-L437

Added lines #L435 - L437 were not covered by tests
workflow.connect([
# Resample BOLD to MNI152NLin6Asym, may duplicate bold_std_wf above
(bold_MNI6_wf, mni6_buffer, [('outputnode.bold_file', 'bold_mni152nlin6asym')]),
]) # fmt:skip
mask_to_mni6 = pe.Node(

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

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L450

Added line #L450 was not covered by tests
ApplyTransforms(
interpolation='MultiLabel',
input_image=functional_cache['bold_mask_native'],
),
name='mask_to_mni6',
)
workflow.connect([

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

Codecov / codecov/patch

src/fmripost_aroma/workflows/base.py#L462

Added line #L462 was not covered by tests
(mask_to_mni6, mni6_buffer, [('output_image', 'bold_mask_mni152nlin6asym')]),
]) # fmt:skip