@@ -240,6 +240,27 @@ def add_participant_record(studydir, subject, age, sex):
240
240
known_subjects = {l .split ('\t ' )[0 ] for l in f .readlines ()}
241
241
if participant_id in known_subjects :
242
242
return
243
+ else :
244
+ # Populate particpants.json (an optional file to describe column names in
245
+ # participant.tsv). This auto generation will make BIDS-validator happy.
246
+ participants_json = op .join (studydir , 'participants.json' )
247
+ if not op .lexists (participants_json ):
248
+ save_json (participants_json ,
249
+ OrderedDict ([
250
+ ("participant_id" , OrderedDict ([
251
+ ("Description" , "Participant identifier" )])),
252
+ ("age" , OrderedDict ([
253
+ ("Description" , "Age in years (TODO - verify) as in the initial"
254
+ " session, might not be correct for other sessions" )])),
255
+ ("sex" , OrderedDict ([
256
+ ("Description" , "self-rated by participant, M for male/F for "
257
+ "female (TODO: verify)" )])),
258
+ ("group" , OrderedDict ([
259
+ ("Description" , "(TODO: adjust - by default everyone is in "
260
+ "control group)" )])),
261
+ ]),
262
+ sort_keys = False ,
263
+ indent = 2 )
243
264
# Add a new participant
244
265
with open (participants_tsv , 'a' ) as f :
245
266
f .write (
@@ -311,7 +332,8 @@ def save_scans_key(item, bids_files):
311
332
312
333
def add_rows_to_scans_keys_file (fn , newrows ):
313
334
"""
314
- Add new rows to file fn for scans key filename
335
+ Add new rows to file fn for scans key filename and generate accompanying json
336
+ descriptor to make BIDS validator happy.
315
337
316
338
Parameters
317
339
----------
@@ -334,6 +356,25 @@ def add_rows_to_scans_keys_file(fn, newrows):
334
356
os .unlink (fn )
335
357
else :
336
358
fnames2info = newrows
359
+ # Populate _scans.json (an optional file to describe column names in
360
+ # _scans.tsv). This auto generation will make BIDS-validator happy.
361
+ scans_json = '.' .join (fn .split ('.' )[:- 1 ] + ['json' ])
362
+ if not op .lexists (scans_json ):
363
+ save_json (scans_json ,
364
+ OrderedDict ([
365
+ ("filename" , OrderedDict ([
366
+ ("Description" , "Name of the nifti file" )])),
367
+ ("acq_time" , OrderedDict ([
368
+ ("LongName" , "Acquisition time" ),
369
+ ("Description" , "Acquisition time of the particular scan" )])),
370
+ ("operator" , OrderedDict ([
371
+ ("Description" , "Name of the operator" )])),
372
+ ("randstr" , OrderedDict ([
373
+ ("LongName" , "Random string" ),
374
+ ("Description" , "md5 hash of UIDs" )])),
375
+ ]),
376
+ sort_keys = False ,
377
+ indent = 2 )
337
378
338
379
header = ['filename' , 'acq_time' , 'operator' , 'randstr' ]
339
380
# prepare all the data rows
0 commit comments