Skip to content

Commit 428242c

Browse files
authored
Merge pull request #142 from mgxd/fix/ref
fix: various fixes left over from refactor
2 parents 24665ae + 4fef052 commit 428242c

File tree

6 files changed

+46
-30
lines changed

6 files changed

+46
-30
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.cache/
33
.coverage
44
*.egg-info/
5+
.idea/

Dockerfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# pull request on our GitHub repository:
66
# https://github.com/kaczmarj/neurodocker
77
#
8-
# Timestamp: 2017-12-26 18:41:41
8+
# Timestamp: 2018-02-02 16:32:55
99

1010
FROM debian:stretch
1111

@@ -40,15 +40,15 @@ RUN apt-get update -qq \
4040
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
4141

4242
#------------------------
43-
# Install dcm2niix v1.0.20171017
43+
# Install dcm2niix v1.0.20171215
4444
#------------------------
4545
WORKDIR /tmp
4646
RUN deps='cmake g++ gcc git make pigz zlib1g-dev' \
4747
&& apt-get update -qq && apt-get install -yq --no-install-recommends $deps \
4848
&& apt-get clean \
4949
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
5050
&& mkdir dcm2niix \
51-
&& curl -sSL https://github.com/rordenlab/dcm2niix/tarball/v1.0.20171017 | tar xz -C dcm2niix --strip-components 1 \
51+
&& curl -sSL https://github.com/rordenlab/dcm2niix/tarball/v1.0.20171215 | tar xz -C dcm2niix --strip-components 1 \
5252
&& mkdir dcm2niix/build && cd dcm2niix/build \
5353
&& cmake .. && make \
5454
&& make install \
@@ -127,7 +127,7 @@ RUN echo '{ \
127127
\n [ \
128128
\n "dcm2niix", \
129129
\n { \
130-
\n "version": "v1.0.20171017" \
130+
\n "version": "v1.0.20171215" \
131131
\n } \
132132
\n ], \
133133
\n [ \
@@ -159,6 +159,6 @@ RUN echo '{ \
159159
\n "/neurodocker/startup.sh heudiconv" \
160160
\n ] \
161161
\n ], \
162-
\n "generation_timestamp": "2017-12-26 18:41:41", \
162+
\n "generation_timestamp": "2018-02-02 16:32:55", \
163163
\n "neurodocker_version": "0.3.2" \
164164
\n}' > /neurodocker/neurodocker_specs.json

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 & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
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

11-
from ..bids import (populate_bids_templates, tuneup_bids_json_files)
1213
import inspect
1314
import logging
1415
lgr = logging.getLogger(__name__)
@@ -37,7 +38,7 @@ def _pdb_excepthook(type, value, tb):
3738
# print()
3839
pdb.post_mortem(tb)
3940
else:
40-
lgr.warn(
41+
lgr.warning(
4142
"We cannot setup exception hook since not in interactive mode")
4243

4344
sys.excepthook = _pdb_excepthook
@@ -116,15 +117,15 @@ def get_parser():
116117
parser.add_argument('--version', action='version', version=__version__)
117118
group = parser.add_mutually_exclusive_group()
118119
group.add_argument('-d', '--dicom_dir_template', dest='dicom_dir_template',
119-
help='location of dicomdir that can be indexed with '
120-
'subject id {subject} and session {session}. Tarballs '
121-
'(can be compressed) are supported in addition to '
122-
'directory. All matching tarballs for a subject are '
123-
'extracted and their content processed in a single pass')
120+
help='location of dicomdir that can be indexed with '
121+
'subject id {subject} and session {session}. Tarballs '
122+
'(can be compressed) are supported in addition to '
123+
'directory. All matching tarballs for a subject are '
124+
'extracted and their content processed in a single pass')
124125
group.add_argument('--files', nargs='*',
125-
help='Files (tarballs, dicoms) or directories '
126-
'containing files to process. Cannot be provided if '
127-
'using --dicom_dir_template or --subjects')
126+
help='Files (tarballs, dicoms) or directories '
127+
'containing files to process. Cannot be provided if '
128+
'using --dicom_dir_template or --subjects')
128129
parser.add_argument('-s', '--subjects', dest='subjs', type=str, nargs='*',
129130
help='list of subjects - required for dicom template. '
130131
'If not provided, DICOMS would first be "sorted" and '

heudiconv/convert.py

Lines changed: 26 additions & 11 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,
@@ -68,6 +69,7 @@ def conversion_info(subject, outdir, info, filegroup, ses):
6869
try:
6970
files = filegroup[item]
7071
except KeyError:
72+
PY3 = sys.version_info[0] >= 3
7173
files = filegroup[(str if PY3 else unicode)(item)]
7274
outprefix = template.format(**parameters)
7375
convert_info.append((op.join(outpath, outprefix),
@@ -266,8 +268,8 @@ def convert(items, converter, scaninfo_suffix, custom_callable, with_prov,
266268
tmpdir = tempdirs('dcm2niix')
267269

268270
# run conversion through nipype
269-
res = nipype_convert(item_dicoms, prefix, with_prov, bids,
270-
tmpdir)
271+
res, prov_file = nipype_convert(item_dicoms, prefix, with_prov,
272+
bids, tmpdir)
271273

272274
bids_outfiles = save_converted_files(res, item_dicoms, bids,
273275
outtype, prefix,
@@ -281,13 +283,7 @@ def convert(items, converter, scaninfo_suffix, custom_callable, with_prov,
281283
# Fix up and unify BIDS files
282284
tuneup_bids_json_files(bids_outfiles)
283285

284-
prov_file = prefix + '_prov.ttl' if with_prov else None
285286
if prov_file:
286-
safe_copyfile(op.join(convertnode.base_dir,
287-
convertnode.name,
288-
'provenance.ttl'),
289-
prov_file,
290-
overwrite=overwrite)
291287
prov_files.append(prov_file)
292288

293289
tempdirs.rmtree(tmpdir)
@@ -330,8 +326,17 @@ def convert_dicom(item_dicoms, bids, prefix,
330326
DICOMs to save
331327
bids : bool
332328
Save to BIDS format
333-
sourcedir : string
334-
Path to BIDS output
329+
prefix : string
330+
Conversion outname
331+
outdir : string
332+
Output directory
333+
tempdirs : TempDirs instance
334+
Object to handle temporary directories created
335+
TODO: remove
336+
symlink : bool
337+
Create softlink to DICOMs - if False, create hardlink instead.
338+
overwrite : bool
339+
If True, allows overwriting of previous conversion
335340
336341
Returns
337342
-------
@@ -389,7 +394,17 @@ def nipype_convert(item_dicoms, prefix, with_prov, bids, tmpdir):
389394
else:
390395
convertnode.terminal_output = 'allatonce'
391396
convertnode.inputs.bids_format = bids
392-
return convertnode.run()
397+
eg = convertnode.run()
398+
399+
# prov information
400+
prov_file = prefix + '_prov.ttl' if with_prov else None
401+
if prov_file:
402+
safe_copyfile(op.join(convertnode.base_dir,
403+
convertnode.name,
404+
'provenance.ttl'),
405+
prov_file)
406+
407+
return eg, prov_file
393408

394409

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

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)