18
18
19
19
INIT_MSG = "Running {packname} version {version}" .format
20
20
21
+ BIDS_OPTIONS = [('notop' , 'Skip creating of top-level bids files. '
22
+ 'Useful when running in batch mode to prevent '
23
+ 'possible race conditions.' )]
24
+
21
25
22
26
def is_interactive ():
23
27
"""Return True if all in/outs are tty"""
@@ -98,9 +102,20 @@ def process_extra_commands(outdir, args):
98
102
return
99
103
100
104
105
+ def help_bids ():
106
+ print ('bids specific options can be passed after the bids flag.' , file = sys .stdout )
107
+ print ('For example, "--bids notop".' , file = sys .stdout )
108
+ print ('The currently supported options are:' , file = sys .stdout )
109
+ for option , helpstr in BIDS_OPTIONS :
110
+ print ('{}: {}' .format (option , helpstr ), file = sys .stdout )
111
+
112
+
101
113
def main (argv = None ):
102
114
parser = get_parser ()
103
115
args = parser .parse_args (argv )
116
+ if args .help_bids :
117
+ help_bids ()
118
+ sys .exit (1 )
104
119
# exit if nothing to be done
105
120
if not args .files and not args .dicom_dir_template and not args .command :
106
121
lgr .warning ("Nothing to be done - displaying usage help" )
@@ -112,6 +127,18 @@ def main(argv=None):
112
127
random .seed (args .random_seed )
113
128
import numpy
114
129
numpy .random .seed (args .random_seed )
130
+ # Ensure only supported bids options are passed
131
+ allowed_options = [option for option , _ in BIDS_OPTIONS ]
132
+ if args .bids is not None :
133
+ for bids_option in args .bids :
134
+ if bids_option not in allowed_options :
135
+ lgr .warning ("{} is not a valid bids option - displaying bids options help" .format (bids_option ))
136
+ help_bids ()
137
+ sys .exit (1 )
138
+ args .bids_options = args .bids
139
+ args .bids = True
140
+ else :
141
+ args .bids = False
115
142
if args .debug :
116
143
lgr .setLevel (logging .DEBUG )
117
144
# Should be possible but only with a single subject -- will be used to
@@ -181,8 +208,11 @@ def get_parser():
181
208
parser .add_argument ('-ss' , '--ses' , dest = 'session' , default = None ,
182
209
help = 'session for longitudinal study_sessions, default '
183
210
'is none' )
184
- parser .add_argument ('-b' , '--bids' , action = 'store_true' ,
185
- help = 'flag for output into BIDS structure' )
211
+ parser .add_argument ('-b' , '--bids' , nargs = '*' ,
212
+ metavar = ('BIDSOPTION1' , 'BIDSOPTION2' ),
213
+ help = 'flag for output into BIDS structure. '
214
+ 'Can also take bids specific options. Use --help-bids '
215
+ 'for more information.' )
186
216
parser .add_argument ('--overwrite' , action = 'store_true' , default = False ,
187
217
help = 'flag to allow overwriting existing converted files' )
188
218
parser .add_argument ('--datalad' , action = 'store_true' ,
@@ -222,10 +252,8 @@ def get_parser():
222
252
help = 'Additional queue arguments passed as '
223
253
'single string of Argument=Value pairs space '
224
254
'separated.' )
225
- parser .add_argument ('--skiptop' , action = 'store_true' ,
226
- help = 'Skip creating of top-level bids files. '
227
- 'Useful when running in batch mode to prevent '
228
- 'possible race conditions.' )
255
+ parser .add_argument ('--help-bids' , action = 'store_true' , dest = 'help_bids' ,
256
+ help = 'Display bids specific help.' )
229
257
return parser
230
258
231
259
@@ -325,7 +353,7 @@ def process_args(args):
325
353
min_meta = args .minmeta ,
326
354
overwrite = args .overwrite ,
327
355
dcmconfig = args .dcmconfig ,
328
- skiptop = args .skiptop ,)
356
+ bids_options = args .bids_options ,)
329
357
330
358
lgr .info ("PROCESSING DONE: {0}" .format (
331
359
str (dict (subject = sid , outdir = study_outdir , session = session ))))
0 commit comments