Skip to content

Commit 99c686f

Browse files
committed
Generate participants.json and the test
1 parent fe0f2c8 commit 99c686f

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

heudiconv/bids.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,27 @@ def add_participant_record(studydir, subject, age, sex):
240240
known_subjects = {l.split('\t')[0] for l in f.readlines()}
241241
if participant_id in known_subjects:
242242
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)
243264
# Add a new participant
244265
with open(participants_tsv, 'a') as f:
245266
f.write(

heudiconv/tests/test_heuristics.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,13 @@ def test_notop(tmpdir, bidsoptions):
165165
runner(args)
166166

167167
assert op.exists(pjoin(tmppath, 'Halchenko/Yarik/950_bids_test4'))
168-
for fname in ['CHANGES', 'dataset_description.json', 'participants.tsv', 'README']:
168+
for fname in [
169+
'CHANGES',
170+
'dataset_description.json',
171+
'participants.tsv',
172+
'README',
173+
'participants.json'
174+
]:
169175
if 'notop' in bidsoptions:
170176
assert not op.exists(pjoin(tmppath, 'Halchenko/Yarik/950_bids_test4', fname))
171177
else:

0 commit comments

Comments
 (0)