forked from cpp-lln-lab/bidsMReye
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_parsers.py
More file actions
249 lines (225 loc) · 7 KB
/
_parsers.py
File metadata and controls
249 lines (225 loc) · 7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
from __future__ import annotations
from argparse import ArgumentParser, HelpFormatter
from pathlib import Path
from bidsmreye._version import __version__
from bidsmreye.defaults import available_models, default_model
def _base_parser(formatter_class: type[HelpFormatter] = HelpFormatter) -> ArgumentParser:
parser = ArgumentParser(
description=(
"BIDS app using deepMReye to decode eye motion for fMRI time series data."
),
epilog="""
For a more readable version of this help section,
see the online https://bidsmreye.readthedocs.io/.
""",
formatter_class=formatter_class,
)
parser.add_argument(
"--version",
action="version",
help="show program's version number and exit",
version=f"\nbidsMReye version {__version__}\n",
)
parser.add_argument(
"bids_dir",
help="""
Fullpath to the directory with the input dataset
formatted according to the BIDS standard.
The dataset should contain 'minimally processed'
(meaning at least 'realigned').
The output of fMRIprep or bidspm should be acceptable inputs.
For "qc", this lust be the fullpath to the directory
with the output generated by bidsmreye
that should be quality controlled.
""",
nargs=1,
)
parser.add_argument(
"output_dir",
help="""
Fullpath to the directory where the output files will be stored.
""",
nargs=1,
)
parser.add_argument(
"analysis_level",
help="""
Level of the analysis that will be performed.
Multiple participant level analyses can be run independently
(in parallel) using the same ``output_dir``.
""",
choices=["participant", "group"],
default="participant",
type=str,
nargs=1,
)
return parser
def _add_common_arguments(parser: ArgumentParser) -> ArgumentParser:
parser.add_argument(
"--participant_label",
help="""
The label(s) of the participant(s) that should be analyzed.
The label corresponds to sub-<participant_label> from the BIDS spec
(so it does not include "sub-").
If this parameter is not provided, all subjects will be analyzed.
Multiple participants can be specified with a space separated list.
""",
nargs="+",
)
parser.add_argument(
"--task",
help="""
The label of the task that will be analyzed.
The label corresponds to task-<task_label> from the BIDS spec
so it does not include "task-").
""",
nargs="+",
)
parser.add_argument(
"--run",
help="""
The label of the run that will be analyzed.
The label corresponds to run-<task_label> from the BIDS spec
so it does not include "run-").
""",
nargs="+",
)
parser.add_argument(
"--space",
help="""
The label of the space that will be analyzed.
The label corresponds to space-<space_label> from the BIDS spec
(so it does not include "space-").
""",
nargs="+",
)
parser.add_argument(
"-v",
"--verbose",
dest="log_level",
action="append_const",
const=-1,
)
parser.add_argument("--debug", help="Switch to debug mode", action="store_true")
parser.add_argument(
"--reset_database",
help="""
Resets the database of the input dataset.
""",
action="store_true",
)
parser.add_argument(
"--bids_filter_file",
help="""
A JSON file describing custom BIDS input filters using PyBIDS.
For further details, please check out TBD.
""",
)
parser.add_argument(
"--force",
help="""
Overwrite previous output.
""",
action="store_true",
)
return parser
def common_parser(formatter_class: type[HelpFormatter] = HelpFormatter) -> ArgumentParser:
"""Execute the main script."""
parser = _base_parser(formatter_class=formatter_class)
subparsers = parser.add_subparsers(
dest="command",
help="Choose a subcommand",
required=True,
)
prepare_parser = subparsers.add_parser(
"prepare",
help="""
Preprocessing data for classification.
Extract the data coming from the eyes from the fMRI images.
If your data is not in MNI space, bidsmreye will also register the data to MNI.
""",
formatter_class=parser.formatter_class,
)
prepare_parser = _add_common_arguments(prepare_parser)
# TODO make it possible to pass path to a model ?
prepare_parser.add_argument(
"--linear_coreg",
help="""
Uses a less aggressive (and linear) alignment procedure
to the deepmreye template.
May lead to worse results so check your outputs.
""",
action="store_true",
)
generalize_parser = subparsers.add_parser(
"generalize",
help="""Run classification.
Use the extracted timeseries to predict the eye movements
using the default pre-trained model of deepmreye.
""",
formatter_class=parser.formatter_class,
)
generalize_parser = _add_common_arguments(generalize_parser)
# TODO make it possible to pass path to a model ?
generalize_parser.add_argument(
"--model",
help=f"Model to use. Default model: {default_model()}.",
choices=available_models(),
default=default_model(),
)
all_parser = subparsers.add_parser(
"all",
help="""Run prepare, generalize.""",
formatter_class=parser.formatter_class,
)
all_parser = _add_common_arguments(all_parser)
# TODO make it possible to pass path to a model ?
all_parser.add_argument(
"--linear_coreg",
help="""
Uses a less aggressive (and linear) alignment procedure
to the deepmreye template.
May lead to worse results so check your outputs.
""",
action="store_true",
)
# TODO make it possible to pass path to a model ?
all_parser.add_argument(
"--model",
help=f"Model to use. Default model: {default_model()}.",
choices=available_models(),
default=default_model(),
)
qc_parser = subparsers.add_parser(
"qc",
help="""Run quality control on output.""",
formatter_class=parser.formatter_class,
)
qc_parser = _add_common_arguments(qc_parser)
return parser
def download_parser(
formatter_class: type[HelpFormatter] = HelpFormatter,
) -> ArgumentParser:
"""Execute the main script."""
parser = ArgumentParser(
description="Download deepmreye pretrained model from OSF.",
epilog="""
For a more readable version of this help section,
see the online https://bidsmreye.readthedocs.io/.
""",
formatter_class=formatter_class,
)
parser.add_argument(
"--model",
help=f"Model to download. Default model: {default_model()}.",
choices=available_models(),
default=default_model(),
)
parser.add_argument(
"--output_dir",
help="""
The directory where the model files will be stored.
""",
default=Path.cwd() / "models",
)
return parser