Skip to content

Commit

Permalink
Merge pull request #993 from nipreps/fix/965
Browse files Browse the repository at this point in the history
ENH: Deprecate ``--start-idx`` / ``--stop-idx``
  • Loading branch information
oesteban committed May 2, 2022
2 parents e5cdc5a + 32889ab commit cb0c660
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 62 deletions.
16 changes: 11 additions & 5 deletions mriqc/cli/parser.py
Expand Up @@ -29,7 +29,8 @@
def _build_parser():
"""Build parser object."""
import sys
from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser
import warnings
from argparse import Action, ArgumentDefaultsHelpFormatter, ArgumentParser
from functools import partial
from pathlib import Path
from shutil import which
Expand All @@ -38,6 +39,11 @@ def _build_parser():

from .version import check_latest, is_flagged

class DeprecateAction(Action):
def __call__(self, parser, namespace, values, option_string=None):
warnings.warn(f"Argument {option_string} is deprecated and is *ignored*.")
delattr(namespace, self.dest)

def _path_exists(path, parser):
"""Ensure a given path exists."""
if path is None or not Path(path).exists():
Expand Down Expand Up @@ -379,16 +385,16 @@ def _bids_filter(value):
)
g_func.add_argument(
"--start-idx",
action="store",
action=DeprecateAction,
type=int,
help="Initial volume in functional timeseries that should be "
help="DEPRECATED Initial volume in functional timeseries that should be "
"considered for preprocessing.",
)
g_func.add_argument(
"--stop-idx",
action="store",
action=DeprecateAction,
type=int,
help="Final volume in functional timeseries that should be "
help="DEPRECATED Final volume in functional timeseries that should be "
"considered for preprocessing.",
)
g_func.add_argument(
Expand Down
4 changes: 0 additions & 4 deletions mriqc/config.py
Expand Up @@ -507,10 +507,6 @@ class workflow(_Config):
"""Run ICA on the raw data and include the components in the individual reports."""
inputs = None
"""List of files to be processed with MRIQC."""
start_idx = None
"""Initial volume in functional timeseries that should be considered for preprocessing."""
stop_idx = None
"""Final volume in functional timeseries that should be considered for preprocessing."""
species = "human"
"""Subject species to choose most appropriate template"""
template_id = "MNI152NLin2009cAsym"
Expand Down
42 changes: 10 additions & 32 deletions mriqc/workflows/functional.py
Expand Up @@ -676,43 +676,21 @@ def hmc(name="fMRI_HMC"):
"""
from nipype.algorithms.confounds import FramewiseDisplacement
from nipype.interfaces.afni import Calc, Despike, Refit, TShift, Volreg
from nipype.interfaces.afni import Despike, Refit, TShift, Volreg

mem_gb = config.workflow.biggest_file_gb

workflow = pe.Workflow(name=name)

inputnode = pe.Node(
niu.IdentityInterface(fields=["in_file", "fd_radius", "start_idx", "stop_idx"]),
niu.IdentityInterface(fields=["in_file", "fd_radius"]),
name="inputnode",
)

outputnode = pe.Node(
niu.IdentityInterface(fields=["out_file", "out_fd"]), name="outputnode"
)

if any(
(
config.workflow.start_idx is not None,
config.workflow.stop_idx is not None,
)
):
drop_trs = pe.Node(Calc(expr="a", outputtype="NIFTI_GZ"), name="drop_trs")
# fmt: off
workflow.connect([
(inputnode, drop_trs, [("in_file", "in_file_a"),
("start_idx", "start_idx"),
("stop_idx", "stop_idx")]),
])
# fmt: on
else:
drop_trs = pe.Node(niu.IdentityInterface(fields=["out_file"]), name="drop_trs")
# fmt: off
workflow.connect([
(inputnode, drop_trs, [("in_file", "out_file")]),
])
# fmt: on

# calculate hmc parameters
hmc = pe.Node(
Volreg(args="-Fourier -twopass", zpad=4, outputtype="NIFTI_GZ"),
Expand Down Expand Up @@ -753,7 +731,7 @@ def hmc(name="fMRI_HMC"):

# fmt: off
workflow.connect([
(drop_trs, st_corr, [("out_file", "in_file")]),
(inputnode, st_corr, [("in_file", "in_file")]),
(st_corr, despike_node, [("out_file", "in_file")]),
(despike_node, deoblique_node, [("out_file", "in_file")]),
(deoblique_node, hmc, [("out_file", "in_file")]),
Expand All @@ -762,52 +740,52 @@ def hmc(name="fMRI_HMC"):
elif config.workflow.correct_slice_timing and config.workflow.despike:
# fmt: off
workflow.connect([
(drop_trs, st_corr, [("out_file", "in_file")]),
(inputnode, st_corr, [("in_file", "in_file")]),
(st_corr, despike_node, [("out_file", "in_file")]),
(despike_node, hmc, [("out_file", "in_file")]),
])
# fmt: on
elif config.workflow.correct_slice_timing and config.workflow.deoblique:
# fmt: off
workflow.connect([
(drop_trs, st_corr, [("out_file", "in_file")]),
(inputnode, st_corr, [("in_file", "in_file")]),
(st_corr, deoblique_node, [("out_file", "in_file")]),
(deoblique_node, hmc, [("out_file", "in_file")]),
])
# fmt: on
elif config.workflow.correct_slice_timing:
# fmt: off
workflow.connect([
(drop_trs, st_corr, [("out_file", "in_file")]),
(inputnode, st_corr, [("in_file", "in_file")]),
(st_corr, hmc, [("out_file", "in_file")]),
])
# fmt: on
elif config.workflow.despike and config.workflow.deoblique:
# fmt: off
workflow.connect([
(drop_trs, despike_node, [("out_file", "in_file")]),
(inputnode, despike_node, [("in_file", "in_file")]),
(despike_node, deoblique_node, [("out_file", "in_file")]),
(deoblique_node, hmc, [("out_file", "in_file")]),
])
# fmt: on
elif config.workflow.despike:
# fmt: off
workflow.connect([
(drop_trs, despike_node, [("out_file", "in_file")]),
(inputnode, despike_node, [("in_file", "in_file")]),
(despike_node, hmc, [("out_file", "in_file")]),
])
# fmt: on
elif config.workflow.deoblique:
# fmt: off
workflow.connect([
(drop_trs, deoblique_node, [("out_file", "in_file")]),
(inputnode, deoblique_node, [("in_file", "in_file")]),
(deoblique_node, hmc, [("out_file", "in_file")]),
])
# fmt: on
else:
# fmt: off
workflow.connect([
(drop_trs, hmc, [("out_file", "in_file")]),
(inputnode, hmc, [("in_file", "in_file")]),
])
# fmt: on
return workflow
Expand Down
21 changes: 0 additions & 21 deletions mriqc/workflows/utils.py
Expand Up @@ -32,27 +32,6 @@ def _tofloat(inlist):
return float(inlist)


def fmri_getidx(in_file, start_idx, stop_idx):
"""Heuristics to set the start and stop indices of fMRI series"""
from nibabel import load
from nipype.interfaces.base import isdefined

nvols = load(in_file).shape[3]
max_idx = nvols - 1

if (
start_idx is None
or not isdefined(start_idx)
or start_idx < 0
or start_idx > max_idx
):
start_idx = 0

if stop_idx is None or not isdefined(stop_idx) or max_idx < stop_idx < start_idx:
stop_idx = max_idx
return start_idx, stop_idx


def fwhm_dict(fwhm):
"""Convert a list of FWHM into a dictionary"""
fwhm = [float(f) for f in fwhm]
Expand Down

0 comments on commit cb0c660

Please sign in to comment.