Skip to content

Commit ce11874

Browse files
committed
BF: Do not overwrite existing files with BIDS templates
Yes, I will.
1 parent 2b9eac6 commit ce11874

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

heudiconv/bids.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def populate_bids_templates(path, defaults={}):
2929

3030
lgr.info("Populating template files under %s", path)
3131
descriptor = op.join(path, 'dataset_description.json')
32-
if not op.exists(descriptor):
32+
if not op.lexists(descriptor):
3333
save_json(descriptor,
3434
OrderedDict([
3535
('Name', "TODO: name of the dataset"),
@@ -51,7 +51,7 @@ def populate_bids_templates(path, defaults={}):
5151
('DatasetDOI', 'TODO: eventually a DOI for the dataset')
5252
]))
5353
sourcedata_README = op.join(path, 'sourcedata', 'README')
54-
if op.exists(op.dirname(sourcedata_README)):
54+
if not op.lexists(op.dirname(sourcedata_README)):
5555
create_file_if_missing(sourcedata_README,
5656
("TODO: Provide description about source data, e.g. \n"
5757
"Directory below contains DICOMS compressed into tarballs per "
@@ -89,18 +89,22 @@ def populate_bids_templates(path, defaults={}):
8989
suf = '_bold.json'
9090
assert fpath.endswith(suf)
9191
events_file = fpath[:-len(suf)] + '_events.tsv'
92-
lgr.debug("Generating %s", events_file)
93-
with open(events_file, 'w') as f:
94-
f.write("onset\tduration\ttrial_type\tresponse_time\tstim_file\tTODO -- fill in rows and add more tab-separated columns if desired")
92+
# do not touch any existing thing, it may be precious
93+
if not op.lexists(events_file):
94+
lgr.debug("Generating %s", events_file)
95+
with open(events_file, 'w') as f:
96+
f.write("onset\tduration\ttrial_type\tresponse_time\tstim_file\tTODO -- fill in rows and add more tab-separated columns if desired")
9597
# extract tasks files stubs
9698
for task_acq, fields in tasks.items():
9799
task_file = op.join(path, task_acq + '_bold.json')
98-
lgr.debug("Generating %s", task_file)
99-
fields["TaskName"] = ("TODO: full task name for %s" %
100-
task_acq.split('_')[0].split('-')[1])
101-
fields["CogAtlasID"] = "TODO"
102-
with open(task_file, 'w') as f:
103-
f.write(json_dumps_pretty(fields, indent=2, sort_keys=True))
100+
# do not touch any existing thing, it may be precious
101+
if not op.lexists(task_file):
102+
lgr.debug("Generating %s", task_file)
103+
fields["TaskName"] = ("TODO: full task name for %s" %
104+
task_acq.split('_')[0].split('-')[1])
105+
fields["CogAtlasID"] = "TODO"
106+
with open(task_file, 'w') as f:
107+
f.write(json_dumps_pretty(fields, indent=2, sort_keys=True))
104108

105109

106110
def tuneup_bids_json_files(json_files):

0 commit comments

Comments
 (0)