Skip to content

Commit ae234cd

Browse files
author
Steven Tilley
committed
Add --skiptop flag to prevent writing top level bids files
This is useful in batch processing to prevent potential race conditions. The batch processing example has also been modified to use this flag.
1 parent 8cdf06d commit ae234cd

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

docs/usage.rst

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ DICOMs as an independent ``heudiconv`` execution.
4343
The first script aggregates the DICOM directories and submits them to
4444
``run_heudiconv.sh`` with SLURM as a job array.
4545

46+
If using bids, the ``--skiptop`` flag suppresses creation of top-level
47+
files in the bids directory (e.g., ``dataset_description.json``) to
48+
avoid possible race conditions. These files may be generated later
49+
with ``populate_templates.sh`` below (except for ``participants.tsv``,
50+
which must be create manually).
51+
4652
.. code:: shell
4753
4854
#!/bin/bash
@@ -76,7 +82,22 @@ The second script processes a DICOM directory with ``heudiconv`` using the built
7682
echo Submitted directory: ${DCMDIR}
7783
7884
IMG="/singularity-images/heudiconv-0.5.4-dev.sif"
79-
CMD="singularity run -B ${DCMDIR}:/dicoms:ro -B ${OUTDIR}:/output -e ${IMG} --files /dicoms/ -o /output -f reproin -c dcm2niix -b --minmeta -l ."
85+
CMD="singularity run -B ${DCMDIR}:/dicoms:ro -B ${OUTDIR}:/output -e ${IMG} --files /dicoms/ -o /output -f reproin -c dcm2niix -b --minmeta -l . --skiptop"
86+
87+
printf "Command:\n${CMD}\n"
88+
${CMD}
89+
echo "Successful process"
90+
91+
This script creates the top-level bids files (e.g.,
92+
``dataset_description.json``)
93+
94+
..code:: shell
95+
#!/bin/bash
96+
set -eu
97+
98+
OUTDIR=${1}
99+
IMG="/singularity-images/heudiconv-0.5.4-dev.sif"
100+
CMD="singularity run -B ${OUTDIR}:/output -e ${IMG} --files /output -f reproin --command populate-templates"
80101

81102
printf "Command:\n${CMD}\n"
82103
${CMD}

heudiconv/cli/run.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ def get_parser():
222222
help='Additional queue arguments passed as '
223223
'single string of Argument=Value pairs space '
224224
'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.')
225229
return parser
226230

227231

@@ -320,7 +324,8 @@ def process_args(args):
320324
seqinfo=seqinfo,
321325
min_meta=args.minmeta,
322326
overwrite=args.overwrite,
323-
dcmconfig=args.dcmconfig,)
327+
dcmconfig=args.dcmconfig,
328+
skiptop=args.skiptop,)
324329

325330
lgr.info("PROCESSING DONE: {0}".format(
326331
str(dict(subject=sid, outdir=study_outdir, session=session))))

heudiconv/convert.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def conversion_info(subject, outdir, info, filegroup, ses):
8080

8181
def prep_conversion(sid, dicoms, outdir, heuristic, converter, anon_sid,
8282
anon_outdir, with_prov, ses, bids, seqinfo, min_meta,
83-
overwrite, dcmconfig):
83+
overwrite, dcmconfig, skiptop):
8484
if dicoms:
8585
lgr.info("Processing %d dicoms", len(dicoms))
8686
elif seqinfo:
@@ -201,7 +201,7 @@ def prep_conversion(sid, dicoms, outdir, heuristic, converter, anon_sid,
201201
for item_dicoms in filegroup.values():
202202
clear_temp_dicoms(item_dicoms)
203203

204-
if bids:
204+
if bids and not skiptop:
205205
if seqinfo:
206206
keys = list(seqinfo)
207207
add_participant_record(anon_outdir,

0 commit comments

Comments
 (0)