Skip to content

Commit d3b7077

Browse files
authored
Merge pull request #209 from mgxd/fix/docker
fail descriptively when cmdline specification is wrong redo conversion if heuristic has changed
2 parents ca57a32 + bbeaec0 commit d3b7077

File tree

6 files changed

+90
-62
lines changed

6 files changed

+90
-62
lines changed

Dockerfile

Lines changed: 49 additions & 48 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: 2018-02-02 16:32:55
8+
# Timestamp: 2018-05-14 16:30:58
99

1010
FROM debian:stretch
1111

@@ -32,27 +32,48 @@ RUN apt-get update -qq && apt-get install -yq --no-install-recommends \
3232
&& chmod -R 777 /neurodocker && chmod a+s /neurodocker
3333
ENTRYPOINT ["/neurodocker/startup.sh"]
3434

35-
RUN apt-get update -qq \
36-
&& apt-get install -y -q --no-install-recommends git \
37-
gcc \
38-
pigz \
39-
&& apt-get clean \
40-
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
41-
4235
#------------------------
43-
# Install dcm2niix v1.0.20171215
36+
# Install dcm2niix v1.0.20180328
4437
#------------------------
4538
WORKDIR /tmp
4639
RUN deps='cmake g++ gcc git make pigz zlib1g-dev' \
4740
&& apt-get update -qq && apt-get install -yq --no-install-recommends $deps \
4841
&& apt-get clean \
4942
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
5043
&& mkdir dcm2niix \
51-
&& curl -sSL https://github.com/rordenlab/dcm2niix/tarball/v1.0.20171215 | tar xz -C dcm2niix --strip-components 1 \
44+
&& curl -sSL https://github.com/rordenlab/dcm2niix/tarball/v1.0.20180328 | tar xz -C dcm2niix --strip-components 1 \
5245
&& mkdir dcm2niix/build && cd dcm2niix/build \
5346
&& cmake .. && make \
5447
&& make install \
55-
&& rm -rf /tmp/*
48+
&& rm -rf /tmp/* \
49+
&& apt-get purge -y --auto-remove $deps
50+
51+
#--------------------------------------------------
52+
# Add NeuroDebian repository
53+
# Please note that some packages downloaded through
54+
# NeuroDebian may have restrictive licenses.
55+
#--------------------------------------------------
56+
RUN apt-get update -qq && apt-get install -yq --no-install-recommends dirmngr gnupg \
57+
&& apt-get clean \
58+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
59+
&& curl -sSL http://neuro.debian.net/lists/stretch.us-nh.full \
60+
> /etc/apt/sources.list.d/neurodebian.sources.list \
61+
&& curl -sSL https://dl.dropbox.com/s/zxs209o955q6vkg/neurodebian.gpg \
62+
| apt-key add - \
63+
&& (apt-key adv --refresh-keys --keyserver hkp://pool.sks-keyservers.net:80 0xA5D32F012649A5A9 || true) \
64+
&& apt-get update
65+
66+
# Install NeuroDebian packages
67+
RUN apt-get update -qq && apt-get install -yq --no-install-recommends git-annex-standalone \
68+
&& apt-get clean \
69+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
70+
71+
RUN apt-get update -qq \
72+
&& apt-get install -y -q --no-install-recommends git \
73+
gcc \
74+
pigz \
75+
&& apt-get clean \
76+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
5677

5778
COPY [".", "/src/heudiconv"]
5879

@@ -83,26 +104,6 @@ RUN conda create -y -q --name neuro python=2 \
83104
&& sync \
84105
&& sed -i '$isource activate neuro' $ND_ENTRYPOINT
85106

86-
#--------------------------------------------------
87-
# Add NeuroDebian repository
88-
# Please note that some packages downloaded through
89-
# NeuroDebian may have restrictive licenses.
90-
#--------------------------------------------------
91-
RUN apt-get update -qq && apt-get install -yq --no-install-recommends dirmngr gnupg \
92-
&& apt-get clean \
93-
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
94-
&& curl -sSL http://neuro.debian.net/lists/stretch.us-nh.full \
95-
> /etc/apt/sources.list.d/neurodebian.sources.list \
96-
&& curl -sSL https://dl.dropbox.com/s/zxs209o955q6vkg/neurodebian.gpg \
97-
| apt-key add - \
98-
&& (apt-key adv --refresh-keys --keyserver hkp://pool.sks-keyservers.net:80 0xA5D32F012649A5A9 || true) \
99-
&& apt-get update
100-
101-
# Install NeuroDebian packages
102-
RUN apt-get update -qq && apt-get install -yq --no-install-recommends git-annex-standalone \
103-
&& apt-get clean \
104-
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
105-
106107
ENTRYPOINT ["/neurodocker/startup.sh", "heudiconv"]
107108

108109
#--------------------------------------
@@ -117,6 +118,20 @@ RUN echo '{ \
117118
\n "debian:stretch" \
118119
\n ], \
119120
\n [ \
121+
\n "dcm2niix", \
122+
\n { \
123+
\n "version": "v1.0.20180328" \
124+
\n } \
125+
\n ], \
126+
\n [ \
127+
\n "neurodebian", \
128+
\n { \
129+
\n "os_codename": "stretch", \
130+
\n "download_server": "usa-nh", \
131+
\n "pkgs": "git-annex-standalone" \
132+
\n } \
133+
\n ], \
134+
\n [ \
120135
\n "install", \
121136
\n [ \
122137
\n "git", \
@@ -125,12 +140,6 @@ RUN echo '{ \
125140
\n ] \
126141
\n ], \
127142
\n [ \
128-
\n "dcm2niix", \
129-
\n { \
130-
\n "version": "v1.0.20171215" \
131-
\n } \
132-
\n ], \
133-
\n [ \
134143
\n "copy", \
135144
\n [ \
136145
\n ".", \
@@ -142,23 +151,15 @@ RUN echo '{ \
142151
\n { \
143152
\n "env_name": "neuro", \
144153
\n "conda_install": "python=2 traits=4.6.0", \
145-
\n "pip_install": "https://github.com/moloney/dcmstack/tarball/master /src/heudiconv[all]", \
146-
\n "activate": true \
147-
\n } \
148-
\n ], \
149-
\n [ \
150-
\n "neurodebian", \
151-
\n { \
152-
\n "os_codename": "stretch", \
153-
\n "download_server": "usa-nh", \
154-
\n "pkgs": "git-annex-standalone" \
154+
\n "activate": true, \
155+
\n "pip_install": "https://github.com/moloney/dcmstack/tarball/master /src/heudiconv[all]" \
155156
\n } \
156157
\n ], \
157158
\n [ \
158159
\n "entrypoint", \
159160
\n "/neurodocker/startup.sh heudiconv" \
160161
\n ] \
161162
\n ], \
162-
\n "generation_timestamp": "2018-02-02 16:32:55", \
163+
\n "generation_timestamp": "2018-05-14 16:30:58", \
163164
\n "neurodocker_version": "0.3.2" \
164165
\n}' > /neurodocker/neurodocker_specs.json

heudiconv/cli/run.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ def process_extra_commands(outdir, args):
9999
def main(argv=None):
100100
parser = get_parser()
101101
args = parser.parse_args(argv)
102+
# exit if nothing to be done
103+
if not args.files and not args.dicom_dir_template and not args.command:
104+
lgr.warning("Nothing to be done - displaying usage help")
105+
parser.print_help()
106+
sys.exit(1)
102107
# To be done asap so anything random is deterministic
103108
if args.random_seed is not None:
104109
import random
@@ -237,6 +242,9 @@ def process_args(args):
237242
#
238243
# Load heuristic -- better do it asap to make sure it loads correctly
239244
#
245+
if not args.heuristic:
246+
raise RuntimeError("No heuristic specified - add to arguments and rerun")
247+
240248
heuristic = load_heuristic(args.heuristic)
241249

242250
study_sessions = get_study_sessions(args.dicom_dir_template, args.files,

heudiconv/convert.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ def prep_conversion(sid, dicoms, outdir, heuristic, converter, anon_sid,
115115

116116
# if conversion table(s) do not exist -- we need to prepare them
117117
# (the *prepare* stage in https://github.com/nipy/heudiconv/issues/134)
118+
# if overwrite - recalculate this anyways
118119
reuse_conversion_table = op.exists(edit_file)
119120
# We also might need to redo it if changes in the heuristic file
120121
# detected
@@ -125,17 +126,15 @@ def prep_conversion(sid, dicoms, outdir, heuristic, converter, anon_sid,
125126
# 1. add a test
126127
# 2. possibly extract into a dedicated function for easier logic flow here
127128
# and a dedicated unittest
128-
if not reuse_conversion_table and \
129-
op.exists(target_heuristic_filename) and \
130-
file_md5sum(target_heuristic_filename) != file_md5sum(heuristic.filename):
129+
if (op.exists(target_heuristic_filename) and
130+
file_md5sum(target_heuristic_filename) != file_md5sum(heuristic.filename)):
131+
# remake conversion table
131132
reuse_conversion_table = False
132133
lgr.info(
133134
"Will not reuse existing conversion table files because heuristic "
134135
"has changed"
135136
)
136137

137-
# MG - maybe add an option to force rerun?
138-
# related issue : https://github.com/nipy/heudiconv/issues/84
139138
if reuse_conversion_table:
140139
lgr.info("Reloading existing filegroup.json "
141140
"because %s exists", edit_file)

heudiconv/external/pydicom.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
# 1.0.0 of pydicom renamed module from dicom to pydicom
66
try:
7-
# for pydicom < 1.0
8-
import dicom as dcm
9-
except ImportError:
107
# pydicom >= 1.0
118
import pydicom as dcm
9+
except ImportError:
10+
# for pydicom < 1.0
11+
import dicom as dcm

tests/test_heuristics.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,17 @@
2424

2525
# this will fail if not in project's root directory
2626
def test_smoke_convertall(tmpdir):
27-
runner(
28-
("-f convertall -c dcm2niix -o %s -b --datalad "
29-
"-s fmap_acq-3mm -d %s/{subject}/*"
30-
% (tmpdir, TESTS_DATA_PATH)
31-
).split(' ')
32-
)
27+
args = ("-c dcm2niix -o %s -b --datalad "
28+
"-s fmap_acq-3mm -d %s/{subject}/*"
29+
% (tmpdir, TESTS_DATA_PATH)
30+
).split(' ')
31+
32+
# complain if no heurisitic
33+
with pytest.raises(RuntimeError):
34+
runner(args)
35+
36+
args.extend(['-f', 'convertall'])
37+
runner(args)
3338

3439

3540
@pytest.mark.parametrize('heuristic', ['reproin', 'convertall'])

utils/gen-docker-image.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
set -eu
4+
5+
VER=$(grep -Po '(?<=^__version__ = ).*' ../heudiconv/info.py | sed 's/"//g')
6+
7+
docker run --rm kaczmarj/neurodocker:v0.3.2 generate -b debian:stretch -p apt \
8+
--dcm2niix version=v1.0.20180328 \
9+
--neurodebian os_codename=stretch download_server=usa-nh pkgs=git-annex-standalone \
10+
--install git gcc pigz \
11+
--copy . /src/heudiconv \
12+
--miniconda env_name=neuro conda_install="python=2 traits=4.6.0" activate=True \
13+
pip_install="https://github.com/moloney/dcmstack/tarball/master /src/heudiconv[all]" \
14+
--entrypoint "/neurodocker/startup.sh heudiconv" \
15+
> ../Dockerfile

0 commit comments

Comments
 (0)