Skip to content

Commit d84d680

Browse files
authored
Apply transforms to raw data when MNI6 derivatives aren't available (#58)
1 parent d3f8b26 commit d84d680

File tree

16 files changed

+458
-150
lines changed

16 files changed

+458
-150
lines changed

.github/ISSUE_TEMPLATE/bug_report.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Bug Report
2+
description: File a report of a problem you encountered.
3+
labels: ["bug"]
4+
body:
5+
- type: markdown
6+
attributes:
7+
value: |
8+
# Thanks for taking the time to fill out this bug report!
9+
### The following information will help us in getting your issue resolved.
10+
- type: textarea
11+
id: what-happened
12+
attributes:
13+
label: What happened?
14+
description: A short description of what went wrong.
15+
validations:
16+
required: true
17+
- type: textarea
18+
id: command
19+
attributes:
20+
label: What command did you use?
21+
description: |
22+
If you're using `fmriprep-docker`, please include the `RUNNING: ...` line that is printed first.
23+
This helps us replicate the problem. This will be automatically formatted into code, so no need for backticks.
24+
render: shell
25+
validations:
26+
required: true
27+
- type: input
28+
id: version
29+
attributes:
30+
label: What version of fMRIPost-AROMA are you running?
31+
validations:
32+
required: true
33+
- type: dropdown
34+
id: environment
35+
attributes:
36+
label: How are you running fMRIPost-AROMA?
37+
options:
38+
- Docker
39+
- Singularity
40+
- Local installation ("bare-metal")
41+
- Other
42+
validations:
43+
required: true
44+
- type: dropdown
45+
id: bids-valid
46+
attributes:
47+
label: Is your data BIDS valid?
48+
description: |
49+
The BIDS validator can be found at: https://bids-standard.github.io/bids-validator/
50+
Errors should not be present, but warnings are acceptable.
51+
options:
52+
- "Yes"
53+
- "No"
54+
validations:
55+
required: true
56+
- type: dropdown
57+
id: reuse
58+
attributes:
59+
label: Are you reusing any previously computed results?
60+
description: |
61+
You can select multiple options.
62+
We recommend using a fresh working directory when upgrading to a new fMRIPost-AROMA minor series.
63+
multiple: true
64+
options:
65+
- FreeSurfer
66+
- Anatomical derivatives
67+
- Work directory
68+
- "No"
69+
validations:
70+
required: true
71+
- type: textarea
72+
id: logs
73+
attributes:
74+
label: Please copy and paste any relevant log output.
75+
description: |
76+
Can you find some traces of the error reported in the visual report (at the bottom) or in *crashfiles*?
77+
This will be automatically formatted into code, so no need for backticks.
78+
render: shell
79+
- type: textarea
80+
id: addinfo
81+
attributes:
82+
label: Additional information / screenshots
83+
description: |
84+
If you would like to include any further information, such as any visual reports, please include them below.
85+
Alternatively, you can privately share with us at <nipreps@gmail.com>.
86+
Reports do not contain data usable with personal identification or other research purposes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
name: Documentation improvement
3+
about: Is the documentation of something missing, unclear, or lacking? This is the place.
4+
title: ''
5+
labels: 'documentation'
6+
assignees: ''
7+
8+
---
9+
<!--
10+
For the Documentation request, please include the following:
11+
------------------------
12+
What would you like changed/added and why?
13+
Do you have any suggestions for the new documents?
14+
-->
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Feature Request
2+
description: Suggest an idea for a new feature or a change to an existing one.
3+
labels: ["enhancement"]
4+
body:
5+
- type: markdown
6+
attributes:
7+
value: |
8+
## Thank you for your suggestion!
9+
10+
We welcome any ideas about how to make *fMRIPost-AROMA* better for the community.
11+
Please keep in mind that features may not get implemented immediately.
12+
- type: textarea
13+
id: summary
14+
attributes:
15+
label: What would you like to see added in fMRIPost-AROMA?
16+
description: |
17+
What are you trying to achieve with fMRIPost-AROMA?
18+
Is this a more convenient way to do something that is already possible, or is a workaround currently unfeasible?
19+
Does this feature adhere to the [NiPreps driving principles](https://www.nipreps.org/community/CONTRIBUTING/#driving-principles)?
20+
validations:
21+
required: true
22+
- type: dropdown
23+
id: interest
24+
attributes:
25+
label: Do you have any interest in helping implement the feature?
26+
description: |
27+
We appreciate any help you can offer!
28+
For information on how to contribute, please refer to our [contributing guidelines](https://www.nipreps.org/community/CONTRIBUTING/).
29+
options:
30+
- "Yes"
31+
- Yes, but I would need guidance
32+
- "No"
33+
validations:
34+
required: true
35+
- type: textarea
36+
id: addinfo
37+
attributes:
38+
label: Additional information / screenshots
39+
description: Add any additional information or context about the feature request here.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ dependencies = [
2121
"fmriprep @ git+https://github.com/nipreps/fmriprep.git@master",
2222
"nipype >= 1.8.5",
2323
"nireports @ git+https://github.com/nipreps/nireports.git@main",
24+
"nitransforms == 23.0.1",
2425
"niworkflows @ git+https://github.com/nipreps/niworkflows.git@master",
2526
"pybids >= 0.15.6",
2627
"sdcflows @ git+https://github.com/nipreps/sdcflows.git@master",

src/fmripost_aroma/cli/parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,8 @@ def _bids_filter(value, parser):
318318
required=False,
319319
action='store',
320320
nargs='+',
321-
default=[],
322-
choices=['fieldmaps', 'slicetiming', 'jacobian'],
321+
default=['fieldmaps'],
322+
choices=['fieldmaps', 'slicetiming', 'fmap-jacobian'],
323323
help=(
324324
'Ignore selected aspects of the input dataset to disable corresponding '
325325
'parts of the resampling workflow (a space delimited list)'

src/fmripost_aroma/config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,10 +546,17 @@ class workflow(_Config):
546546
(positive = exact, negative = maximum)."""
547547
denoise_method = None
548548
"""Denoising strategy to be used."""
549+
ignore = None
550+
"""Ignore particular steps for *fMRIPost-AROMA*."""
549551
cifti_output = None
550552
"""Generate HCP Grayordinates, accepts either ``'91k'`` (default) or ``'170k'``."""
551553
dummy_scans = None
552554
"""Set a number of initial scans to be considered nonsteady states."""
555+
slice_time_ref = 0.5
556+
"""The time of the reference slice to correct BOLD values to, as a fraction
557+
acquisition time. 0 indicates the start, 0.5 the midpoint, and 1 the end
558+
of acquisition. The alias `start` corresponds to 0, and `middle` to 0.5.
559+
The default value is 0.5."""
553560

554561

555562
class loggers:

src/fmripost_aroma/data/io_spec.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,20 @@
7878
"extension": [
7979
".tsv"
8080
]
81+
},
82+
"anat_dseg": {
83+
"datatype": "anat",
84+
"task": null,
85+
"run": null,
86+
"space": null,
87+
"res": null,
88+
"den": null,
89+
"desc": null,
90+
"suffix": "dseg",
91+
"extension": [
92+
".nii.gz",
93+
".nii"
94+
]
8195
}
8296
},
8397
"transforms": {

src/fmripost_aroma/data/reports-spec-func.yml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,15 @@ sections:
1010
reportlets:
1111
- bids: {datatype: figures, desc: summary, suffix: bold}
1212
- bids: {datatype: figures, desc: validation, suffix: bold}
13-
- bids: {datatype: figures, desc: aroma, suffix: bold}
14-
- bids: {datatype: figures, desc: metrics, suffix: bold}
15-
- bids: {datatype: figures, desc: coreg, suffix: bold}
13+
- bids: {datatype: figures, desc: normalization, suffix: bold}
1614
caption: This panel shows the alignment of the reference EPI (BOLD) image to the
17-
anatomical (T1-weighted) image.
18-
The reference EPI has been contrast enhanced and susceptibility-distortion
19-
corrected (if applicable) for improved anatomical fidelity.
20-
The anatomical image has been resampled into EPI space, as well as the
21-
anatomical white matter mask, which appears as a red contour.
15+
MNI152NLin6Asym template.
16+
The anatomical white matter mask has been warped to MNI152NLin6Asym space
17+
and appears as a red contour.
2218
static: false
23-
subtitle: Alignment of functional and anatomical MRI data (coregistration)
19+
subtitle: Alignment of functional and template MRI data (normalization)
20+
- bids: {datatype: figures, desc: aroma, suffix: bold}
21+
- bids: {datatype: figures, desc: metrics, suffix: bold}
2422
- bids: {datatype: figures, desc: preprocCarpetplot, suffix: bold}
2523
title: Preprocessed BOLD
2624
- bids: {datatype: figures, desc: nonaggrCarpetplot, suffix: bold}

src/fmripost_aroma/data/reports-spec.yml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,15 @@ sections:
1010
reportlets:
1111
- bids: {datatype: figures, desc: summary, suffix: bold}
1212
- bids: {datatype: figures, desc: validation, suffix: bold}
13-
- bids: {datatype: figures, desc: aroma, suffix: bold}
14-
- bids: {datatype: figures, desc: metrics, suffix: bold}
15-
- bids: {datatype: figures, desc: coreg, suffix: bold}
13+
- bids: {datatype: figures, desc: normalization, suffix: bold}
1614
caption: This panel shows the alignment of the reference EPI (BOLD) image to the
17-
anatomical (T1-weighted) image.
18-
The reference EPI has been contrast enhanced and susceptibility-distortion
19-
corrected (if applicable) for improved anatomical fidelity.
20-
The anatomical image has been resampled into EPI space, as well as the
21-
anatomical white matter mask, which appears as a red contour.
15+
MNI152NLin6Asym template.
16+
The anatomical white matter mask has been warped to MNI152NLin6Asym space
17+
and appears as a red contour.
2218
static: false
23-
subtitle: Alignment of functional and anatomical MRI data (coregistration)
19+
subtitle: Alignment of functional and template MRI data (normalization)
20+
- bids: {datatype: figures, desc: aroma, suffix: bold}
21+
- bids: {datatype: figures, desc: metrics, suffix: bold}
2422
- bids: {datatype: figures, desc: preprocCarpetplot, suffix: bold}
2523
title: Preprocessed BOLD
2624
- bids: {datatype: figures, desc: nonaggrCarpetplot, suffix: bold}

src/fmripost_aroma/interfaces/confounds.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ def _get_ica_confounds(mixing, aroma_features, skip_vols, newpath=None):
101101

102102
# Regress the good components out of the bad time series to get "pure evil" regressors
103103
signal_mixing_arr = mixing_arr[signal_ics, :].T
104-
orthaggr_mixing_arr = aggr_mixing_arr.copy()
105104
aggr_mixing_arr_z = stats.zscore(aggr_mixing_arr, axis=0)
106105
signal_mixing_arr_z = stats.zscore(signal_mixing_arr, axis=0)
107106
betas = np.linalg.lstsq(signal_mixing_arr_z, aggr_mixing_arr_z, rcond=None)[0]

src/fmripost_aroma/interfaces/nilearn.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class _MeanImageInputSpec(BaseInterfaceInputSpec):
2121
)
2222
mask_file = File(
2323
exists=True,
24-
mandatory=True,
24+
mandatory=False,
2525
desc='A binary brain mask.',
2626
)
2727
out_file = File(
@@ -46,11 +46,19 @@ class MeanImage(NilearnBaseInterface, SimpleInterface):
4646
output_spec = _MeanImageOutputSpec
4747

4848
def _run_interface(self, runtime):
49+
import nibabel as nb
4950
from nilearn.masking import apply_mask, unmask
51+
from nipype.interfaces.base import isdefined
52+
53+
if isdefined(self.inputs.mask_file):
54+
data = apply_mask(self.inputs.bold_file, self.inputs.mask_file)
55+
mean_data = data.mean(axis=0)
56+
mean_img = unmask(mean_data, self.inputs.mask_file)
57+
else:
58+
in_img = nb.load(self.inputs.bold_file)
59+
mean_data = in_img.get_fdata().mean(axis=3)
60+
mean_img = nb.Nifti1Image(mean_data, in_img.affine, in_img.header)
5061

51-
data = apply_mask(self.inputs.bold_file, self.inputs.mask_file)
52-
mean_data = data.mean(axis=0)
53-
mean_img = unmask(mean_data, self.inputs.mask_file)
5462
self._results['out_file'] = os.path.join(runtime.cwd, self.inputs.out_file)
5563
mean_img.to_filename(self._results['out_file'])
5664

src/fmripost_aroma/tests/test_base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def test_init_ica_aroma_wf(tmp_path_factory):
2020
wf = init_ica_aroma_wf(
2121
bold_file='sub-01_task-rest_bold.nii.gz',
2222
metadata={'RepetitionTime': 2.0},
23+
mem_gb={'resampled': 1},
2324
)
2425
assert wf.name == 'aroma_task_rest_wf'
2526

src/fmripost_aroma/workflows/aroma.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def init_ica_aroma_wf(
3535
*,
3636
bold_file: str,
3737
metadata: dict,
38+
mem_gb: dict,
3839
susan_fwhm: float = 6.0,
3940
):
4041
"""Build a workflow that runs `ICA-AROMA`_.
@@ -192,6 +193,7 @@ def init_ica_aroma_wf(
192193
output_type='NIFTI' if config.execution.low_mem else 'NIFTI_GZ',
193194
),
194195
name='smooth',
196+
mem_gb=mem_gb['resampled'],
195197
)
196198
workflow.connect([
197199
(rm_non_steady_state, smooth, [('bold_cut', 'in_file')]),
@@ -209,6 +211,7 @@ def init_ica_aroma_wf(
209211
dim=config.workflow.melodic_dim,
210212
),
211213
name='melodic',
214+
mem_gb=mem_gb['resampled'],
212215
)
213216
workflow.connect([
214217
(inputnode, melodic, [('bold_mask_std', 'mask')]),

0 commit comments

Comments
 (0)