Skip to content

Commit ca402a9

Browse files
authored
Merge pull request #359 from mgxd/fix/group
ENH: grouping
2 parents 4247eb6 + 7446875 commit ca402a9

File tree

7 files changed

+328
-232
lines changed

7 files changed

+328
-232
lines changed

heudiconv/cli/run.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ def main(argv=None):
124124

125125
if args.debug:
126126
setup_exceptionhook()
127-
128127
process_args(args)
129128

130129

@@ -154,8 +153,7 @@ def get_parser():
154153
'If not provided, DICOMS would first be "sorted" and '
155154
'subject IDs deduced by the heuristic')
156155
parser.add_argument('-c', '--converter',
157-
default='dcm2niix',
158-
choices=('dcm2niix', 'none'),
156+
choices=('dcm2niix', 'none'), default='dcm2niix',
159157
help='tool to use for DICOM conversion. Setting to '
160158
'"none" disables the actual conversion step -- useful'
161159
'for testing heuristics.')
@@ -219,7 +217,7 @@ def get_parser():
219217
help='custom actions to be performed on provided '
220218
'files instead of regular operation.')
221219
parser.add_argument('-g', '--grouping', default='studyUID',
222-
choices=('studyUID', 'accession_number'),
220+
choices=('studyUID', 'accession_number', 'all', 'custom'),
223221
help='How to group dicoms (default: by studyUID)')
224222
parser.add_argument('--minmeta', action='store_true',
225223
help='Exclude dcmstack meta information in sidecar '
@@ -343,7 +341,8 @@ def process_args(args):
343341
seqinfo=seqinfo,
344342
min_meta=args.minmeta,
345343
overwrite=args.overwrite,
346-
dcmconfig=args.dcmconfig,)
344+
dcmconfig=args.dcmconfig,
345+
grouping=args.grouping,)
347346

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

heudiconv/convert.py

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

8181

8282
def prep_conversion(sid, dicoms, outdir, heuristic, converter, anon_sid,
83-
anon_outdir, with_prov, ses, bids_options, seqinfo, min_meta,
84-
overwrite, dcmconfig):
83+
anon_outdir, with_prov, ses, bids_options, seqinfo,
84+
min_meta, overwrite, dcmconfig, grouping):
8585
if dicoms:
8686
lgr.info("Processing %d dicoms", len(dicoms))
8787
elif seqinfo:
@@ -157,16 +157,17 @@ def prep_conversion(sid, dicoms, outdir, heuristic, converter, anon_sid,
157157
# So either it would need to be brought back or reconsidered altogether
158158
# (since no sample data to test on etc)
159159
else:
160-
# TODO -- might have been done outside already!
161-
# MG -- will have to try with both dicom template, files
162160
assure_no_file_exists(target_heuristic_filename)
163161
safe_copyfile(heuristic.filename, target_heuristic_filename)
164162
if dicoms:
165163
seqinfo = group_dicoms_into_seqinfos(
166164
dicoms,
165+
grouping,
167166
file_filter=getattr(heuristic, 'filter_files', None),
168167
dcmfilter=getattr(heuristic, 'filter_dicom', None),
169-
grouping=None)
168+
flatten=True,
169+
custom_grouping=getattr(heuristic, 'grouping', None))
170+
170171
seqinfo_list = list(seqinfo.keys())
171172
filegroup = {si.series_id: x for si, x in seqinfo.items()}
172173
dicominfo_file = op.join(idir, 'dicominfo%s.tsv' % ses_suffix)

0 commit comments

Comments
 (0)