Skip to content

Commit

Permalink
Update.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsalo committed Sep 3, 2024
1 parent 2734f06 commit 80e7adb
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 113 deletions.
3 changes: 0 additions & 3 deletions env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ dependencies:
# Utilities
- graphviz=9.0
- pandoc=3.1
# Workflow dependencies: FSL (versions pinned in 6.0.7.7)
- fsl-bet2=2111.4
- fsl-miscmaths=2203.2
# Workflow dependencies: ANTs
- ants=2.5
# Other dependencies
Expand Down
4 changes: 2 additions & 2 deletions scripts/fetch_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ def fetch_MNI6():
"""
template = 'MNI152NLin6Asym'

tf.get(template, resolution=(1, 2), desc=None, suffix='T1w')
tf.get(template, resolution=(1, 2), desc=[None, 'brain'], suffix='T1w')
tf.get(template, resolution=(1, 2), desc='brain', suffix='mask')
# CIFTI
tf.get(template, resolution=2, atlas='HCP', suffix='dseg')
# tf.get(template, resolution=2, atlas='HCP', suffix='dseg')
# Transform from MNI152NLin2009cAsym to MNI152NLin6Asym
tf.get(
template, mode='image', suffix='xfm', extension='.h5', **{'from': 'MNI152NLin2009cAsym'}
Expand Down
22 changes: 11 additions & 11 deletions src/fmripost_rapidtide/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def _bids_filter(value, parser):
)
filt_opts.add_argument(
'--filterfreqs',
dest='passvec',
dest='filterfreqs',
action='store',
nargs=2,
type=float,
Expand All @@ -249,7 +249,7 @@ def _bids_filter(value, parser):
)
filt_opts.add_argument(
'--filterstopfreqs',
dest='stopvec',
dest='filterstopfreqs',
action='store',
nargs=2,
type=float,
Expand All @@ -266,7 +266,7 @@ def _bids_filter(value, parser):
sigcalc_opts = g_rapidtide.add_argument_group('Significance calculation options')
sigcalc_opts.add_argument(
'--numnull',
dest='numestreps',
dest='numnull',
action='store',
type=int,
metavar='NREPS',
Expand All @@ -288,7 +288,7 @@ def _bids_filter(value, parser):
)
preproc.add_argument(
'--spatialfilt',
dest='gausssigma',
dest='spatialfilt',
action='store',
type=float,
metavar='GAUSSSIGMA',
Expand All @@ -302,7 +302,7 @@ def _bids_filter(value, parser):
)
preproc.add_argument(
'--confoundfile',
dest='confoundfilespec',
dest='confoundfile',
metavar='CONFFILE',
help=(
'Read additional (non-motion) confound regressors out of CONFFILE file '
Expand All @@ -314,15 +314,15 @@ def _bids_filter(value, parser):
)
preproc.add_argument(
'--confoundpowers',
dest='confound_power',
dest='confoundpowers',
metavar='N',
type=int,
help='Include powers of each confound regressor up to order N.',
default=1,
)
preproc.add_argument(
'--confoundderiv',
dest='confound_deriv',
dest='confoundderiv',
action='store_false',
help='Toggle whether derivatives will be used in confound regression.',
default=True,
Expand Down Expand Up @@ -433,7 +433,7 @@ def _bids_filter(value, parser):
fixdelay = corr_fit.add_mutually_exclusive_group()
fixdelay.add_argument(
'--fixdelay',
dest='fixeddelayvalue',
dest='fixdelay',
action='store',
type=float,
metavar='DELAYTIME',
Expand All @@ -442,7 +442,7 @@ def _bids_filter(value, parser):
)
fixdelay.add_argument(
'--searchrange',
dest='lag_extrema',
dest='searchrange',
action=IndicateSpecifiedAction,
nargs=2,
type=float,
Expand All @@ -452,7 +452,7 @@ def _bids_filter(value, parser):
)
corr_fit.add_argument(
'--sigmalimit',
dest='widthmax',
dest='sigmalimit',
action='store',
type=float,
metavar='SIGMALIMIT',
Expand Down Expand Up @@ -620,7 +620,7 @@ def _bids_filter(value, parser):
)
experimental.add_argument(
'--autorespdelete',
dest='respdelete',
dest='autorespdelete',
action='store_true',
help='Attempt to detect and remove respiratory signal that strays into the LFO band.',
default=False,
Expand Down
22 changes: 11 additions & 11 deletions src/fmripost_rapidtide/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,21 +544,21 @@ class workflow(_Config):
crosscorrelation."""
filterband = None
"""Filter data and regressors to specific band. Use "None" to disable filtering."""
passvec = None
filterfreqs = None
"""Filter data and regressors to retain LOWERPASS to UPPERPASS."""
stopvec = None
filterstopfreqs = None
"""Filter data and regressors to with stop frequencies LOWERSTOP and UPPERSTOP."""
numestreps = None
numnull = None
"""Estimate significance threshold by running NREPS null correlations."""
detrendorder = None
"""Set order of trend removal (0 to disable)."""
gausssigma = None
spatialfilt = None
"""Spatially filter fMRI data prior to analysis using GAUSSSIGMA in mm."""
confoundfilespec = None
confoundfile = None
"""Read additional (non-motion) confound regressors out of CONFFILE file."""
confound_power = None
confoundpowers = None
"""Include powers of each confound regressor up to order N."""
confound_deriv = None
confoundderiv = None
"""Toggle whether derivatives will be used in confound regression."""
globalsignalmethod = None
"""The method for constructing the initial global signal regressor - straight summation."""
Expand All @@ -573,11 +573,11 @@ class workflow(_Config):
"""Method to use for cross-correlation weighting."""
simcalcrange = None
"""Limit correlation calculation to data between timepoints START and END in the fmri file."""
fixeddelayvalue = None
fixdelay = None
"""Don't fit the delay time - set it to DELAYTIME seconds for all voxels."""
lag_extrema = None
searchrange = None
"""Limit fit to a range of lags from LAGMIN to LAGMAX."""
widthmax = None
sigmalimit = None
"""Reject lag fits with linewidth wider than SIGMALIMIT Hz."""
bipolar = None
"""Bipolar mode - match peak correlation ignoring sign."""
Expand Down Expand Up @@ -605,7 +605,7 @@ class workflow(_Config):
territorymap = None
"""This specifies a territory map. Each territory is a set of voxels with the same integral
value."""
respdelete = None
autorespdelete = None
"""Attempt to detect and remove respiratory signal that strays into the LFO band."""
err_on_warn = False
"""Cast Rapidtide warnings to errors."""
Expand Down
38 changes: 27 additions & 11 deletions src/fmripost_rapidtide/data/io_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,6 @@
".nii"
]
},
"dseg": {
"datatype": "anat",
"res": "2",
"space": "MNI152NLin6Asym",
"desc": null,
"suffix": "dseg",
"extension": [
".nii.gz",
".nii"
]
},
"confounds": {
"datatype": "func",
"echo": null,
Expand All @@ -89,6 +78,33 @@
"extension": [
".tsv"
]
},
"dseg_mni152nlin6asym": {
"datatype": "anat",
"task": null,
"run": null,
"res": "2",
"space": "MNI152NLin6Asym",
"desc": null,
"suffix": "dseg",
"extension": [
".nii.gz",
".nii"
]
},
"anat_dseg": {
"datatype": "anat",
"task": null,
"run": null,
"space": null,
"res": null,
"den": null,
"desc": null,
"suffix": "dseg",
"extension": [
".nii.gz",
".nii"
]
}
},
"transforms": {
Expand Down
16 changes: 12 additions & 4 deletions src/fmripost_rapidtide/interfaces/nilearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class _MeanImageInputSpec(BaseInterfaceInputSpec):
)
mask_file = File(
exists=True,
mandatory=True,
mandatory=False,
desc='A binary brain mask.',
)
out_file = File(
Expand All @@ -44,11 +44,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'])

Expand Down
24 changes: 17 additions & 7 deletions src/fmripost_rapidtide/interfaces/rapidtide.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ class _RapidtideInputSpec(CommandLineInputSpec):
in_file = File(
exists=True,
argstr='%s',
position=-1,
position=-2,
mandatory=True,
desc='File to denoise',
)
outputname = traits.Str(
argstr='%s',
position=-1,
mandatory=True,
desc='Output name',
)
# Set by the workflow
denoising = traits.Bool(
argstr='--denoising',
Expand Down Expand Up @@ -151,7 +157,7 @@ class _RapidtideInputSpec(CommandLineInputSpec):
mandatory=False,
)
timerange = traits.List(
traits.Float,
traits.Int,
argstr='--timerange %s',
mandatory=False,
minlen=2,
Expand All @@ -166,7 +172,7 @@ class _RapidtideInputSpec(CommandLineInputSpec):
mandatory=False,
)
simcalcrange = traits.List(
traits.Float,
traits.Int,
argstr='--simcalcrange %s',
mandatory=False,
minlen=2,
Expand All @@ -177,7 +183,7 @@ class _RapidtideInputSpec(CommandLineInputSpec):
mandatory=False,
)
searchrange = traits.List(
traits.Float,
traits.Int,
argstr='--searchrange %s',
mandatory=False,
minlen=2,
Expand Down Expand Up @@ -264,10 +270,14 @@ class Rapidtide(CommandLine):
def _list_outputs(self):
outputs = self._outputs().get()
out_dir = os.getcwd()
outputs['delay_map'] = os.path.join(out_dir, 'desc-maxtime_map.nii.gz')
outputname = self.inputs.outputname
outputs['delay_map'] = os.path.join(out_dir, f'{outputname}_desc-maxtime_map.nii.gz')
outputs['regressor_file'] = os.path.join(
out_dir,
'desc-refinedmovingregressor_timeseries.tsv.gz',
f'{outputname}_desc-refinedmovingregressor_timeseries.tsv.gz',
)
outputs['denoised'] = os.path.join(
out_dir,
f'{outputname}_desc-lfofilterCleaned_bold.nii.gz'
)
outputs['denoised'] = os.path.join(out_dir, 'desc-lfofilterCleaned_bold.nii.gz')
return outputs
3 changes: 3 additions & 0 deletions src/fmripost_rapidtide/workflows/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ def init_single_run_wf(bold_file):
# Run rapidtide
rapidtide_wf = init_rapidtide_wf(bold_file=bold_file, metadata=bold_metadata, mem_gb=mem_gb)
rapidtide_wf.inputs.inputnode.confounds = functional_cache['confounds']
rapidtide_wf.inputs.inputnode.dseg_std = functional_cache['dseg_mni152nlin6asym']
rapidtide_wf.inputs.inputnode.skip_vols = skip_vols

mni6_buffer = pe.Node(niu.IdentityInterface(fields=['bold', 'bold_mask']), name='mni6_buffer')
Expand All @@ -395,6 +396,8 @@ def init_single_run_wf(bold_file):
from niworkflows.interfaces.header import ValidateImage
from templateflow.api import get as get_template

raise Exception()

workflow.__desc__ += """\
Raw BOLD series were resampled to MNI152NLin6Asym:res-2, for rapidtide denoising.
"""
Expand Down
Loading

0 comments on commit 80e7adb

Please sign in to comment.