Skip to content

Commit

Permalink
Merge pull request #359 from mgxd/fix/group
Browse files Browse the repository at this point in the history
ENH: grouping
  • Loading branch information
yarikoptic authored Mar 6, 2020
2 parents 4247eb6 + 7446875 commit ca402a9
Show file tree
Hide file tree
Showing 7 changed files with 328 additions and 232 deletions.
9 changes: 4 additions & 5 deletions heudiconv/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ def main(argv=None):

if args.debug:
setup_exceptionhook()

process_args(args)


Expand Down Expand Up @@ -154,8 +153,7 @@ def get_parser():
'If not provided, DICOMS would first be "sorted" and '
'subject IDs deduced by the heuristic')
parser.add_argument('-c', '--converter',
default='dcm2niix',
choices=('dcm2niix', 'none'),
choices=('dcm2niix', 'none'), default='dcm2niix',
help='tool to use for DICOM conversion. Setting to '
'"none" disables the actual conversion step -- useful'
'for testing heuristics.')
Expand Down Expand Up @@ -219,7 +217,7 @@ def get_parser():
help='custom actions to be performed on provided '
'files instead of regular operation.')
parser.add_argument('-g', '--grouping', default='studyUID',
choices=('studyUID', 'accession_number'),
choices=('studyUID', 'accession_number', 'all', 'custom'),
help='How to group dicoms (default: by studyUID)')
parser.add_argument('--minmeta', action='store_true',
help='Exclude dcmstack meta information in sidecar '
Expand Down Expand Up @@ -343,7 +341,8 @@ def process_args(args):
seqinfo=seqinfo,
min_meta=args.minmeta,
overwrite=args.overwrite,
dcmconfig=args.dcmconfig,)
dcmconfig=args.dcmconfig,
grouping=args.grouping,)

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


def prep_conversion(sid, dicoms, outdir, heuristic, converter, anon_sid,
anon_outdir, with_prov, ses, bids_options, seqinfo, min_meta,
overwrite, dcmconfig):
anon_outdir, with_prov, ses, bids_options, seqinfo,
min_meta, overwrite, dcmconfig, grouping):
if dicoms:
lgr.info("Processing %d dicoms", len(dicoms))
elif seqinfo:
Expand Down Expand Up @@ -157,16 +157,17 @@ def prep_conversion(sid, dicoms, outdir, heuristic, converter, anon_sid,
# So either it would need to be brought back or reconsidered altogether
# (since no sample data to test on etc)
else:
# TODO -- might have been done outside already!
# MG -- will have to try with both dicom template, files
assure_no_file_exists(target_heuristic_filename)
safe_copyfile(heuristic.filename, target_heuristic_filename)
if dicoms:
seqinfo = group_dicoms_into_seqinfos(
dicoms,
grouping,
file_filter=getattr(heuristic, 'filter_files', None),
dcmfilter=getattr(heuristic, 'filter_dicom', None),
grouping=None)
flatten=True,
custom_grouping=getattr(heuristic, 'grouping', None))

seqinfo_list = list(seqinfo.keys())
filegroup = {si.series_id: x for si, x in seqinfo.items()}
dicominfo_file = op.join(idir, 'dicominfo%s.tsv' % ses_suffix)
Expand Down
Loading

0 comments on commit ca402a9

Please sign in to comment.