diff --git a/src/fmripost_aroma/data/io_spec.json b/src/fmripost_aroma/data/io_spec.json index 9493d36..81a9007 100644 --- a/src/fmripost_aroma/data/io_spec.json +++ b/src/fmripost_aroma/data/io_spec.json @@ -81,6 +81,8 @@ }, "anat_dseg": { "datatype": "anat", + "task": null, + "run": null, "space": null, "res": null, "den": null, diff --git a/src/fmripost_aroma/data/reports-spec-func.yml b/src/fmripost_aroma/data/reports-spec-func.yml index 29e8513..179e200 100644 --- a/src/fmripost_aroma/data/reports-spec-func.yml +++ b/src/fmripost_aroma/data/reports-spec-func.yml @@ -10,17 +10,15 @@ sections: reportlets: - bids: {datatype: figures, desc: summary, suffix: bold} - bids: {datatype: figures, desc: validation, suffix: bold} - - bids: {datatype: figures, desc: aroma, suffix: bold} - - bids: {datatype: figures, desc: metrics, suffix: bold} - - bids: {datatype: figures, desc: coreg, suffix: bold} + - bids: {datatype: figures, desc: normalization, suffix: bold} caption: This panel shows the alignment of the reference EPI (BOLD) image to the - anatomical (T1-weighted) image. - The reference EPI has been contrast enhanced and susceptibility-distortion - corrected (if applicable) for improved anatomical fidelity. - The anatomical image has been resampled into EPI space, as well as the - anatomical white matter mask, which appears as a red contour. + MNI152NLin6Asym template. + The anatomical white matter mask has been warped to MNI152NLin6Asym space + and appears as a red contour. static: false - subtitle: Alignment of functional and anatomical MRI data (coregistration) + subtitle: Alignment of functional and template MRI data (normalization) + - bids: {datatype: figures, desc: aroma, suffix: bold} + - bids: {datatype: figures, desc: metrics, suffix: bold} - bids: {datatype: figures, desc: preprocCarpetplot, suffix: bold} title: Preprocessed BOLD - bids: {datatype: figures, desc: nonaggrCarpetplot, suffix: bold} diff --git a/src/fmripost_aroma/data/reports-spec.yml b/src/fmripost_aroma/data/reports-spec.yml index eb346a3..e9c194d 100644 --- a/src/fmripost_aroma/data/reports-spec.yml +++ b/src/fmripost_aroma/data/reports-spec.yml @@ -10,17 +10,15 @@ sections: reportlets: - bids: {datatype: figures, desc: summary, suffix: bold} - bids: {datatype: figures, desc: validation, suffix: bold} - - bids: {datatype: figures, desc: aroma, suffix: bold} - - bids: {datatype: figures, desc: metrics, suffix: bold} - - bids: {datatype: figures, desc: coreg, suffix: bold} + - bids: {datatype: figures, desc: normalization, suffix: bold} caption: This panel shows the alignment of the reference EPI (BOLD) image to the - anatomical (T1-weighted) image. - The reference EPI has been contrast enhanced and susceptibility-distortion - corrected (if applicable) for improved anatomical fidelity. - The anatomical image has been resampled into EPI space, as well as the - anatomical white matter mask, which appears as a red contour. + MNI152NLin6Asym template. + The anatomical white matter mask has been warped to MNI152NLin6Asym space + and appears as a red contour. static: false - subtitle: Alignment of functional and anatomical MRI data (coregistration) + subtitle: Alignment of functional and template MRI data (normalization) + - bids: {datatype: figures, desc: aroma, suffix: bold} + - bids: {datatype: figures, desc: metrics, suffix: bold} - bids: {datatype: figures, desc: preprocCarpetplot, suffix: bold} title: Preprocessed BOLD - bids: {datatype: figures, desc: nonaggrCarpetplot, suffix: bold} diff --git a/src/fmripost_aroma/interfaces/nilearn.py b/src/fmripost_aroma/interfaces/nilearn.py index 936d8c8..5a0cda3 100644 --- a/src/fmripost_aroma/interfaces/nilearn.py +++ b/src/fmripost_aroma/interfaces/nilearn.py @@ -21,7 +21,7 @@ class _MeanImageInputSpec(BaseInterfaceInputSpec): ) mask_file = File( exists=True, - mandatory=True, + mandatory=False, desc='A binary brain mask.', ) out_file = File( @@ -46,11 +46,19 @@ class MeanImage(NilearnBaseInterface, SimpleInterface): output_spec = _MeanImageOutputSpec def _run_interface(self, runtime): + import nibabel as nb from nilearn.masking import apply_mask, unmask + from nipype.interfaces.base import isdefined + + if isdefined(self.inputs.mask_file): + data = apply_mask(self.inputs.bold_file, self.inputs.mask_file) + mean_data = data.mean(axis=0) + mean_img = unmask(mean_data, self.inputs.mask_file) + else: + in_img = nb.load(self.inputs.bold_file) + mean_data = in_img.get_fdata().mean(axis=3) + mean_img = nb.Nifti1Image(mean_data, in_img.affine, in_img.header) - data = apply_mask(self.inputs.bold_file, self.inputs.mask_file) - mean_data = data.mean(axis=0) - mean_img = unmask(mean_data, self.inputs.mask_file) self._results['out_file'] = os.path.join(runtime.cwd, self.inputs.out_file) mean_img.to_filename(self._results['out_file']) diff --git a/src/fmripost_aroma/workflows/outputs.py b/src/fmripost_aroma/workflows/outputs.py index 3a3e242..9000d4d 100644 --- a/src/fmripost_aroma/workflows/outputs.py +++ b/src/fmripost_aroma/workflows/outputs.py @@ -58,6 +58,7 @@ def init_func_fit_reports_wf( from nireports.interfaces.reporting.base import ( SimpleBeforeAfterRPT as SimpleBeforeAfter, ) + from templateflow.api import get as get_template from fmripost_aroma.interfaces.nilearn import MeanImage @@ -99,28 +100,36 @@ def init_func_fit_reports_wf( mem_gb=DEFAULT_MEMORY_MIN_GB, ) mni6_wm.inputs.label = 2 # BIDS default is WM=2 - workflow.connect([(dseg_to_mni6, mni6_wm, [('output_image', 'in_file')])]) + workflow.connect([(dseg_to_mni6, mni6_wm, [('output_image', 'in_seg')])]) # EPI-MNI registration epi_mni_report = pe.Node( SimpleBeforeAfter( - before_label='T1w', - after_label='EPI', + after=str( + get_template( + 'MNI152NLin6Asym', + resolution=2, + desc='brain', + suffix='T1w', + extension=['.nii', '.nii.gz'], + ) + ), + before_label='EPI', + after_label='MNI152NLin6Asym', dismiss_affine=True, ), name='epi_mni_report', mem_gb=0.1, ) workflow.connect([ - (inputnode, epi_mni_report, [('coreg_boldref', 'after')]), (calculate_mean_bold, epi_mni_report, [('out_file', 'before')]), - (mni6_wm, epi_mni_report, [('output_image', 'wm_seg')]), + (mni6_wm, epi_mni_report, [('out', 'wm_seg')]), ]) # fmt:skip ds_epi_mni_report = pe.Node( DerivativesDataSink( base_directory=output_dir, - desc='coreg', + desc='normalization', suffix='bold', datatype='figures', dismiss_entities=dismiss_echo(),