Skip to content

Commit b0729cf

Browse files
committed
v0.0.1: Initial working version of dtiInit Gear.
1 parent 7bade92 commit b0729cf

8 files changed

Lines changed: 284 additions & 2 deletions

File tree

Dockerfile

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Create Flywheel Gear that can run dtiInit
2+
# See https://github.com/vistalab/vistasoft/tree/master/mrDiffusion/dtiInit/standalone for source code
3+
4+
# Start with the Matlab r2013b runtime container
5+
FROM vistalab/mcr-v82
6+
MAINTAINER Michael Perry <lmperry@stanford.edu>
7+
8+
# Install dependencies
9+
RUN apt-get update \
10+
&& apt-get install -y \
11+
zip \
12+
gzip \
13+
python
14+
15+
# ADD the dtiInit Matlab Stand-Alone (MSA) into the container.
16+
ADD https://github.com/vistalab/vistasoft/raw/97aa8a83ea1e89a900e4c6597a404d84f7390b12/mrDiffusion/dtiInit/standalone/executables/dtiInit_glnxa64_v82 /usr/local/bin/dtiInit
17+
18+
# Add bet2 (FSL) to the container
19+
ADD https://github.com/vistalab/vistasoft/raw/f1e7c57bb01bd281be6a8b93cc162994a1307b86/mrAnatomy/Segment/bet2 /usr/local/bin/
20+
21+
# Add the MNI_EPI template and JSON schema files to the container
22+
ADD https://github.com/vistalab/vistasoft/raw/f1e7c57bb01bd281be6a8b93cc162994a1307b86/mrDiffusion/templates/MNI_EPI.nii.gz /templates/
23+
ADD https://github.com/vistalab/vistasoft/raw/97aa8a83ea1e89a900e4c6597a404d84f7390b12/mrDiffusion/dtiInit/standalone/dtiInitStandAloneJsonSchema.json /templates/
24+
25+
# Copy the help text to display when no args are passed in.
26+
COPY help.txt /opt/help.txt
27+
28+
# Ensure that the executable files are executable
29+
RUN chmod +x /usr/local/bin/bet2 && chmod +x /usr/local/bin/dtiInit
30+
31+
# Configure environment variables for bet2
32+
ENV FSLOUTPUTTYPE NIFTI_GZ
33+
34+
# Make directory for flywheel spec (v0)
35+
ENV FLYWHEEL /flywheel/v0
36+
RUN mkdir -p ${FLYWHEEL}
37+
38+
# Copy and configure run script and metadata code
39+
COPY run ${FLYWHEEL}/run
40+
RUN chmod +x ${FLYWHEEL}/run
41+
COPY manifest.json ${FLYWHEEL}/manifest.json
42+
ADD https://raw.githubusercontent.com/scitran/utilities/daf5ebc7dac6dde1941ca2a6588cb6033750e38c/metadata_from_gear_output.py ${FLYWHEEL}/metadata_create.py
43+
RUN chmod +x ${FLYWHEEL}/metadata_create.py
44+
45+
# Configure entrypoint
46+
ENTRYPOINT ["/flywheel/v0/run"]
47+

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
# dtiinit
2-
Vistasoft mrDiffusion preprocessing pipeline
1+
## scitran-apps/dtiinit
2+
3+
Build context for a [Flywheel Gear](https://github.com/flywheel-io/gears/tree/master/spec) that can preprocess diffusion data using the Vistasoft [dtiInit](https://github.com/vistalab/vistasoft/tree/master/mrDiffusion/dtiInit) pipeline.
4+

build.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
# Builds the gear/container
3+
# The container can be exported using the export.sh script
4+
5+
GEAR=scitran-apps/dtiinit
6+
7+
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
8+
9+
docker build --no-cache --tag $GEAR $DIR

dtiinit.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"input_dir": "/flywheel/v0/input",
3+
"output_dir": "/flywheel/v0/output",
4+
"dwi_file": "",
5+
"bvec_file": "",
6+
"bval_file": "",
7+
"t1_file": "",
8+
"params":
9+
{
10+
"bvalue": "",
11+
"gradDirsCode": "",
12+
"clobber": 0,
13+
"dt6BaseName": "",
14+
"flipLrApFlag": 0,
15+
"numBootStrapSamples": 500,
16+
"fitMethod": "ls",
17+
"nStep": 50,
18+
"eddyCorrect": 1,
19+
"excludeVols": "",
20+
"bsplineInterpFlag": 0,
21+
"phaseEncodeDir": "",
22+
"dwOutMm": [2, 2, 2],
23+
"rotateBvecsWithRx": 0,
24+
"rotateBvecsWithCanXform": 0,
25+
"bvecsFile": "",
26+
"bvalsFile": "",
27+
"noiseCalcMethod": "b0",
28+
"outDir": ""
29+
}
30+
}
31+

export.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
# Exports the container in the cwd.
3+
# The container can be exported once it's started with
4+
gear=dtiinit
5+
version=0.0.1
6+
outname=$gear-$version.tar
7+
container=$gear
8+
image=scitran-apps/$gear
9+
10+
# Check if input was passed in.
11+
if [[ -n $1 ]]; then
12+
outname=$1
13+
fi
14+
15+
docker run --name=$container --entrypoint=/bin/true $image
16+
docker export -o $outname $container
17+
docker rm $container

help.txt

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
%
2+
% Read a JSON object, a JSON file, or a directory containing a json file
3+
% and run dtiInit inside of a docker container (scitran-apps/dtiinit).
4+
%
5+
%
6+
% INPUTS:
7+
% json - a JSON string, a JSON file, or a directory containing a json
8+
% file, in the following format (Note that 'input_dir' and
9+
% 'output_dir' are the only REQUIRED inputs)
10+
%
11+
% OUTPUTS:
12+
% A docker run produces a zip file containing all of the outputs
13+
% from the algorithm. The name of the output zip file is:
14+
% 'dtiInit[date-time].zip'
15+
%
16+
%
17+
% JSON SCHEMA:
18+
% Below is an example JSON file with the defaults show for 'params'.
19+
% See dtiInitParams.m for more info regarding params. Note that
20+
% "input_dir" and "output_dir" are required and must be in the
21+
% context of the container.
22+
%
23+
% {
24+
% "input_dir": "/input",
25+
% "output_dir": "/output",
26+
% "dwi_file": "",
27+
% "bvec_file": "",
28+
% "bval_file": "",
29+
% "t1_file": "",
30+
% "params":
31+
% {
32+
% "bvalue": "",
33+
% "gradDirsCode": "",
34+
% "clobber": 0,
35+
% "dt6BaseName": "",
36+
% "flipLrApFlag": 0,
37+
% "numBootStrapSamples": 500,
38+
% "fitMethod": "ls",
39+
% "nStep": 50,
40+
% "eddyCorrect": 1,
41+
% "excludeVols": "",
42+
% "bsplineInterpFlag": 0,
43+
% "phaseEncodeDir": "",
44+
% "dwOutMm": [2, 2, 2],
45+
% "rotateBvecsWithRx": 0,
46+
% "rotateBvecsWithCanXform": 0,
47+
% "bvecsFile": "",
48+
% "bvalsFile": "",
49+
% "noiseCalcMethod": "b0",
50+
% "outDir": "/output/"
51+
% }
52+
% }
53+
%
54+
%
55+
% REQUIRED INPUTS:
56+
% 'input_dir' and 'output_dir' are the only required inputs.
57+
%
58+
%
59+
% HELP:
60+
% If 'help', '-h', '--help', or nothing (nargin==0), is passed in
61+
% this help will be displayed.
62+
%
63+
%
64+
% USAGE:
65+
% Pass in a JSON file, a JSON text string, or a path to a directory
66+
% containing a JSON file to the docker container to initiate a
67+
% dtiInit processing run (see INPUT section for JSON schema):
68+
%
69+
% % Using a JSON file
70+
% docker run --rm -ti -v `pwd`/input:/input -v `pwd`/output:/output scitran-apps/dtiinit /input/<JSON_filename>.json
71+
%
72+
% % Using a JSON string
73+
% docker run --rm -ti -v `pwd`/input:/input -v `pwd`/output:/output scitran-apps/dtiinit '{"input_dir":"/input", "output_dir": "/output"}'
74+
%
75+
% % Using a directory (in the container), containing a JSON (.json)
76+
% docker run --rm -ti -v `pwd`/input:/input -v `pwd`/output:/output scitran-apps/dtiinit /input/
77+
%
78+
%
79+
%

manifest.json

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"name": "dtiinit",
3+
"label": "Diffusion Data Initialization Pipeline",
4+
"description": "dtiInit (DTI Initialization) runs the VISTASOFT/mrDiffusion pre-processing pipeline on raw DWI data. See: http://white.stanford.edu/newlm/index.php/DTI_Preprocessing for more information regarding the pipeline. This dtiInit gear will output motion-corrected diffusion data (nifti, bval, bvecs) aligned to the first b0 image in the acquisition. It will also calculate FA, MD, RD, and AD maps. Tensors, vector RGB, brain mask, white-matter mask, and white-matter probability maps will also be output. All outputs will be included in a zip file.",
5+
"author": "Michael Perry <lmperry@stanford.edu>",
6+
"url": "https://github.com/vistalab/vistasoft/wiki",
7+
"source": "https://github.com/scitran-apps/dtiinit",
8+
"license": "GPL-2.0",
9+
"flywheel": "0",
10+
"version": "0.0.1",
11+
"config": {
12+
},
13+
"inputs": {
14+
"nifti": {
15+
"base": "file",
16+
"type": {
17+
"enum": [
18+
"nifti"
19+
]
20+
}
21+
},
22+
"bvec": {
23+
"base": "file",
24+
"type": {
25+
"enum": [
26+
"bvec"
27+
]
28+
}
29+
},
30+
"bval": {
31+
"base": "file",
32+
"type": {
33+
"enum": [
34+
"bval"
35+
]
36+
}
37+
},
38+
"json": {
39+
"base": "file",
40+
"type": {
41+
"enum": [
42+
"json"
43+
]
44+
}
45+
}
46+
}
47+
}

run

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#! /bin/bash
2+
#
3+
# Run dtiinit Gear
4+
# Built to flywheel-v0 spec.
5+
#
6+
CONTAINER="[scitran-apps/dtiinit]"
7+
8+
# Configure the ENV
9+
export FSLOUTPUTTYPE=NIFTI_GZ
10+
export LD_LIBRARY_PATH=/opt/mcr/v82/runtime/glnxa64:/opt/mcr/v82/bin/glnxa64:/opt/mcr/v82/sys/os/glnxa64:/opt/mcr/v82/sys/java/jre/glnxa64/jre/lib/amd64/native_threads:/opt/mcr/v82/sys/java/jre/glnxa64/jre/lib/amd64/server:/opt/mcr/v82/sys/java/jre/glnxa64/jre/lib/amd64:$LD_LIBRARY_PATH
11+
export XAPPLRESDIR=/opt/mcr/v82/X11/app-defaults
12+
13+
FLYWHEEL_BASE=/flywheel/v0
14+
OUTPUT_DIR=$FLYWHEEL_BASE/output
15+
NIFTI_DIR=$FLYWHEEL_BASE/nifti
16+
BVEC_DIR=$FLYWHEEL_BASE/bvec
17+
BVAL_DIR=$FLYWHEEL_BASE/bval
18+
JSON_DIR=$FLYWHEEL_BASE/json
19+
WORK_DIR=$FLYWHEEL_BASE/input
20+
21+
echo -e "$CONTAINER Initiated"
22+
23+
if [[ ! -d "$OUTPUT_DIR" ]]
24+
then
25+
echo "$CONTAINER $OUTPUT_DIR not found!"
26+
exit 1
27+
fi
28+
29+
# Do the work
30+
mkdir $WORK_DIR
31+
cp $NIFTI_DIR/* $BVEC_DIR/* $BVAL_DIR/* $JSON_DIR/* $WORK_DIR
32+
/usr/local/bin/dtiInit $WORK_DIR 2>&1 | tee $OUTPUT_DIR/dtiinit-log.txt
33+
34+
# Get a list of the files in the output directory
35+
outputs=$(find $OUTPUT_DIR/* -maxdepth 0 -type f)
36+
37+
# If outputs exist, generate metadata, and exit
38+
if [[ -z $outputs ]]
39+
then
40+
echo "$CONTAINER No results found in output directory... Exiting"
41+
exit 1
42+
else
43+
cd $OUTPUT_DIR
44+
$FLYWHEEL_BASE/metadata_create.py $OUTPUT_DIR $CONTAINER
45+
echo -e "$CONTAINER Wrote: `ls`"
46+
echo -e "$CONTAINER Done!"
47+
fi
48+
49+
exit 0
50+

0 commit comments

Comments
 (0)