Skip to content

Commit 5e12dea

Browse files
author
Steven Tilley
committed
Restructure so bids flag takes bids specific options
the flag for skipping the top directory is now called notop.
1 parent ae234cd commit 5e12dea

File tree

3 files changed

+44
-15
lines changed

3 files changed

+44
-15
lines changed

docs/usage.rst

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +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).
46+
If using bids, the ``notop`` bids option suppresses creation of
47+
top-level files in the bids directory (e.g.,
48+
``dataset_description.json``) to avoid possible race conditions.
49+
These files may be generated later with ``populate_templates.sh``
50+
below (except for ``participants.tsv``, which must be create
51+
manually).
5152

5253
.. code:: shell
5354
@@ -82,7 +83,7 @@ The second script processes a DICOM directory with ``heudiconv`` using the built
8283
echo Submitted directory: ${DCMDIR}
8384
8485
IMG="/singularity-images/heudiconv-0.5.4-dev.sif"
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+
CMD="singularity run -B ${DCMDIR}:/dicoms:ro -B ${OUTDIR}:/output -e ${IMG} --files /dicoms/ -o /output -f reproin -c dcm2niix -b notop --minmeta -l ."
8687
8788
printf "Command:\n${CMD}\n"
8889
${CMD}

heudiconv/cli/run.py

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
INIT_MSG = "Running {packname} version {version}".format
2020

21+
BIDS_OPTIONS = [('notop', 'Skip creating of top-level bids files. '
22+
'Useful when running in batch mode to prevent '
23+
'possible race conditions.')]
24+
2125

2226
def is_interactive():
2327
"""Return True if all in/outs are tty"""
@@ -98,9 +102,20 @@ def process_extra_commands(outdir, args):
98102
return
99103

100104

105+
def help_bids():
106+
print('bids specific options can be passed after the bids flag.', file=sys.stdout)
107+
print('For example, "--bids notop".', file=sys.stdout)
108+
print('The currently supported options are:', file=sys.stdout)
109+
for option, helpstr in BIDS_OPTIONS:
110+
print('{}: {}'.format(option, helpstr), file=sys.stdout)
111+
112+
101113
def main(argv=None):
102114
parser = get_parser()
103115
args = parser.parse_args(argv)
116+
if args.help_bids:
117+
help_bids()
118+
sys.exit(1)
104119
# exit if nothing to be done
105120
if not args.files and not args.dicom_dir_template and not args.command:
106121
lgr.warning("Nothing to be done - displaying usage help")
@@ -112,6 +127,18 @@ def main(argv=None):
112127
random.seed(args.random_seed)
113128
import numpy
114129
numpy.random.seed(args.random_seed)
130+
# Ensure only supported bids options are passed
131+
allowed_options = [option for option, _ in BIDS_OPTIONS]
132+
if args.bids is not None:
133+
for bids_option in args.bids:
134+
if bids_option not in allowed_options:
135+
lgr.warning("{} is not a valid bids option - displaying bids options help".format(bids_option))
136+
help_bids()
137+
sys.exit(1)
138+
args.bids_options = args.bids
139+
args.bids = True
140+
else:
141+
args.bids = False
115142
if args.debug:
116143
lgr.setLevel(logging.DEBUG)
117144
# Should be possible but only with a single subject -- will be used to
@@ -181,8 +208,11 @@ def get_parser():
181208
parser.add_argument('-ss', '--ses', dest='session', default=None,
182209
help='session for longitudinal study_sessions, default '
183210
'is none')
184-
parser.add_argument('-b', '--bids', action='store_true',
185-
help='flag for output into BIDS structure')
211+
parser.add_argument('-b', '--bids', nargs='*',
212+
metavar=('BIDSOPTION1', 'BIDSOPTION2'),
213+
help='flag for output into BIDS structure. '
214+
'Can also take bids specific options. Use --help-bids '
215+
'for more information.')
186216
parser.add_argument('--overwrite', action='store_true', default=False,
187217
help='flag to allow overwriting existing converted files')
188218
parser.add_argument('--datalad', action='store_true',
@@ -222,10 +252,8 @@ def get_parser():
222252
help='Additional queue arguments passed as '
223253
'single string of Argument=Value pairs space '
224254
'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.')
255+
parser.add_argument('--help-bids', action='store_true', dest='help_bids',
256+
help='Display bids specific help.')
229257
return parser
230258

231259

@@ -325,7 +353,7 @@ def process_args(args):
325353
min_meta=args.minmeta,
326354
overwrite=args.overwrite,
327355
dcmconfig=args.dcmconfig,
328-
skiptop=args.skiptop,)
356+
bids_options=args.bids_options,)
329357

330358
lgr.info("PROCESSING DONE: {0}".format(
331359
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, skiptop):
83+
overwrite, dcmconfig, bids_options):
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 and not skiptop:
204+
if bids and 'notop' not in bids_options:
205205
if seqinfo:
206206
keys = list(seqinfo)
207207
add_participant_record(anon_outdir,

0 commit comments

Comments
 (0)