Skip to content

Commit ad51a00

Browse files
author
Stefano Moia
authored
Merge pull request #17 from smoia/enh/skeleton
Add main workflow of phys2denoise Merging by agreement.
2 parents 9233348 + 1ca8780 commit ad51a00

2 files changed

Lines changed: 425 additions & 0 deletions

File tree

phys2denoise/cli/run.py

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
# -*- coding: utf-8 -*-
2+
"""Parser for phys2denoise."""
3+
4+
5+
import argparse
6+
7+
from phys2denoise import __version__
8+
from phys2denoise.metrics.cardiac import crf
9+
from phys2denoise.metrics.chest_belt import rpv, rv, rvt, rrf, env
10+
11+
12+
def _get_parser():
13+
"""
14+
Parse command line inputs for this function.
15+
16+
Returns
17+
-------
18+
parser.parse_args() : argparse dict
19+
20+
Notes
21+
-----
22+
Default values must be updated in __call__ method from MetricsArgDict class.
23+
# Argument parser follow template provided by RalphyZ.
24+
# https://stackoverflow.com/a/43456577
25+
"""
26+
27+
parser = argparse.ArgumentParser()
28+
optional = parser._action_groups.pop()
29+
required = parser.add_argument_group("Required Argument")
30+
metrics = parser.add_argument_group("Metrics")
31+
metric_arg = parser.add_argument_group("Metrics Arguments")
32+
# Required arguments
33+
required.add_argument("-in", "--input-file",
34+
dest="filename",
35+
type=str,
36+
help="Full path and name of the file containing "
37+
"physiological data, with or without extension.",
38+
required=True)
39+
# Important optional arguments
40+
optional.add_argument("-outdir", "--output-dir",
41+
dest="outdir",
42+
type=str,
43+
help="Folder where output should be placed. "
44+
"Default is current folder.",
45+
default=".")
46+
# Metric selection
47+
metrics.add_argument("-crf", "--cardiac-response-function",
48+
dest="metrics",
49+
action="append_const",
50+
const=crf,
51+
help="Cardiac response function. Requires the following "
52+
"inputs:sample-rate, oversampling, time-length, "
53+
"onset and tr.",
54+
default=[])
55+
metrics.add_argument("-rpv", "--respiratory-pattern-variability",
56+
dest="metrics",
57+
action="append_const",
58+
const=rpv,
59+
help="Respiratory pattern variability. Requires the following "
60+
"input: window.",
61+
default=[])
62+
metrics.add_argument("-env", "--envelope",
63+
dest="metrics",
64+
action="append_const",
65+
const=env,
66+
help="Respiratory pattern variability calculated across a sliding "
67+
"window. Requires the following inputs: sample-rate, window and lags.",
68+
default=[])
69+
metrics.add_argument("-rv", "--respiratory-variance",
70+
dest="metrics",
71+
action="append_const",
72+
const=rv,
73+
help="Respiratory variance. Requires the following inputs: "
74+
"sample-rate, window and lags. If the input file "
75+
"not a .phys file, it also requires peaks and troughs",
76+
default=[])
77+
"""
78+
metrics.add_argument("-rvt", "--respiratory-volume-per-time",
79+
dest="metrics",
80+
action="append_const",
81+
const="rvt",
82+
help="Respiratory volume-per-time. Requires the following inputs: "
83+
"sample-rate, window, lags, peaks and troughs.",
84+
default=[])
85+
"""
86+
metrics.add_argument("-rrf", "--respiratory-response-function",
87+
dest="metrics",
88+
action="append_const",
89+
const=rrf,
90+
help="Respiratory response function. Requires the following inputs: "
91+
"sample-rate, oversampling, time-length, onset and tr.",
92+
default=[])
93+
metrics.add_argument("-rcard", "--retroicor-card",
94+
dest="metrics",
95+
action="append_const",
96+
const="r_card",
97+
help="Computes regressors for cardiac signal. Requires the following "
98+
"inputs: tr, nscans and n_harm.",
99+
default=[])
100+
metrics.add_argument("-rresp", "--retroicor-resp",
101+
dest="metrics",
102+
action="append_const",
103+
const="r_resp",
104+
help="Computes regressors for respiratory signal. Requires the following "
105+
"inputs: tr, nscans and n_harm.",
106+
default=[])
107+
# Metric arguments
108+
metric_arg.add_argument("-sr", "--sample-rate",
109+
dest="sample_rate",
110+
type=float,
111+
help="Sampling rate of the physiological data in Hz.",
112+
default=None)
113+
metric_arg.add_argument("-pk", "--peaks",
114+
dest="peaks",
115+
type=str,
116+
help="Full path and filename of the list with the indexed peaks' "
117+
"positions of the physiological data.",
118+
default=None)
119+
metric_arg.add_argument("-tg", "--troughs",
120+
dest="troughs",
121+
type=str,
122+
help="Full path and filename of the list with the indexed troughs' "
123+
"positions of the physiological data.",
124+
default=None)
125+
metric_arg.add_argument("-os", "--oversampling",
126+
dest="oversampling",
127+
type=int,
128+
help="Temporal oversampling factor. "
129+
"Default is 50.",
130+
default=50)
131+
metric_arg.add_argument("-tl", "--time-length",
132+
dest="time_length",
133+
type=int,
134+
help="RRF or CRF Kernel length in seconds.",
135+
default=None)
136+
metric_arg.add_argument("-onset", "--onset",
137+
dest="onset",
138+
type=float,
139+
help="Onset of the response in seconds. "
140+
"Default is 0.",
141+
default=0)
142+
metric_arg.add_argument("-tr", "--tr",
143+
dest="tr",
144+
type=float,
145+
help="TR of sequence in seconds.",
146+
default=None)
147+
metric_arg.add_argument("-win", "--window",
148+
dest="window",
149+
type=int,
150+
help="Size of the sliding window in seconds. "
151+
"Default is 6 seconds.",
152+
default=6)
153+
metric_arg.add_argument("-lags", "--lags",
154+
dest="lags",
155+
nargs="*",
156+
type=int,
157+
help="List of lags to apply to the RV estimate "
158+
"in seconds.",
159+
default=None)
160+
metric_arg.add_argument("-nscans", "--number-scans",
161+
dest="nscans",
162+
type=int,
163+
help="Number of timepoints in the imaging data. "
164+
"Also called sub-bricks, TRs, scans, volumes."
165+
"Default is 1.",
166+
default=1)
167+
metric_arg.add_argument("-nharm", "--number-harmonics",
168+
dest="n_harm",
169+
type=int,
170+
help="Number of harmonics.",
171+
default=None)
172+
173+
# Other optional arguments
174+
optional.add_argument("-debug", "--debug",
175+
dest="debug",
176+
action="store_true",
177+
help="Only print debugging info to log file. Default is False.",
178+
default=False)
179+
optional.add_argument("-quiet", "--quiet",
180+
dest="quiet",
181+
action="store_true",
182+
help="Only print warnings to log file. Default is False.",
183+
default=False)
184+
optional.add_argument("-v", "--version", action="version",
185+
version=("%(prog)s " + __version__))
186+
187+
parser._action_groups.append(optional)
188+
189+
return parser
190+
191+
192+
if __name__ == "__main__":
193+
raise RuntimeError("phys2denoise/cli/run.py should not be run directly;\n"
194+
"Please `pip install` phys2denoise and use the "
195+
"`phys2denoise` command")

0 commit comments

Comments
 (0)