Skip to content

Commit

Permalink
enh: allow dcm2niix configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
mgxd committed May 9, 2018
1 parent 9c3e823 commit e113349
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
10 changes: 4 additions & 6 deletions heudiconv/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ def get_parser():
'jsons')
parser.add_argument('--random-seed', type=int, default=None,
help='Random seed to initialize RNG')
parser.add_argument('--dcmconfig', default=None,
help='JSON file for additional dcm2niix configuration')
submission = parser.add_argument_group('Conversion submission options')
submission.add_argument('-q', '--queue', default=None,
help='select batch system to submit jobs to instead'
Expand All @@ -226,14 +228,9 @@ def process_args(args):

outdir = op.abspath(args.outdir)

if args.command:
process_extra_commands(outdir, args)
return

lgr.info(INIT_MSG(packname=__packagename__,
version=__version__))


#
# Load heuristic -- better do it asap to make sure it loads correctly
#
Expand Down Expand Up @@ -327,7 +324,8 @@ def process_args(args):
bids=args.bids,
seqinfo=seqinfo,
min_meta=args.minmeta,
overwrite=args.overwrite,)
overwrite=args.overwrite,
dcmconfig=args.dcmconfig,)

lgr.info("PROCESSING DONE: {0}".format(
str(dict(subject=sid, outdir=study_outdir, session=session))))
Expand Down
37 changes: 29 additions & 8 deletions heudiconv/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def conversion_info(subject, outdir, info, filegroup, ses):

def prep_conversion(sid, dicoms, outdir, heuristic, converter, anon_sid,
anon_outdir, with_prov, ses, bids, seqinfo, min_meta,
overwrite):
overwrite, dcmconfig):
if dicoms:
lgr.info("Processing %d dicoms", len(dicoms))
elif seqinfo:
Expand Down Expand Up @@ -195,7 +195,8 @@ def prep_conversion(sid, dicoms, outdir, heuristic, converter, anon_sid,
bids=bids,
outdir=tdir,
min_meta=min_meta,
overwrite=overwrite,)
overwrite=overwrite,
dcmconfig=dcmconfig,)

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


def convert(items, converter, scaninfo_suffix, custom_callable, with_prov,
bids, outdir, min_meta, overwrite, symlink=True, prov_file=None):
bids, outdir, min_meta, overwrite, symlink=True, prov_file=None,
dcmconfig=None):
"""Perform actual conversion (calls to converter etc) given info from
heuristic's `infotodict`
Expand Down Expand Up @@ -279,7 +281,7 @@ def convert(items, converter, scaninfo_suffix, custom_callable, with_prov,

# run conversion through nipype
res, prov_file = nipype_convert(item_dicoms, prefix, with_prov,
bids, tmpdir)
bids, tmpdir, dcmconfig)

bids_outfiles = save_converted_files(res, item_dicoms, bids,
outtype, prefix,
Expand Down Expand Up @@ -383,8 +385,25 @@ def convert_dicom(item_dicoms, bids, prefix,
shutil.copyfile(filename, outfile)


def nipype_convert(item_dicoms, prefix, with_prov, bids, tmpdir):
""" """
def nipype_convert(item_dicoms, prefix, with_prov, bids, tmpdir, dcmconfig=None):
"""
Converts DICOMs grouped from heuristic using Nipype's Dcm2niix interface.
Parameters
----------
item_dicoms : List
DICOM files to convert
prefix : String
Heuristic output path
with_prov : Bool
Store provenance information
bids : Bool
Output BIDS sidecar JSONs
tmpdir : Directory
Conversion working directory
dcmconfig : File (optional)
JSON file used for additional Dcm2niix configuration
"""
import nipype
if with_prov:
from nipype import config
Expand All @@ -394,9 +413,11 @@ def nipype_convert(item_dicoms, prefix, with_prov, bids, tmpdir):

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

dicom_dir = op.dirname(item_dicoms[0]) if item_dicoms else None
fromfile = dcmconfig if dcmconfig else None
if fromfile:
lgr.info("Using custom config file %s", fromfile)

convertnode = Node(Dcm2niix(), name='convert')
convertnode = Node(Dcm2niix(from_file=fromfile), name='convert')
convertnode.base_dir = tmpdir
convertnode.inputs.source_names = item_dicoms
convertnode.inputs.out_filename = op.basename(op.dirname(prefix))
Expand Down

0 comments on commit e113349

Please sign in to comment.