Skip to content

Commit a5de8ae

Browse files
committed
fix: various fixes left over from refactor
1 parent ece8462 commit a5de8ae

File tree

4 files changed

+40
-23
lines changed

4 files changed

+40
-23
lines changed

heudiconv/bids.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ def tuneup_bids_json_files(json_files):
123123
# Let's hope no word 'Date' comes within a study name or smth like
124124
# that
125125
raise ValueError("There must be no dates in .json sidecar")
126-
#json.dump(json_, open(jsonfile, 'w'), indent=2)
127-
save_json(jsonfile, json_, indent=2) # ensure this does same as above
126+
save_json(jsonfile, json_, indent=2)
128127

129128
# Load the beast
130129
seqtype = op.basename(op.dirname(jsonfile))
@@ -163,7 +162,7 @@ def add_participant_record(studydir, subject, age, sex):
163162
participant_id = 'sub-%s' % subject
164163

165164
if not create_file_if_missing(participants_tsv,
166-
'\t'.join(['participant_id', 'age', 'sex', 'group']) + '\n'):
165+
'\t'.join(['participant_id', 'age', 'sex', 'group']) + '\n'):
167166
# check if may be subject record already exists
168167
with open(participants_tsv) as f:
169168
f.readline()

heudiconv/cli/run.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from ..parser import get_study_sessions
88
from ..utils import load_heuristic, anonymize_sid, treat_infofile, SeqInfo
99
from ..convert import prep_conversion
10+
from ..bids import populate_bids_templates, tuneup_bids_json_files
11+
from ..queue import queue_conversion
1012

1113
import inspect
1214
import logging
@@ -36,7 +38,7 @@ def _pdb_excepthook(type, value, tb):
3638
# print()
3739
pdb.post_mortem(tb)
3840
else:
39-
lgr.warn(
41+
lgr.warning(
4042
"We cannot setup exception hook since not in interactive mode")
4143

4244
sys.excepthook = _pdb_excepthook
@@ -106,15 +108,15 @@ def get_parser():
106108
parser.add_argument('--version', action='version', version=__version__)
107109
group = parser.add_mutually_exclusive_group()
108110
group.add_argument('-d', '--dicom_dir_template', dest='dicom_dir_template',
109-
help='location of dicomdir that can be indexed with '
110-
'subject id {subject} and session {session}. Tarballs '
111-
'(can be compressed) are supported in addition to '
112-
'directory. All matching tarballs for a subject are '
113-
'extracted and their content processed in a single pass')
111+
help='location of dicomdir that can be indexed with '
112+
'subject id {subject} and session {session}. Tarballs '
113+
'(can be compressed) are supported in addition to '
114+
'directory. All matching tarballs for a subject are '
115+
'extracted and their content processed in a single pass')
114116
group.add_argument('--files', nargs='*',
115-
help='Files (tarballs, dicoms) or directories '
116-
'containing files to process. Cannot be provided if '
117-
'using --dicom_dir_template or --subjects')
117+
help='Files (tarballs, dicoms) or directories '
118+
'containing files to process. Cannot be provided if '
119+
'using --dicom_dir_template or --subjects')
118120
parser.add_argument('-s', '--subjects', dest='subjs', type=str, nargs='*',
119121
help='list of subjects - required for dicom template. '
120122
'If not provided, DICOMS would first be "sorted" and '

heudiconv/convert.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os.path as op
33
import logging
44
import shutil
5+
import sys
56

67
from .utils import (
78
read_config,
@@ -66,6 +67,7 @@ def conversion_info(subject, outdir, info, filegroup, ses):
6667
try:
6768
files = filegroup[item]
6869
except KeyError:
70+
PY3 = sys.version_info[0] >= 3
6971
files = filegroup[(str if PY3 else unicode)(item)]
7072
outprefix = template.format(**parameters)
7173
convert_info.append((op.join(outpath, outprefix),
@@ -238,8 +240,8 @@ def convert(items, converter, scaninfo_suffix, custom_callable, with_prov,
238240
tmpdir = tempdirs('dcm2niix')
239241

240242
# run conversion through nipype
241-
res = nipype_convert(item_dicoms, prefix, with_prov, bids,
242-
tmpdir)
243+
res, prov_file = nipype_convert(item_dicoms, prefix, with_prov,
244+
bids, tmpdir)
243245

244246
bids_outfiles = save_converted_files(res, item_dicoms, bids,
245247
outtype, prefix,
@@ -252,12 +254,7 @@ def convert(items, converter, scaninfo_suffix, custom_callable, with_prov,
252254
# Fix up and unify BIDS files
253255
tuneup_bids_json_files(bids_outfiles)
254256

255-
prov_file = prefix + '_prov.ttl' if with_prov else None
256257
if prov_file:
257-
safe_copyfile(op.join(convertnode.base_dir,
258-
convertnode.name,
259-
'provenance.ttl'),
260-
prov_file)
261258
prov_files.append(prov_file)
262259

263260
tempdirs.rmtree(tmpdir)
@@ -293,8 +290,17 @@ def convert_dicom(item_dicoms, bids, prefix,
293290
DICOMs to save
294291
bids : bool
295292
Save to BIDS format
296-
sourcedir : string
297-
Path to BIDS output
293+
prefix : string
294+
Conversion outname
295+
outdir : string
296+
Output directory
297+
tempdirs : TempDirs instance
298+
Object to handle temporary directories created
299+
TODO: remove
300+
symlink : bool
301+
Create softlink to DICOMs - if False, create hardlink instead.
302+
overwrite : bool
303+
If True, allows overwriting of previous conversion
298304
299305
Returns
300306
-------
@@ -346,7 +352,17 @@ def nipype_convert(item_dicoms, prefix, with_prov, bids, tmpdir):
346352
convertnode.inputs.out_filename = op.basename(op.dirname(prefix))
347353
convertnode.inputs.terminal_output = 'allatonce'
348354
convertnode.inputs.bids_format = bids
349-
return convertnode.run()
355+
eg = convertnode.run()
356+
357+
# prov information
358+
prov_file = prefix + '_prov.ttl' if with_prov else None
359+
if prov_file:
360+
safe_copyfile(op.join(convertnode.base_dir,
361+
convertnode.name,
362+
'provenance.ttl'),
363+
prov_file)
364+
365+
return eg, prov_file
350366

351367

352368
def save_converted_files(res, item_dicoms, bids, outtype, prefix, outname_bids):

heudiconv/queue.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def queue_conversion(progname, queue, outdir, heuristic, dicoms, sid,
1111

1212
# Rework this...
1313
convertcmd = ' '.join(['python', progname,
14-
'-o', study_outdir,
14+
'-o', outdir,
1515
'-f', heuristic,
1616
'-s', sid,
1717
'--anon-cmd', anon_cmd,

0 commit comments

Comments
 (0)