Skip to content

Commit e113349

Browse files
committed
enh: allow dcm2niix configuration
1 parent 9c3e823 commit e113349

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

heudiconv/cli/run.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ def get_parser():
207207
'jsons')
208208
parser.add_argument('--random-seed', type=int, default=None,
209209
help='Random seed to initialize RNG')
210+
parser.add_argument('--dcmconfig', default=None,
211+
help='JSON file for additional dcm2niix configuration')
210212
submission = parser.add_argument_group('Conversion submission options')
211213
submission.add_argument('-q', '--queue', default=None,
212214
help='select batch system to submit jobs to instead'
@@ -226,14 +228,9 @@ def process_args(args):
226228

227229
outdir = op.abspath(args.outdir)
228230

229-
if args.command:
230-
process_extra_commands(outdir, args)
231-
return
232-
233231
lgr.info(INIT_MSG(packname=__packagename__,
234232
version=__version__))
235233

236-
237234
#
238235
# Load heuristic -- better do it asap to make sure it loads correctly
239236
#
@@ -327,7 +324,8 @@ def process_args(args):
327324
bids=args.bids,
328325
seqinfo=seqinfo,
329326
min_meta=args.minmeta,
330-
overwrite=args.overwrite,)
327+
overwrite=args.overwrite,
328+
dcmconfig=args.dcmconfig,)
331329

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

heudiconv/convert.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def conversion_info(subject, outdir, info, filegroup, ses):
7979

8080
def prep_conversion(sid, dicoms, outdir, heuristic, converter, anon_sid,
8181
anon_outdir, with_prov, ses, bids, seqinfo, min_meta,
82-
overwrite):
82+
overwrite, dcmconfig):
8383
if dicoms:
8484
lgr.info("Processing %d dicoms", len(dicoms))
8585
elif seqinfo:
@@ -195,7 +195,8 @@ def prep_conversion(sid, dicoms, outdir, heuristic, converter, anon_sid,
195195
bids=bids,
196196
outdir=tdir,
197197
min_meta=min_meta,
198-
overwrite=overwrite,)
198+
overwrite=overwrite,
199+
dcmconfig=dcmconfig,)
199200

200201
for item_dicoms in filegroup.values():
201202
clear_temp_dicoms(item_dicoms)
@@ -212,7 +213,8 @@ def prep_conversion(sid, dicoms, outdir, heuristic, converter, anon_sid,
212213

213214

214215
def convert(items, converter, scaninfo_suffix, custom_callable, with_prov,
215-
bids, outdir, min_meta, overwrite, symlink=True, prov_file=None):
216+
bids, outdir, min_meta, overwrite, symlink=True, prov_file=None,
217+
dcmconfig=None):
216218
"""Perform actual conversion (calls to converter etc) given info from
217219
heuristic's `infotodict`
218220
@@ -279,7 +281,7 @@ def convert(items, converter, scaninfo_suffix, custom_callable, with_prov,
279281

280282
# run conversion through nipype
281283
res, prov_file = nipype_convert(item_dicoms, prefix, with_prov,
282-
bids, tmpdir)
284+
bids, tmpdir, dcmconfig)
283285

284286
bids_outfiles = save_converted_files(res, item_dicoms, bids,
285287
outtype, prefix,
@@ -383,8 +385,25 @@ def convert_dicom(item_dicoms, bids, prefix,
383385
shutil.copyfile(filename, outfile)
384386

385387

386-
def nipype_convert(item_dicoms, prefix, with_prov, bids, tmpdir):
387-
""" """
388+
def nipype_convert(item_dicoms, prefix, with_prov, bids, tmpdir, dcmconfig=None):
389+
"""
390+
Converts DICOMs grouped from heuristic using Nipype's Dcm2niix interface.
391+
392+
Parameters
393+
----------
394+
item_dicoms : List
395+
DICOM files to convert
396+
prefix : String
397+
Heuristic output path
398+
with_prov : Bool
399+
Store provenance information
400+
bids : Bool
401+
Output BIDS sidecar JSONs
402+
tmpdir : Directory
403+
Conversion working directory
404+
dcmconfig : File (optional)
405+
JSON file used for additional Dcm2niix configuration
406+
"""
388407
import nipype
389408
if with_prov:
390409
from nipype import config
@@ -394,9 +413,11 @@ def nipype_convert(item_dicoms, prefix, with_prov, bids, tmpdir):
394413

395414
item_dicoms = list(map(op.abspath, item_dicoms)) # absolute paths
396415

397-
dicom_dir = op.dirname(item_dicoms[0]) if item_dicoms else None
416+
fromfile = dcmconfig if dcmconfig else None
417+
if fromfile:
418+
lgr.info("Using custom config file %s", fromfile)
398419

399-
convertnode = Node(Dcm2niix(), name='convert')
420+
convertnode = Node(Dcm2niix(from_file=fromfile), name='convert')
400421
convertnode.base_dir = tmpdir
401422
convertnode.inputs.source_names = item_dicoms
402423
convertnode.inputs.out_filename = op.basename(op.dirname(prefix))

0 commit comments

Comments
 (0)