Skip to content
This repository has been archived by the owner on Dec 15, 2020. It is now read-only.

Commit

Permalink
Merge pull request #35 from scitran-apps/parker-dev2
Browse files Browse the repository at this point in the history
Parker dev2 [GEAR-142]
  • Loading branch information
lmperry authored Jan 24, 2020
2 parents 3cadf78 + e4902e4 commit 41fb0df
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 4 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.git
.DS_Store
output/
output2/
config.json
work/
input/
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
output/
output2/
config.json
work/
input/
15 changes: 14 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,16 @@ RUN apt-get update -qq \
python \
python-nibabel

# Need to update pydicom
RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && \
python get-pip.py

COPY requirements.txt ./requirements.txt
RUN pip install -r requirements.txt && rm -rf /root/.cache/pip

# Compile DCM2NIIX from source
ENV DCMCOMMIT=54cfd5176cb9f50c1c66d2f2e96beadf60e2edb4
#ENV DCMCOMMIT=f54be46667fce7994d2062e2623d12253c1bd968
RUN curl -#L https://github.com/rordenlab/dcm2niix/archive/$DCMCOMMIT.zip | bsdtar -xf- -C /usr/local
WORKDIR /usr/local/dcm2niix-${DCMCOMMIT}/build
RUN cmake -DUSE_OPENJPEG=ON -MY_DEBUG_GE=ON ../ && \
Expand All @@ -42,9 +50,14 @@ RUN cmake -DUSE_OPENJPEG=ON -MY_DEBUG_GE=ON ../ && \
ENV FLYWHEEL /flywheel/v0
WORKDIR ${FLYWHEEL}

## Copy in fix_dcm_vols
ENV FIXDCMCOMMIT=918ee3327174c3c736e7b3839a556e0a709730c8
RUN curl -#L https://raw.githubusercontent.com/VisionandCognition/NHP-Process-MRI/$FIXDCMCOMMIT/bin/fix_dcm_vols > ${FLYWHEEL}/fix_dcm_vols.py
RUN chmod +x ${FLYWHEEL}/fix_dcm_vols.py

# Add executables
COPY run run_dcm2niix metadata.py coil_combine.py ./
RUN chmod +x run metadata.py coil_combine.py
RUN chmod 777 run metadata.py coil_combine.py fix_dcm_vols.py

# Create Flywheel User
RUN adduser --disabled-password --gecos "Flywheel User" flywheel
Expand Down
11 changes: 8 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
"source": "https://github.com/scitran-apps/dcm2niix",
"license": "BSD-2-Clause",
"flywheel": "0",
"version": "0.7.9_1.0.20190410",
"version": "0.7.10_1.0.20190410",
"custom": {
"docker-image": "scitran/dcm2niix:0.7.9_1.0.20190410",
"docker-image": "scitran/dcm2niix:0.7.10_1.0.20190410",
"flywheel": {
"uid": 1000,
"gid": 1000,
"suite": "SciTran"
},
"gear-builder": {
"category": "converter",
"image": "scitran/dcm2niix:0.7.8_1.0.20190410"
"image": "scitran/dcm2niix:0.7.10_1.0.20190410"
}
},
"config": {
Expand Down Expand Up @@ -113,6 +113,11 @@
"description": "For sequences with individual coil data, saved as individual volumes, this option will save a NIfTI file with ONLY the combined coil data (i.e., the last volume). Default=False. Warning: We make no effort to check for independent coil data, we simply trust that if you have selcted this option you know what you are asking for.",
"type": "boolean",
"default": false
},
"remove_incomplete_volumes": {
"description": "Some 4D scans can be aborted mid-acquisition after any number of complete volume acquisitions. The final volume may be incomplete, which causes problems during dcm2niix reconstruction. Check this to scan the dicom archive before reconstruction and remove the files associated with the trailing incomplete volume. All other volumes will be reconstructed as normal. ",
"type": "boolean",
"default": false
}
},
"inputs": {
Expand Down
Empty file modified metadata.py
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pydicom==1.3.0
Empty file modified run
100644 → 100755
Empty file.
43 changes: 43 additions & 0 deletions run_dcm2niix
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ convert_only_series="$(parse_config 'convert_only_series')"
lossless_scaling="$(parse_config 'lossless_scaling')"
ignore_errors="$(parse_config 'ignore_errors')"
coil_combine="$(parse_config 'coil_combine')"
remove_incomplete_volumes="$(parse_config 'remove_incomplete_volumes')"


##############################################################################
Expand Down Expand Up @@ -162,6 +163,48 @@ else
dicom_input=$INPUT_DIR
fi


##############################################################################################
# Check to see if we need to remove dicoms from an incomplete volume for proper reconstruction
if [[ ${remove_incomplete_volumes} == "true" ]]; then
echo $dicom_input

# Run the python script
echo "$CONTAINER Running incomplete volume correction"

echo dicoms before:
ls ${dicom_input}/*.dcm -1 | wc -l


python $FLYWHEEL_BASE/fix_dcm_vols.py ${dicom_input}
echo "$CONTAINER Complete"
# If it found missing volumes and worked succesfully, there will be a new directory in the original dicom input dir
# called "corrected_dcm"
echo "$CONTAINER Checking for files"
corrected_output=${dicom_input}/orphan_dcm
if [[ -d $corrected_output ]]; then
echo "$CONTAINER removed incomplete volumes from scan"
# For the sake of flywheel's naming, remove the orphan dcms
rm -rf ${dicom_input}/orphan_dcm

# and remove any DCM's still in the original directory (should be zero if python code works correctly)
rm ${dicom_input}/*.dcm

# move back all the corrected images to the original directory
mv ${dicom_input}/corrected_dcm/*.dcm ${dicom_input}

# Remove the corrected directory
rm -rf ${dicom_input}/corrected_dcm

# Give report of dicoms after.
echo dicoms after:
ls ${dicom_input}/*.dcm -1 | wc -l

else
echo "$CONTAINER Attempted to run incomplete volume correction, but no correction was made"
fi
fi

echo -e "$CONTAINER $dicom_input"

##############################################################################
Expand Down

0 comments on commit 41fb0df

Please sign in to comment.