Skip to content
Permalink
Browse files

Hotfix

  • Loading branch information
lukassnoek committed Oct 8, 2019
1 parent 7cbb4aa commit 67ece8df942683cfab6d8b5194ef4eb41e5a0384
Showing with 59 additions and 37 deletions.
  1. +33 −26 Dockerfile
  2. +4 −0 bidsify/main.py
  3. +19 −8 bidsify/mri2nifti.py
  4. +1 −1 bidsify/version.py
  5. +2 −2 generate_dockerfile
@@ -1,5 +1,6 @@
# Generated by Neurodocker version 0.4.3-2-g01cdd22
# Timestamp: 2019-02-28 15:29:24 UTC
# Your version: 0.6.0 Latest version: 0.6.0
# Generated by Neurodocker version 0.6.0
# Timestamp: 2019-10-08 15:07:42 UTC
#
# Thank you for using Neurodocker. If you discover any issues
# or ways to improve this software, please submit an issue or
@@ -24,7 +25,7 @@ RUN export ND_ENTRYPOINT="/neurodocker/startup.sh" \
locales \
unzip \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
&& rm -rf /var/lib/apt/lists/* \
&& sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen \
&& dpkg-reconfigure --frontend=noninteractive locales \
&& update-locale LANG="en_US.UTF-8" \
@@ -33,6 +34,7 @@ RUN export ND_ENTRYPOINT="/neurodocker/startup.sh" \
&& if [ ! -f "$ND_ENTRYPOINT" ]; then \
echo '#!/usr/bin/env bash' >> "$ND_ENTRYPOINT" \
&& echo 'set -e' >> "$ND_ENTRYPOINT" \
&& echo 'export USER="${USER:=`whoami`}"' >> "$ND_ENTRYPOINT" \
&& echo 'if [ -n "$1" ]; then "$@"; else /usr/bin/env bash; fi' >> "$ND_ENTRYPOINT"; \
fi \
&& chmod -R 777 /neurodocker && chmod a+s /neurodocker
@@ -43,10 +45,10 @@ RUN apt-get update -qq \
&& apt-get install -y -q --no-install-recommends \
git \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
&& rm -rf /var/lib/apt/lists/*

ENV FSLDIR="/opt/fsl-5.0.10" \
PATH="/opt/fsl-5.0.10/bin:$PATH"
ENV FSLDIR="/opt/fsl-6.0.1" \
PATH="/opt/fsl-6.0.1/bin:$PATH"
RUN apt-get update -qq \
&& apt-get install -y -q --no-install-recommends \
bc \
@@ -55,29 +57,34 @@ RUN apt-get update -qq \
libfontconfig1 \
libfreetype6 \
libgl1-mesa-dev \
libgl1-mesa-dri \
libglu1-mesa-dev \
libgomp1 \
libice6 \
libmng1 \
libxcursor1 \
libxft2 \
libxinerama1 \
libxrandr2 \
libxrender1 \
libxt6 \
sudo \
wget \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
&& rm -rf /var/lib/apt/lists/* \
&& echo "Downloading FSL ..." \
&& mkdir -p /opt/fsl-5.0.10 \
&& curl -fsSL --retry 5 https://fsl.fmrib.ox.ac.uk/fsldownloads/fsl-5.0.10-centos6_64.tar.gz \
| tar -xz -C /opt/fsl-5.0.10 --strip-components 1 \
&& mkdir -p /opt/fsl-6.0.1 \
&& curl -fsSL --retry 5 https://fsl.fmrib.ox.ac.uk/fsldownloads/fsl-6.0.1-centos6_64.tar.gz \
| tar -xz -C /opt/fsl-6.0.1 --strip-components 1 \
&& sed -i '$iecho Some packages in this Docker container are non-free' $ND_ENTRYPOINT \
&& sed -i '$iecho If you are considering commercial use of this container, please consult the relevant license:' $ND_ENTRYPOINT \
&& sed -i '$iecho https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/Licence' $ND_ENTRYPOINT \
&& sed -i '$isource $FSLDIR/etc/fslconf/fsl.sh' $ND_ENTRYPOINT \
&& echo "Installing FSL conda environment ..." \
&& bash /opt/fsl-5.0.10/etc/fslconf/fslpython_install.sh -f /opt/fsl-5.0.10
&& bash /opt/fsl-6.0.1/etc/fslconf/fslpython_install.sh -f /opt/fsl-6.0.1 \
&& echo "Downgrading deprecation module per https://github.com/kaczmarj/neurodocker/issues/271#issuecomment-514523420" \
&& /opt/fsl-6.0.1/fslpython/bin/conda install -n fslpython -c conda-forge -y deprecation==1.* \
&& echo "Removing bundled with FSLeyes libz likely incompatible with the one from OS" \
&& rm -f /opt/fsl-6.0.1/bin/FSLeyes/libz.so.1

ENV PATH="/opt/dcm2niix-master/bin:$PATH"
RUN apt-get update -qq \
@@ -90,7 +97,7 @@ RUN apt-get update -qq \
pigz \
zlib1g-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
&& rm -rf /var/lib/apt/lists/* \
&& git clone https://github.com/rordenlab/dcm2niix /tmp/dcm2niix \
&& mkdir /tmp/dcm2niix/build \
&& cd /tmp/dcm2niix/build \
@@ -111,20 +118,20 @@ RUN export PATH="/opt/miniconda-latest/bin:$PATH" \
&& conda config --system --prepend channels conda-forge \
&& conda config --system --set auto_update_conda false \
&& conda config --system --set show_channel_urls true \
&& sync && conda clean -tipsy && sync \
&& sync && conda clean --all && sync \
&& conda create -y -q --name neuro \
&& conda install -y -q --name neuro \
'python=3.6' \
'numpy' \
'pandas' \
&& sync && conda clean -tipsy && sync \
"python=3.6" \
"numpy" \
"pandas" \
&& sync && conda clean --all && sync \
&& bash -c "source activate neuro \
&& pip install --no-cache-dir \
'nipype' \
'git+https://github.com/poldracklab/pydeface.git@master' \
'pyyaml' \
'nibabel' \
'joblib'" \
"nipype" \
"git+https://github.com/poldracklab/pydeface.git@master" \
"pyyaml" \
"nibabel" \
"joblib"" \
&& rm -rf ~/.cache/pip/* \
&& sync \
&& sed -i '$isource activate neuro' $ND_ENTRYPOINT
@@ -134,15 +141,15 @@ RUN apt-get update -qq \
gnupg2 \
vim \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
&& rm -rf /var/lib/apt/lists/*

RUN curl --silent --location https://deb.nodesource.com/setup_10.x | bash -

RUN apt-get update -qq \
&& apt-get install -y -q --no-install-recommends \
nodejs \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
&& rm -rf /var/lib/apt/lists/*

RUN npm install -g bids-validator

@@ -172,7 +179,7 @@ RUN echo '{ \
\n [ \
\n "fsl", \
\n { \
\n "version": "5.0.10" \
\n "version": "6.0.1" \
\n } \
\n ], \
\n [ \
@@ -215,6 +215,9 @@ def bidsify(cfg_path, directory, out_dir, validate):
if validate:
bids_validator_log = op.join(out_dir,
'bids_validator_log.txt')
if op.isfile(bids_validator_log):
os.remove(bids_validator_log)

cmd = ['bids-validator', '--ignoreNiftiHeaders', out_dir]

rs = _run_cmd(cmd, outfile=bids_validator_log, verbose=True)
@@ -299,6 +302,7 @@ def _process_directory(cdir, out_dir, cfg, is_sess=False):
if 'spinoza_cfg' in op.basename(cfg['orig_cfg_path']):
dtype_elements = _infer_dtype_elements(this_out_dir, cfg)
cfg.update(dtype_elements)
print(json.dumps(cfg, indent = 4))

# Check which datatypes (dtypes) are available (func, anat, fmap, dwi)
cfg['data_types'] = [c for c in cfg.keys() if c in DTYPES]
@@ -106,6 +106,7 @@ def _rename_phasediff_files(directory, cfg, idf):
magnitude_jsons = glob(op.join(directory, '*_magnitude1.json'))
[os.remove(tf) for tf in magnitude_jsons]


def _fix_header_manually_stopped_scan(par):

with open(par, 'r') as f:
@@ -120,20 +121,30 @@ def _fix_header_manually_stopped_scan(par):

if not found:
raise ValueError("Could not determine number of slices from PAR header (%s)!" % par)

found = False
for line_nr_of_dyns, line in enumerate(lines):
found = 'Max. number of dynamics' in line
if found:
n_dyns = int(line.split(':')[-1].strip().replace('\n', ''))
break

if not found:
raise ValueError("Could not determine number of dynamics from PAR header (%s)!" % par)

if n_dyns == 1:
# Not an fMRI file! skip
return

if not found:
raise ValueError("Could not determine number of slices from PAR header (%s)!" % par)
found = False
for line in lines:
found = 'Max. number of echoes' in line
if found:
n_echoes = int(line.split(':')[-1].strip().replace('\n', ''))
break

# Multiecho fMRI has n_dyns * n_echoes volumes in the 4th dim
n_vols = int(n_dyns * n_echoes)

found = False
for idx_start_slices, line in enumerate(lines):
@@ -144,20 +155,20 @@ def _fix_header_manually_stopped_scan(par):

idx_stop_slices = len(lines) - 2
slices = lines[idx_start_slices:idx_stop_slices]
actual_n_dyns = len(slices) / n_slices
actual_n_vols = len(slices) / n_slices

if actual_n_dyns != n_dyns:
print("Found %.3f dyns (%i slices) for file %s, but expected %i dyns (%i slices);"
if actual_n_vols != n_vols:
print("Found %.3f vols (%i slices) for file %s, but expected %i dyns (%i slices);"
" going to try to fix it by removing slices from the PAR header ..." %
(actual_n_dyns, len(slices), op.basename(par), n_dyns, n_dyns*n_slices))
(actual_n_vols, len(slices), op.basename(par), n_vols, n_vols*n_slices))

lines_to_remove = len(slices) % n_slices
if lines_to_remove != 0:
for i in range(lines_to_remove):
lines.pop(idx_stop_slices - (i+1))

slices = lines[idx_start_slices:(idx_stop_slices - lines_to_remove)]
actual_n_dyns = len(slices) / n_slices
actual_n_dyns = len(slices) / n_slices / n_echoes
if not actual_n_dyns.is_integer():
print("Couldn't fix PAR header (probably multiple randomly dropped frames)")
return
@@ -4,7 +4,7 @@
# Format expected by setup.py and doc/source/conf.py: string of form "X.Y.Z"
_version_major = 0
_version_minor = 3
_version_micro = 5 # use '' for first of series, number for 1 and above
_version_micro = 6 # use '' for first of series, number for 1 and above
# _version_extra = 'dev'
_version_extra = '' # Uncomment this for full releases

@@ -1,8 +1,8 @@
#!/bin/bash
docker run --rm kaczmarj/neurodocker:0.4.3 generate docker \
docker run --rm kaczmarj/neurodocker:0.6.0 generate docker \
--base debian:stretch --pkg-manager apt \
--install git \
--fsl version=5.0.10 \
--fsl version=6.0.1 \
--dcm2niix version=master method=source \
--miniconda create_env=neuro \
conda_install="python=3.6 numpy pandas" \

0 comments on commit 67ece8d

Please sign in to comment.
You can’t perform that action at this time.