@@ -60,7 +60,7 @@ def process_extra_commands(outdir, args):
60
60
for f in args .files :
61
61
treat_infofile (f )
62
62
elif args .command == 'ls' :
63
- heuristic = load_heuristic (op . realpath ( args .heuristic_file ) )
63
+ heuristic = load_heuristic (args .heuristic )
64
64
heuristic_ls = getattr (heuristic , 'ls' , None )
65
65
for f in args .files :
66
66
study_sessions = get_study_sessions (
@@ -76,11 +76,21 @@ def process_extra_commands(outdir, args):
76
76
% (str (study_session ), len (sequences ), suf )
77
77
)
78
78
elif args .command == 'populate-templates' :
79
- heuristic = load_heuristic (op . realpath ( args .heuristic_file ) )
79
+ heuristic = load_heuristic (args .heuristic )
80
80
for f in args .files :
81
81
populate_bids_templates (f , getattr (heuristic , 'DEFAULT_FIELDS' , {}))
82
82
elif args .command == 'sanitize-jsons' :
83
83
tuneup_bids_json_files (args .files )
84
+ elif args .command == 'heuristics' :
85
+ from ..utils import get_known_heuristics_with_descriptions
86
+ for name_desc in get_known_heuristics_with_descriptions ().items ():
87
+ print ("- %s: %s" % name_desc )
88
+ elif args .command == 'heuristic-info' :
89
+ from ..utils import get_heuristic_description , get_known_heuristic_names
90
+ if not args .heuristic :
91
+ raise ValueError ("Specify heuristic using -f. Known are: %s"
92
+ % ', ' .join (get_known_heuristic_names ()))
93
+ print (get_heuristic_description (args .heuristic , full = True ))
84
94
else :
85
95
raise ValueError ("Unknown command %s" , args .command )
86
96
return
@@ -149,9 +159,11 @@ def get_parser():
149
159
'DICOMs to anonymized IDs. Such command must take a '
150
160
'single argument and return a single anonymized ID. '
151
161
'Also see --conv-outdir' )
152
- parser .add_argument ('-f' , '--heuristic' , dest = 'heuristic_file' ,
153
- required = True ,
154
- help = 'python script containing heuristic' )
162
+ parser .add_argument ('-f' , '--heuristic' , dest = 'heuristic' ,
163
+ # some commands might not need heuristic
164
+ # required=True,
165
+ help = 'Name of a known heuristic or path to the Python'
166
+ 'script containing heuristic' )
155
167
parser .add_argument ('-p' , '--with-prov' , action = 'store_true' ,
156
168
help = 'Store additional provenance information. '
157
169
'Requires python-rdflib.' )
@@ -174,8 +186,11 @@ def get_parser():
174
186
help = 'Do not catch exceptions and show exception '
175
187
'traceback' )
176
188
parser .add_argument ('--command' ,
177
- choices = ('ls' , 'populate-templates' ,
178
- 'treat-jsons' , 'sanitize-jsons' ),
189
+ choices = (
190
+ 'heuristics' , 'heuristic-info' ,
191
+ 'ls' , 'populate-templates' ,
192
+ 'sanitize-jsons' , 'treat-jsons' ,
193
+ ),
179
194
help = 'custom actions to be performed on provided '
180
195
'files instead of regular operation.' )
181
196
parser .add_argument ('-g' , '--grouping' , default = 'studyUID' ,
@@ -203,19 +218,20 @@ def process_args(args):
203
218
# pre-process provided list of files and possibly sort into groups/sessions
204
219
# Group files per each study/sid/session
205
220
206
- lgr .info (INIT_MSG (packname = __packagename__ ,
207
- version = __version__ ))
208
-
209
221
outdir = op .abspath (args .outdir )
210
222
211
223
if args .command :
212
224
process_extra_commands (outdir , args )
213
225
return
214
226
227
+ lgr .info (INIT_MSG (packname = __packagename__ ,
228
+ version = __version__ ))
229
+
230
+
215
231
#
216
232
# Load heuristic -- better do it asap to make sure it loads correctly
217
233
#
218
- heuristic = load_heuristic (op . realpath ( args .heuristic_file ) )
234
+ heuristic = load_heuristic (args .heuristic )
219
235
220
236
study_sessions = get_study_sessions (args .dicom_dir_template , args .files ,
221
237
heuristic , outdir , args .session ,
0 commit comments