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
Work on rapidtide interfaces.
tsalo committed Sep 26, 2024
commit 4df6124f7c8fda4c757908a49eaf88fd32c48e9d
155 changes: 138 additions & 17 deletions src/fmripost_rapidtide/interfaces/rapidtide.py
Original file line number Diff line number Diff line change
@@ -6,16 +6,12 @@
from nipype.interfaces.base import (
CommandLine,
CommandLineInputSpec,
DynamicTraitedSpec,
File,
TraitedSpec,
traits,
)

from fmripost_rapidtide.data import load as load_data

with open(load_data('rapidtide_spec.yml')) as f:
rapidtide_output_spec = yaml.safe_load(f)


class _RapidtideInputSpec(CommandLineInputSpec):
in_file = File(
@@ -25,10 +21,11 @@
mandatory=True,
desc='File to denoise',
)
outputname = traits.Str(
prefix = traits.Str(
argstr='%s',
position=-1,
mandatory=True,
mandatory=False,
genfile=True,
desc='Output name',
)
# Set by the workflow
@@ -267,11 +264,10 @@


class _RapidtideOutputSpec(TraitedSpec):
pass


for name in rapidtide_output_spec.keys():
_RapidtideOutputSpec.add_class_trait(name, File)
prefix = traits.Str(desc='Directory containing the results, with prefix.')
lagtimesfile = File(exists=True, desc='3D map of optimal delay times')
lagtcgeneratorfile = File(exists=True, desc='Time series of refined regressor')
maskfile = File(exists=True, desc='Mask file (usually called XXX_desc-corrfit_mask.nii.gz)')


class Rapidtide(CommandLine):
@@ -281,24 +277,149 @@
input_spec = _RapidtideInputSpec
output_spec = _RapidtideOutputSpec

def _gen_filename(self, name):
if name == 'prefix':
return os.path.join(os.getcwd(), 'rapidtide')

Check warning on line 282 in src/fmripost_rapidtide/interfaces/rapidtide.py

Codecov / codecov/patch

src/fmripost_rapidtide/interfaces/rapidtide.py#L282

Added line #L282 was not covered by tests

return None

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

Codecov / codecov/patch

src/fmripost_rapidtide/interfaces/rapidtide.py#L284

Added line #L284 was not covered by tests

def _list_outputs(self):
outputs = self._outputs().get()
out_dir = os.getcwd()
outputname = self.inputs.outputname
for name, spec in rapidtide_output_spec.items():
outputs[name] = os.path.join(out_dir, f'{outputname}_{spec["filename"]}')
prefix = self.inputs.prefix
outputs['prefix'] = prefix
outputs['lagtimesfile'] = f'{prefix}_desc-maxtime_map.nii.gz'
outputs['lagtcgeneratorfile'] = f'{prefix}_desc-lagtcgenerator_timeseries.tsv.gz'
outputs['maskfile'] = f'{prefix}_desc-corrfit_mask.nii.gz'

Check warning on line 292 in src/fmripost_rapidtide/interfaces/rapidtide.py

Codecov / codecov/patch

src/fmripost_rapidtide/interfaces/rapidtide.py#L287-L292

Added lines #L287 - L292 were not covered by tests

return outputs

Check warning on line 294 in src/fmripost_rapidtide/interfaces/rapidtide.py

Codecov / codecov/patch

src/fmripost_rapidtide/interfaces/rapidtide.py#L294

Added line #L294 was not covered by tests


class _RetroLagTCSInputSpec(CommandLineInputSpec):
in_file = File(
exists=True,
argstr='%s',
position=0,
mandatory=True,
desc='The name of 4D nifti fmri target file.',
)
maskfile = File(
exists=True,
argstr='%s',
position=1,
mandatory=True,
desc='The mask file to use (usually called XXX_desc-corrfit_mask.nii.gz)',
)
lagtimesfile = File(
exists=True,
argstr='%s',
position=2,
mandatory=True,
desc='The name of the lag times file (usually called XXX_desc-maxtime_map.nii.gz)',
)
lagtcgeneratorfile = File(
exists=True,
argstr='%s',
position=3,
mandatory=True,
desc=(
'The root name of the lagtc generator file '
'(usually called XXX_desc-lagtcgenerator_timeseries)'
),
)
prefix = traits.Str(
argstr='%s',
position=4,
mandatory=False,
genfile=True,
desc='Output root.',
)
glmderivs = traits.Int(
argstr='--glmderivs %d',
mandatory=False,
desc='When doing final GLM, include derivatives up to NDERIVS order. Default is 0.',
default=0,
usedefault=True,
)
nprocs = traits.Int(
default=1,
usedefault=True,
argstr='--nprocs %d',
mandatory=False,
desc=(
'Use NPROCS worker processes for multiprocessing. '
'Setting NPROCS to less than 1 sets the number of worker processes to n_cpus.'
),
)
numskip = traits.Int(
argstr='--numskip %d',
default=0,
usedefault=True,
mandatory=False,
desc='Skip NUMSKIP points at the beginning of the fmri file.',
)
noprogressbar = traits.Bool(
argstr='--noprogressbar',
mandatory=False,
default=True,
usedefault=True,
desc='Will disable showing progress bars (helpful if stdout is going to a file).',
)
debug = traits.Bool(
argstr='--debug',
mandatory=False,
default=False,
usedefault=True,
desc='Output lots of helpful information.',
)


class _RetroLagTCSOutputSpec(DynamicTraitedSpec):
filter_file = File(exists=True, desc='Filter file')


class RetroLagTCS(CommandLine):
"""Run the retrolagtcs command-line interface."""

_cmd = 'retrolagtcs'
input_spec = _RetroLagTCSInputSpec
output_spec = _RetroLagTCSOutputSpec

def _gen_filename(self, name):
if name == 'prefix':
return os.path.join(os.getcwd(), 'retrolagtcs')

Check warning on line 389 in src/fmripost_rapidtide/interfaces/rapidtide.py

Codecov / codecov/patch

src/fmripost_rapidtide/interfaces/rapidtide.py#L389

Added line #L389 was not covered by tests

return None

Check warning on line 391 in src/fmripost_rapidtide/interfaces/rapidtide.py

Codecov / codecov/patch

src/fmripost_rapidtide/interfaces/rapidtide.py#L391

Added line #L391 was not covered by tests

def _list_outputs(self):
outputs = self._outputs().get()
prefix = self.inputs.prefix
outputs['filter_file'] = f'{prefix}_desc-lfofilterEV_bold.nii.gz'

Check warning on line 396 in src/fmripost_rapidtide/interfaces/rapidtide.py

Codecov / codecov/patch

src/fmripost_rapidtide/interfaces/rapidtide.py#L394-L396

Added lines #L394 - L396 were not covered by tests
if self.inputs.glmderivs > 0:
for i_deriv in range(self.inputs.glmderivs):
outputs[f'filter_file_deriv{i_deriv + 1}'] = (

Check warning on line 399 in src/fmripost_rapidtide/interfaces/rapidtide.py

Codecov / codecov/patch

src/fmripost_rapidtide/interfaces/rapidtide.py#L399

Added line #L399 was not covered by tests
f'{prefix}_desc-lfofilterEVDeriv{i_deriv + 1}_bold.nii.gz'
)

return outputs

Check warning on line 403 in src/fmripost_rapidtide/interfaces/rapidtide.py

Codecov / codecov/patch

src/fmripost_rapidtide/interfaces/rapidtide.py#L403

Added line #L403 was not covered by tests


class _RetroGLMInputSpec(CommandLineInputSpec):
in_file = File(
exists=True,
argstr='%s',
position=-1,
position=0,
mandatory=True,
desc='File to denoise',
)
datafileroot = traits.Str(
argstr='%s',
position=1,
mandatory=True,
desc=(
'The root name of the previously run rapidtide dataset '
'(everything up to but not including the underscore.)'
),
)
runoptionsfile = File(
exists=True,
argstr='--runoptionsfile %s',
Loading