Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ab66ba8
Add first skeleton draft
Nov 11, 2020
5f685eb
add parser
ineschh Nov 12, 2020
2fa576f
Update phys2denoise/cli/run.py
ineschh Nov 12, 2020
6142d30
Update
ineschh Nov 12, 2020
ae489ad
Merge branch 'master' of https://github.com/ineschh/phys2denoise
ineschh Nov 12, 2020
8e521f3
More skeleton
Nov 12, 2020
4c265e3
More updates
ineschh Nov 13, 2020
8bd4b8f
Suggested changes
ineschh Nov 13, 2020
7b950b6
Import metrics
Nov 13, 2020
6090b6f
First skeleton version
Nov 14, 2020
195c369
Remove unused libraries and improve function argument
Nov 14, 2020
298acaf
Input args to metrics using inspect.signature()
Nov 25, 2020
bd340be
Change log path
Nov 25, 2020
cb8b42e
Change inspection of metrics and add a logger function
Nov 25, 2020
9c1bd60
Recognising planning contribution to @62442katieb
Nov 25, 2020
1541149
metric_args into dict
ineschh Nov 26, 2020
636f585
Remove extra "version" imports
Feb 25, 2021
36abfb8
Change metric_args into **kwargs
Feb 25, 2021
46c1e0c
Move metric call log to metrics.utils instead of in the main workflow.
Feb 25, 2021
7c25d9c
Merge branch 'ineschh/master' into enh/skeleton
Feb 25, 2021
44fde8c
Move the bash call saving to a function on its own out of the main wo…
Feb 25, 2021
570619d
Move main workflow in the right place
Feb 25, 2021
3a66afa
Add parser
Feb 25, 2021
5adc4f5
Change call to retroicor into argument selection of type
Feb 25, 2021
6e7f7ee
Revert "Change call to retroicor into argument selection of type"
Feb 25, 2021
76fe437
Better retroicor call
Feb 25, 2021
d767359
Deal better with retroicor outputs
Feb 25, 2021
1ca8780
Remove unused code
Feb 25, 2021
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
195 changes: 195 additions & 0 deletions phys2denoise/cli/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
# -*- coding: utf-8 -*-
"""Parser for phys2denoise."""


import argparse

from phys2denoise import __version__
from phys2denoise.metrics.cardiac import crf
from phys2denoise.metrics.chest_belt import rpv, rv, rvt, rrf, env


def _get_parser():
"""
Parse command line inputs for this function.

Returns
-------
parser.parse_args() : argparse dict

Notes
-----
Default values must be updated in __call__ method from MetricsArgDict class.
# Argument parser follow template provided by RalphyZ.
# https://stackoverflow.com/a/43456577
"""

parser = argparse.ArgumentParser()
optional = parser._action_groups.pop()
required = parser.add_argument_group("Required Argument")
metrics = parser.add_argument_group("Metrics")
metric_arg = parser.add_argument_group("Metrics Arguments")
# Required arguments
required.add_argument("-in", "--input-file",
dest="filename",
type=str,
help="Full path and name of the file containing "
"physiological data, with or without extension.",
required=True)
# Important optional arguments
optional.add_argument("-outdir", "--output-dir",
dest="outdir",
type=str,
help="Folder where output should be placed. "
"Default is current folder.",
default=".")
# Metric selection
metrics.add_argument("-crf", "--cardiac-response-function",
dest="metrics",
action="append_const",
const=crf,
help="Cardiac response function. Requires the following "
"inputs:sample-rate, oversampling, time-length, "
"onset and tr.",
default=[])
metrics.add_argument("-rpv", "--respiratory-pattern-variability",
dest="metrics",
action="append_const",
const=rpv,
help="Respiratory pattern variability. Requires the following "
"input: window.",
default=[])
metrics.add_argument("-env", "--envelope",
dest="metrics",
action="append_const",
const=env,
help="Respiratory pattern variability calculated across a sliding "
"window. Requires the following inputs: sample-rate, window and lags.",
default=[])
metrics.add_argument("-rv", "--respiratory-variance",
dest="metrics",
action="append_const",
const=rv,
help="Respiratory variance. Requires the following inputs: "
"sample-rate, window and lags. If the input file "
"not a .phys file, it also requires peaks and troughs",
default=[])
"""
metrics.add_argument("-rvt", "--respiratory-volume-per-time",
dest="metrics",
action="append_const",
const="rvt",
help="Respiratory volume-per-time. Requires the following inputs: "
"sample-rate, window, lags, peaks and troughs.",
default=[])
"""
metrics.add_argument("-rrf", "--respiratory-response-function",
dest="metrics",
action="append_const",
const=rrf,
help="Respiratory response function. Requires the following inputs: "
"sample-rate, oversampling, time-length, onset and tr.",
default=[])
metrics.add_argument("-rcard", "--retroicor-card",
dest="metrics",
action="append_const",
const="r_card",
help="Computes regressors for cardiac signal. Requires the following "
"inputs: tr, nscans and n_harm.",
default=[])
metrics.add_argument("-rresp", "--retroicor-resp",
dest="metrics",
action="append_const",
const="r_resp",
help="Computes regressors for respiratory signal. Requires the following "
"inputs: tr, nscans and n_harm.",
default=[])
# Metric arguments
metric_arg.add_argument("-sr", "--sample-rate",
dest="sample_rate",
type=float,
help="Sampling rate of the physiological data in Hz.",
default=None)
metric_arg.add_argument("-pk", "--peaks",
dest="peaks",
type=str,
help="Full path and filename of the list with the indexed peaks' "
"positions of the physiological data.",
default=None)
metric_arg.add_argument("-tg", "--troughs",
dest="troughs",
type=str,
help="Full path and filename of the list with the indexed troughs' "
"positions of the physiological data.",
default=None)
metric_arg.add_argument("-os", "--oversampling",
dest="oversampling",
type=int,
help="Temporal oversampling factor. "
"Default is 50.",
default=50)
metric_arg.add_argument("-tl", "--time-length",
dest="time_length",
type=int,
help="RRF or CRF Kernel length in seconds.",
default=None)
metric_arg.add_argument("-onset", "--onset",
dest="onset",
type=float,
help="Onset of the response in seconds. "
"Default is 0.",
default=0)
metric_arg.add_argument("-tr", "--tr",
dest="tr",
type=float,
help="TR of sequence in seconds.",
default=None)
metric_arg.add_argument("-win", "--window",
dest="window",
type=int,
help="Size of the sliding window in seconds. "
"Default is 6 seconds.",
default=6)
metric_arg.add_argument("-lags", "--lags",
dest="lags",
nargs="*",
type=int,
help="List of lags to apply to the RV estimate "
"in seconds.",
default=None)
metric_arg.add_argument("-nscans", "--number-scans",
dest="nscans",
type=int,
help="Number of timepoints in the imaging data. "
"Also called sub-bricks, TRs, scans, volumes."
"Default is 1.",
default=1)
metric_arg.add_argument("-nharm", "--number-harmonics",
dest="n_harm",
type=int,
help="Number of harmonics.",
default=None)

# Other optional arguments
optional.add_argument("-debug", "--debug",
dest="debug",
action="store_true",
help="Only print debugging info to log file. Default is False.",
default=False)
optional.add_argument("-quiet", "--quiet",
dest="quiet",
action="store_true",
help="Only print warnings to log file. Default is False.",
default=False)
optional.add_argument("-v", "--version", action="version",
version=("%(prog)s " + __version__))

parser._action_groups.append(optional)

return parser


if __name__ == "__main__":
raise RuntimeError("phys2denoise/cli/run.py should not be run directly;\n"
"Please `pip install` phys2denoise and use the "
"`phys2denoise` command")
Loading