Skip to content

Commit

Permalink
Update again.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsalo committed Sep 1, 2024
1 parent 25428f3 commit 63684e0
Show file tree
Hide file tree
Showing 12 changed files with 404 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/fmripost_phase/interfaces/bids.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
#
# Copyright 2021 The NiPreps Developers <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# We support and encourage derived works from this project, please read
# about our expectations at
#
# https://www.nipreps.org/community/licensing/
#
"""BIDS-related interfaces for fMRIPost-Phase."""

from json import loads
Expand Down
22 changes: 22 additions & 0 deletions src/fmripost_phase/interfaces/confounds.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
#
# Copyright 2021 The NiPreps Developers <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# We support and encourage derived works from this project, please read
# about our expectations at
#
# https://www.nipreps.org/community/licensing/
#
"""Interfaces for miscellaneous confound extraction methods, including HighCor."""

import os
Expand Down
22 changes: 22 additions & 0 deletions src/fmripost_phase/interfaces/gift.py
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
#
# Copyright 2021 The NiPreps Developers <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# We support and encourage derived works from this project, please read
# about our expectations at
#
# https://www.nipreps.org/community/licensing/
#
"""Interfaces for the GIFT toolbox."""
22 changes: 22 additions & 0 deletions src/fmripost_phase/interfaces/laynii.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
#
# Copyright 2021 The NiPreps Developers <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# We support and encourage derived works from this project, please read
# about our expectations at
#
# https://www.nipreps.org/community/licensing/
#
"""LayNii is a C++ library for layer fMRI processing and analysis."""

from nipype.interfaces.base import (
Expand Down
22 changes: 22 additions & 0 deletions src/fmripost_phase/interfaces/regression.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
#
# Copyright 2021 The NiPreps Developers <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# We support and encourage derived works from this project, please read
# about our expectations at
#
# https://www.nipreps.org/community/licensing/
#
"""Interfaces for phase regression."""

import numpy as np
Expand Down
162 changes: 162 additions & 0 deletions src/fmripost_phase/interfaces/reportlets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
#
# Copyright 2021 The NiPreps Developers <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# We support and encourage derived works from this project, please read
# about our expectations at
#
# https://www.nipreps.org/community/licensing/
#
"""ReportCapableInterfaces for segmentation tools."""

import os
import re
import time
from collections import Counter

from nipype.interfaces.base import (
BaseInterfaceInputSpec,
File,
InputMultiObject,
SimpleInterface,
Str,
TraitedSpec,
isdefined,
traits,
)

SUBJECT_TEMPLATE = """\
\t<ul class="elem-desc">
\t\t<li>Subject ID: {subject_id}</li>
\t\t<li>Functional series: {n_bold:d}</li>
{tasks}
\t\t<li>Standard output spaces: {std_spaces}</li>
\t\t<li>Non-standard output spaces: {nstd_spaces}</li>
\t</ul>
"""

FUNCTIONAL_TEMPLATE = """\
\t\t<details open>
\t\t<summary>Summary</summary>
\t\t<ul class="elem-desc">
\t\t\t<li>Original orientation: {ornt}</li>
\t\t\t<li>Repetition time (TR): {tr:.03g}s</li>
\t\t\t<li>Phase-encoding (PE) direction: {pedir}</li>
\t\t\t<li>Slice timing correction: {stc}</li>
\t\t\t<li>Susceptibility distortion correction: {sdc}</li>
\t\t\t<li>Registration: {registration}</li>
\t\t\t<li>Non-steady-state volumes: {dummy_scan_desc}</li>
\t\t</ul>
\t\t</details>
"""

ABOUT_TEMPLATE = """\t<ul>
\t\t<li>fMRIPost-Phase version: {version}</li>
\t\t<li>fMRIPost-Phase command: <code>{command}</code></li>
\t\t<li>Date postprocessed: {date}</li>
\t</ul>
</div>
"""


class SummaryOutputSpec(TraitedSpec):
out_report = File(exists=True, desc='HTML segment containing summary')


class SummaryInterface(SimpleInterface):
output_spec = SummaryOutputSpec

def _run_interface(self, runtime):
segment = self._generate_segment()
fname = os.path.join(runtime.cwd, 'report.html')
with open(fname, 'w') as fobj:
fobj.write(segment)
self._results['out_report'] = fname
return runtime

def _generate_segment(self):
raise NotImplementedError


class SubjectSummaryInputSpec(BaseInterfaceInputSpec):
subject_id = Str(desc='Subject ID')
bold = InputMultiObject(
traits.Either(File(exists=True), traits.List(File(exists=True))),
desc='BOLD functional series',
)
std_spaces = traits.List(Str, desc='list of standard spaces')
nstd_spaces = traits.List(Str, desc='list of non-standard spaces')


class SubjectSummary(SummaryInterface):
input_spec = SubjectSummaryInputSpec
output_spec = SummaryOutputSpec

def _generate_segment(self):
BIDS_NAME = re.compile(
r'^(.*\/)?'
'(?P<subject_id>sub-[a-zA-Z0-9]+)'
'(_(?P<session_id>ses-[a-zA-Z0-9]+))?'
'(_(?P<task_id>task-[a-zA-Z0-9]+))?'
'(_(?P<acq_id>acq-[a-zA-Z0-9]+))?'
'(_(?P<rec_id>rec-[a-zA-Z0-9]+))?'
'(_(?P<run_id>run-[a-zA-Z0-9]+))?'
)

# Add list of tasks with number of runs
bold_series = self.inputs.bold if isdefined(self.inputs.bold) else []
bold_series = [s[0] if isinstance(s, list) else s for s in bold_series]

counts = Counter(
BIDS_NAME.search(series).groupdict()['task_id'][5:] for series in bold_series
)

tasks = ''
if counts:
header = '\t\t<ul class="elem-desc">'
footer = '\t\t</ul>'
lines = [
'\t\t\t<li>Task: {task_id} ({n_runs:d} run{s})</li>'.format(
task_id=task_id, n_runs=n_runs, s='' if n_runs == 1 else 's'
)
for task_id, n_runs in sorted(counts.items())
]
tasks = '\n'.join([header] + lines + [footer])

return SUBJECT_TEMPLATE.format(
subject_id=self.inputs.subject_id,
n_bold=len(bold_series),
tasks=tasks,
std_spaces=', '.join(self.inputs.std_spaces),
nstd_spaces=', '.join(self.inputs.nstd_spaces),
)


class AboutSummaryInputSpec(BaseInterfaceInputSpec):
version = Str(desc='FMRIPREP version')
command = Str(desc='FMRIPREP command')
# Date not included - update timestamp only if version or command changes


class AboutSummary(SummaryInterface):
input_spec = AboutSummaryInputSpec

def _generate_segment(self):
return ABOUT_TEMPLATE.format(
version=self.inputs.version,
command=self.inputs.command,
date=time.strftime('%Y-%m-%d %H:%M:%S %z'),
)
22 changes: 22 additions & 0 deletions src/fmripost_phase/interfaces/warpkit.py
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
#
# Copyright 2021 The NiPreps Developers <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# We support and encourage derived works from this project, please read
# about our expectations at
#
# https://www.nipreps.org/community/licensing/
#
"""Interfaces for the warpkit toolbox."""
22 changes: 22 additions & 0 deletions src/fmripost_phase/utils/bids.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
#
# Copyright 2021 The NiPreps Developers <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# We support and encourage derived works from this project, please read
# about our expectations at
#
# https://www.nipreps.org/community/licensing/
#
"""Utilities to handle BIDS inputs."""

from __future__ import annotations
Expand Down
22 changes: 22 additions & 0 deletions src/fmripost_phase/utils/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
#
# Copyright 2021 The NiPreps Developers <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# We support and encourage derived works from this project, please read
# about our expectations at
#
# https://www.nipreps.org/community/licensing/
#
"""Utility functions for fmriprep_phase."""

from nipype.pipeline import engine as pe
Expand Down
22 changes: 22 additions & 0 deletions src/fmripost_phase/workflows/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
#
# Copyright 2021 The NiPreps Developers <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# We support and encourage derived works from this project, please read
# about our expectations at
#
# https://www.nipreps.org/community/licensing/
#
"""Workflow functions for fMRIPost-phase."""

from fmripost_phase.workflows import base, regression
Expand Down
Loading

0 comments on commit 63684e0

Please sign in to comment.