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

Split regressor estimation and denoising steps #17

Draft
wants to merge 33 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
a3c44a4
Work on memory issues.
tsalo Sep 5, 2024
e00778c
Don't run GLM within rapidtide call.
tsalo Sep 6, 2024
52b702d
Update rapidtide.py
tsalo Sep 6, 2024
1bde248
Try tracking outputs.
tsalo Sep 6, 2024
b97bff1
Run rapidtide on boldref-space data.
tsalo Sep 6, 2024
9003dbc
Write out delay map and regressor.
tsalo Sep 6, 2024
7e62346
Fix filenames.
tsalo Sep 6, 2024
358bd2f
Fix stuff.
tsalo Sep 6, 2024
9b55cf3
Work on denoising step.
tsalo Sep 7, 2024
15da054
Merge branch 'main' into memory-issues
tsalo Sep 7, 2024
c16841d
Update.
tsalo Sep 7, 2024
adf5c40
Update.
tsalo Sep 7, 2024
806bc5d
Keep working.
tsalo Sep 7, 2024
b0475c4
Fix import.
tsalo Sep 18, 2024
ab3b7fa
Update rapidtide.py
tsalo Sep 18, 2024
4df6124
Work on rapidtide interfaces.
tsalo Sep 26, 2024
c7315d3
Update rapidtide.py
tsalo Sep 26, 2024
8bfd10e
A bit more work.
tsalo Sep 28, 2024
320718d
Fix some stuff up.
tsalo Oct 9, 2024
5e9c610
Merge branch 'main' into memory-issues
tsalo Oct 9, 2024
db47088
Minor fix.
tsalo Oct 9, 2024
a7068a5
Update rapidtide version.
tsalo Oct 9, 2024
4abb7e2
Fix?
tsalo Oct 9, 2024
d4db0b5
update
tsalo Oct 9, 2024
743affb
[DATALAD] Added subdataset
tsalo Oct 9, 2024
7832f03
[DATALAD] Added subdataset
tsalo Oct 9, 2024
6fb425b
[DATALAD] Added subdataset
tsalo Oct 9, 2024
5c027da
Update.
tsalo Oct 9, 2024
387ea91
Remove old submodules.
tsalo Oct 9, 2024
b5cf819
Update.
tsalo Oct 9, 2024
430a676
Update.
tsalo Oct 9, 2024
eec3bc8
Update test_base.py
tsalo Oct 9, 2024
22be228
Update test_base.py
tsalo Oct 9, 2024
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
Prev Previous commit
Next Next commit
Update.
  • Loading branch information
tsalo committed Sep 7, 2024
commit c16841dec83cf1d8b4d03999dff767fabf410faf
4 changes: 0 additions & 4 deletions src/fmripost_rapidtide/workflows/base.py
Original file line number Diff line number Diff line change
@@ -134,16 +134,16 @@

"""
from bids.utils import listify
from nipype.interfaces import utility as niu

Check warning on line 137 in src/fmripost_rapidtide/workflows/base.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/base.py#L137

Added line #L137 was not covered by tests
from niworkflows.engine.workflows import LiterateWorkflow as Workflow
from niworkflows.interfaces.bids import BIDSInfo
from niworkflows.interfaces.nilearn import NILEARN_VERSION

from fmripost_rapidtide.interfaces.bids import DerivativesDataSink
from fmripost_rapidtide.interfaces.nilearn import MeanImage

Check warning on line 143 in src/fmripost_rapidtide/workflows/base.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/base.py#L143

Added line #L143 was not covered by tests
from fmripost_rapidtide.interfaces.reportlets import AboutSummary, SubjectSummary
from fmripost_rapidtide.utils.bids import collect_derivatives
from fmripost_rapidtide.workflows.rapidtide import init_denoise_single_run_wf

Check warning on line 146 in src/fmripost_rapidtide/workflows/base.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/base.py#L146

Added line #L146 was not covered by tests

spaces = config.workflow.spaces

@@ -201,7 +201,7 @@
spaces=None,
)
# Patch standard-space BOLD files into 'bold' key
subject_data['bold'] = listify(subject_data['bold_boldref'])

Check warning on line 204 in src/fmripost_rapidtide/workflows/base.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/base.py#L204

Added line #L204 was not covered by tests

if not subject_data['bold_boldref']:
task_id = config.execution.task_id
@@ -282,38 +282,38 @@
"""
workflow.__desc__ += func_pre_desc

denoise_within_run = (len(subject_data['bold']) > 1) and not config.workflow.average_over_runs

Check warning on line 285 in src/fmripost_rapidtide/workflows/base.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/base.py#L285

Added line #L285 was not covered by tests
if not denoise_within_run:
# Average the lag map across runs before denoising
merge_lag_maps = pe.Node(

Check warning on line 288 in src/fmripost_rapidtide/workflows/base.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/base.py#L288

Added line #L288 was not covered by tests
niu.Merge(len(subject_data['bold'])),
name='merge_lag_maps',
)
average_lag_map = pe.Node(

Check warning on line 292 in src/fmripost_rapidtide/workflows/base.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/base.py#L292

Added line #L292 was not covered by tests
MeanImage(),
name='average_lag_map',
)

for i_run, bold_file in enumerate(subject_data['bold']):
single_run_wf = init_single_run_wf(bold_file, denoise=denoise_within_run)

Check warning on line 298 in src/fmripost_rapidtide/workflows/base.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/base.py#L298

Added line #L298 was not covered by tests
workflow.add_nodes([single_run_wf])

if not denoise_within_run:
# Denoise the BOLD data using the mean lag map
workflow.connect([

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

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/base.py#L303

Added line #L303 was not covered by tests
(single_run_wf, merge_lag_maps, [('outputnode.delay_map', f'in{i_run + 1}')]),
(merge_lag_maps, average_lag_map, [('out', 'in_file')]),
]) # fmt:skip

denoise_single_run_wf = init_denoise_single_run_wf(bold_file)
workflow.connect([

Check warning on line 309 in src/fmripost_rapidtide/workflows/base.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/base.py#L308-L309

Added lines #L308 - L309 were not covered by tests
(single_run_wf, denoise_single_run_wf, [
('outputnode.regressor', 'inputnode.regressor'),
]),
(average_lag_map, denoise_single_run_wf, [('out_file', 'inputnode.delay_map')]),
]) # fmt:skip

return workflow

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

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/base.py#L316

Added line #L316 was not covered by tests


def init_single_run_wf(bold_file, denoise=True):
@@ -322,11 +322,11 @@
from nipype.interfaces import utility as niu
from niworkflows.engine.workflows import LiterateWorkflow as Workflow

from fmripost_rapidtide.interfaces.misc import ApplyTransforms

Check warning on line 325 in src/fmripost_rapidtide/workflows/base.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/base.py#L325

Added line #L325 was not covered by tests
from fmripost_rapidtide.utils.bids import collect_derivatives, extract_entities
from fmripost_rapidtide.workflows.confounds import init_confounds_wf
from fmripost_rapidtide.workflows.outputs import init_func_fit_reports_wf
from fmripost_rapidtide.workflows.rapidtide import (

Check warning on line 329 in src/fmripost_rapidtide/workflows/base.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/base.py#L329

Added line #L329 was not covered by tests
init_denoise_single_run_wf,
init_rapidtide_wf,
)
@@ -414,13 +414,13 @@
rapidtide_wf.inputs.inputnode.confounds = functional_cache['confounds']
rapidtide_wf.inputs.inputnode.skip_vols = skip_vols

boldref_buffer = pe.Node(

Check warning on line 417 in src/fmripost_rapidtide/workflows/base.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/base.py#L417

Added line #L417 was not covered by tests
niu.IdentityInterface(fields=['bold', 'bold_mask']),
name='boldref_buffer',
)

# Warp the dseg from anatomical space to boldref space
dseg_to_boldref = pe.Node(

Check warning on line 423 in src/fmripost_rapidtide/workflows/base.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/base.py#L423

Added line #L423 was not covered by tests
ApplyTransforms(
interpolation='GenericLabel',
input_image=functional_cache['anat_dseg'],
@@ -465,7 +465,7 @@
else:
workflow.connect([(validate_bold, stc_buffer, [('out_file', 'bold_file')])])

bold_boldref_wf = init_bold_volumetric_resample_wf(

Check warning on line 468 in src/fmripost_rapidtide/workflows/base.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/base.py#L468

Added line #L468 was not covered by tests
metadata=bold_metadata,
fieldmap_id=None, # XXX: Ignoring the field map for now
omp_nthreads=omp_nthreads,
@@ -473,13 +473,13 @@
jacobian='fmap-jacobian' not in config.workflow.ignore,
name='bold_MNI6_wf',
)
bold_boldref_wf.inputs.inputnode.motion_xfm = functional_cache['hmc']
bold_boldref_wf.inputs.inputnode.boldref2fmap_xfm = functional_cache['boldref2fmap']
bold_boldref_wf.inputs.inputnode.resolution = 'native'

Check warning on line 478 in src/fmripost_rapidtide/workflows/base.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/base.py#L476-L478

Added lines #L476 - L478 were not covered by tests
# use mask as boldref?
bold_boldref_wf.inputs.inputnode.bold_ref_file = functional_cache['boldref']
bold_boldref_wf.inputs.inputnode.target_mask = functional_cache['bold_mask_boldref']
bold_boldref_wf.inputs.inputnode.target_ref_file = functional_cache['boldref']

Check warning on line 482 in src/fmripost_rapidtide/workflows/base.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/base.py#L480-L482

Added lines #L480 - L482 were not covered by tests

workflow.connect([
# Resample BOLD to MNI152NLin6Asym, may duplicate bold_std_wf above
@@ -497,8 +497,8 @@
workflow.__desc__ += """\
Preprocessed BOLD series in boldref:res-native space were collected for rapidtide denoising.
"""
boldref_buffer.inputs.bold = functional_cache['bold_boldref']
boldref_buffer.inputs.bold_mask = functional_cache['bold_mask_boldref']

Check warning on line 501 in src/fmripost_rapidtide/workflows/base.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/base.py#L500-L501

Added lines #L500 - L501 were not covered by tests

else:
raise ValueError('No valid BOLD series found for rapidtide denoising.')
@@ -513,8 +513,8 @@

# Denoising workflow
if denoise:
denoise_single_run_wf = init_denoise_single_run_wf(bold_file)
workflow.connect([

Check warning on line 517 in src/fmripost_rapidtide/workflows/base.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/base.py#L516-L517

Added lines #L516 - L517 were not covered by tests
(rapidtide_wf, denoise_single_run_wf, [
('outputnode.regressor', 'inputnode.regressor'),
('outputnode.delay_map', 'inputnode.delay_map'),
@@ -526,7 +526,7 @@
func_fit_reports_wf.inputs.inputnode.source_file = bold_file
func_fit_reports_wf.inputs.inputnode.anat2std_xfm = functional_cache['anat2mni152nlin6asym']
func_fit_reports_wf.inputs.inputnode.anat_dseg = functional_cache['anat_dseg']
workflow.connect([(boldref_buffer, func_fit_reports_wf, [('bold', 'inputnode.bold_mni6')])])

Check warning on line 529 in src/fmripost_rapidtide/workflows/base.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/base.py#L529

Added line #L529 was not covered by tests

# Generate confounds
confounds_wf = init_confounds_wf(
@@ -544,24 +544,20 @@
]),
]) # fmt:skip

return clean_datasinks(workflow, bold_file=bold_file)

Check warning on line 547 in src/fmripost_rapidtide/workflows/base.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/base.py#L547

Added line #L547 was not covered by tests


def _prefix(subid):
return subid if subid.startswith('sub-') else f'sub-{subid}'


def clean_datasinks(workflow: pe.Workflow, bold_file: str) -> pe.Workflow:
"""Overwrite attributes of DataSinks."""
for node in workflow.list_node_names():
node_name = node.split('.')[-1]

Check warning on line 553 in src/fmripost_rapidtide/workflows/base.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/base.py#L553

Added line #L553 was not covered by tests
if node_name.startswith('ds_'):
workflow.get_node(node).interface.out_path_base = ''
workflow.get_node(node).inputs.base_directory = str(config.execution.output_dir)
workflow.get_node(node).inputs.source_file = bold_file

Check warning on line 557 in src/fmripost_rapidtide/workflows/base.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/base.py#L556-L557

Added lines #L556 - L557 were not covered by tests

if node_name.startswith('ds_report_'):
workflow.get_node(node).inputs.datatype = 'figures'

Check warning on line 560 in src/fmripost_rapidtide/workflows/base.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/base.py#L560

Added line #L560 was not covered by tests

return workflow

2 changes: 0 additions & 2 deletions src/fmripost_rapidtide/workflows/rapidtide.py
Original file line number Diff line number Diff line change
@@ -117,8 +117,6 @@
fields=[
'delay_map',
'regressor_file',
'confound_regressed',
'denoised',
],
),
name='outputnode',
@@ -191,7 +189,7 @@
]),
]) # fmt:skip

ds_delay_map = pe.Node(

Check warning on line 192 in src/fmripost_rapidtide/workflows/rapidtide.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/rapidtide.py#L192

Added line #L192 was not covered by tests
DerivativesDataSink(
compress=True,
desc='delay',
@@ -200,7 +198,7 @@
name='ds_delay_map',
run_without_submitting=True,
)
workflow.connect([

Check warning on line 201 in src/fmripost_rapidtide/workflows/rapidtide.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/rapidtide.py#L201

Added line #L201 was not covered by tests
(rapidtide, ds_delay_map, [
('maxtimemap', 'in_file'),
('maxtimemap_json', 'meta_dict'),
@@ -208,7 +206,7 @@
(ds_delay_map, outputnode, [('out_file', 'delay_map')]),
]) # fmt:skip

ds_regressor = pe.Node(

Check warning on line 209 in src/fmripost_rapidtide/workflows/rapidtide.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/rapidtide.py#L209

Added line #L209 was not covered by tests
DerivativesDataSink(
desc='regressor',
suffix='timeseries',
@@ -217,7 +215,7 @@
name='ds_regressor',
run_without_submitting=True,
)
workflow.connect([

Check warning on line 218 in src/fmripost_rapidtide/workflows/rapidtide.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/rapidtide.py#L218

Added line #L218 was not covered by tests
(rapidtide, ds_regressor, [
('lagtcgenerator', 'in_file'),
('lagtcgenerator_json', 'meta_dict'),
@@ -225,7 +223,7 @@
(ds_regressor, outputnode, [('out_file', 'regressor_file')]),
]) # fmt:skip

return workflow

Check warning on line 226 in src/fmripost_rapidtide/workflows/rapidtide.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/rapidtide.py#L226

Added line #L226 was not covered by tests


def init_denoise_single_run_wf(
@@ -236,17 +234,17 @@
):
"""Denoise a single run using rapidtide."""

from niworkflows.engine.workflows import LiterateWorkflow as Workflow

Check warning on line 237 in src/fmripost_rapidtide/workflows/rapidtide.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/rapidtide.py#L237

Added line #L237 was not covered by tests

from fmripost_rapidtide.interfaces.bids import DerivativesDataSink
from fmripost_rapidtide.interfaces.rapidtide import RetroGLM

Check warning on line 240 in src/fmripost_rapidtide/workflows/rapidtide.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/rapidtide.py#L239-L240

Added lines #L239 - L240 were not covered by tests

workflow = Workflow(name=_get_wf_name(bold_file, 'rapidtide_denoise'))
workflow.__postdesc__ = """\

Check warning on line 243 in src/fmripost_rapidtide/workflows/rapidtide.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/rapidtide.py#L242-L243

Added lines #L242 - L243 were not covered by tests
Identification and removal of traveling wave artifacts was performed using rapidtide.
"""

inputnode = pe.Node(

Check warning on line 247 in src/fmripost_rapidtide/workflows/rapidtide.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/rapidtide.py#L247

Added line #L247 was not covered by tests
niu.IdentityInterface(
fields=[
'bold',
@@ -259,11 +257,11 @@
),
name='inputnode',
)
denoise_bold = pe.Node(

Check warning on line 260 in src/fmripost_rapidtide/workflows/rapidtide.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/rapidtide.py#L260

Added line #L260 was not covered by tests
RetroGLM(),
name='denoise_bold',
)
workflow.connect([

Check warning on line 264 in src/fmripost_rapidtide/workflows/rapidtide.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/rapidtide.py#L264

Added line #L264 was not covered by tests
(inputnode, denoise_bold, [
('bold', 'in_file'),
('bold_mask', 'brainmask'),
@@ -274,7 +272,7 @@
]),
]) # fmt:skip

ds_denoised_bold = pe.Node(

Check warning on line 275 in src/fmripost_rapidtide/workflows/rapidtide.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/rapidtide.py#L275

Added line #L275 was not covered by tests
DerivativesDataSink(
compress=True,
desc='denoised',
@@ -283,7 +281,7 @@
name='ds_denoised_bold',
run_without_submitting=True,
)
workflow.connect([

Check warning on line 284 in src/fmripost_rapidtide/workflows/rapidtide.py

Codecov / codecov/patch

src/fmripost_rapidtide/workflows/rapidtide.py#L284

Added line #L284 was not covered by tests
(denoise_bold, ds_denoised_bold, [
('denoised', 'in_file'),
('denoised_json', 'meta_dict'),
Loading