Skip to content

Commit

Permalink
v0.1.0: adds full support for configuration with defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
lmperry committed Sep 21, 2016
1 parent b0729cf commit 52f3d60
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 22 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ RUN chmod +x ${FLYWHEEL}/run
COPY manifest.json ${FLYWHEEL}/manifest.json
ADD https://raw.githubusercontent.com/scitran/utilities/daf5ebc7dac6dde1941ca2a6588cb6033750e38c/metadata_from_gear_output.py ${FLYWHEEL}/metadata_create.py
RUN chmod +x ${FLYWHEEL}/metadata_create.py
COPY parse_config.py ${FLYWHEEL}/parse_config.py
RUN chmod +x ${FLYWHEEL}/parse_config.py

# Configure entrypoint
ENTRYPOINT ["/flywheel/v0/run"]

2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Builds the gear/container
# The container can be exported using the export.sh script

GEAR=scitran-apps/dtiinit
GEAR=scitran/dtiinit

DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )

Expand Down
4 changes: 2 additions & 2 deletions export.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# Exports the container in the cwd.
# The container can be exported once it's started with
gear=dtiinit
version=0.0.1
version=0.1.0
outname=$gear-$version.tar
container=$gear
image=scitran-apps/$gear
image=scitran/$gear

# Check if input was passed in.
if [[ -n $1 ]]; then
Expand Down
8 changes: 4 additions & 4 deletions help.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%
% Read a JSON object, a JSON file, or a directory containing a json file
% and run dtiInit inside of a docker container (scitran-apps/dtiinit).
% and run dtiInit inside of a docker container (scitran/dtiinit).
%
%
% INPUTS:
Expand Down Expand Up @@ -67,13 +67,13 @@
% dtiInit processing run (see INPUT section for JSON schema):
%
% % Using a JSON file
% docker run --rm -ti -v `pwd`/input:/input -v `pwd`/output:/output scitran-apps/dtiinit /input/<JSON_filename>.json
% docker run --rm -ti -v `pwd`/input:/input -v `pwd`/output:/output scitran/dtiinit /input/<JSON_filename>.json
%
% % Using a JSON string
% docker run --rm -ti -v `pwd`/input:/input -v `pwd`/output:/output scitran-apps/dtiinit '{"input_dir":"/input", "output_dir": "/output"}'
% docker run --rm -ti -v `pwd`/input:/input -v `pwd`/output:/output scitran/dtiinit '{"input_dir":"/input", "output_dir": "/output"}'
%
% % Using a directory (in the container), containing a JSON (.json)
% docker run --rm -ti -v `pwd`/input:/input -v `pwd`/output:/output scitran-apps/dtiinit /input/
% docker run --rm -ti -v `pwd`/input:/input -v `pwd`/output:/output scitran/dtiinit /input/
%
%
%
77 changes: 67 additions & 10 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
"source": "https://github.com/scitran-apps/dtiinit",
"license": "GPL-2.0",
"flywheel": "0",
"version": "0.0.1",
"config": {
},
"version": "0.1.0",
"inputs": {
"nifti": {
"base": "file",
Expand All @@ -34,14 +32,73 @@
"bval"
]
}
}
},
"config": {
"flipLrApFlag": {
"description": "This flag will signal dtiRawBuildBvecs to reorient the gradient directions specified in the dwepi.grads file to logical space rather than keeping the directions in scanner space. Thus, the bvecs do not need to be reoriented for oblique prescriptions as with some other DTI sequences. However, this sequence assumes that the 2nd column in dwepi.grads is the phase-encode dim. If your phase-encode is the usual '2', then this is fine. But, if you run ASSET and change the phase encode to L-R (dim 1), you need to swap the first and second columns of dwepi.grads. Also, there appears to be a flip in the phase-encode dim, so you also need to flip the sign on the phase-encode column.",
"default": 0,
"type": "integer"
},
"json": {
"base": "file",
"type": {
"enum": [
"json"
]
}
"numBootStrapSamples": {
"description": "Number of boostrap interations.",
"default": 500,
"type": "integer"
},
"fitMethod": {
"description": "Fit-method for tesnsor fitting. Options are ['ls', 'rt', 'lsrt']: 'ls': least-squares (default) 'rt': RESTORE robust tensor fitting and outlier rejection (Chang, Jones & Pierpaoli (2005) RESTORE: Robust Estimation of Tensors by Outlier Rejection. Magnetic Resonance in Medicine, v53). 'lsrt': does least-squares and robust tensor fitting in one go. ",
"default": "ls",
"type": "string"
},
"nStep": {
"description": "The number of steps for the restore algorithm in the robust tensor fitting case. (dtiRawFitTensorRobust).",
"default": 50,
"type": "integer"
},
"eddyCorrect": {
"description": "Motion and eddy-current correction. [default = 1, Do eddy-current and motion correction]. Options [0, 1, -1]. 0 = Only motion correction is done. 1 = Do eddy-current and motion correction. -1 = No motion or eddy correction.",
"default": 1,
"type": "integer"
},
"bsplineInterpFlag": {
"description": "Method used for interpolation during resampling (dtiRawResample). 1 = bspline. 0 = trilinear (default)",
"default": 0,
"type": "integer"
},
"phaseEncodeDir": {
"description": "Phase encoding direction. (1 = L/R 'row', 2 = A/P 'col'). This value is read from the rawDti nifti field, you should specify it here if it does not exist. If you collected your DTI data using GE's ASSET, you should provide the phase-encode direction (1= L/R 'row', 2 = A/P 'col'). Information about this, as well as the b-value and gradient code, can be found in the dicom file header.",
"type": "integer",
"default": 2
},
"dwOutMm-1": {
"description": "Resolution of the output in mm.",
"type": "integer",
"default": 2
},
"dwOutMm-2": {
"description": "Resolution of the output in mm.",
"type": "integer",
"default": 2
},
"dwOutMm-3": {
"description": "Resolution of the output in mm.",
"type": "integer",
"default": 2
},
"rotateBvecsWithRx": {
"description": "Rotate the b-vectors according to the scanner perscription. 0 = false, 1 = true",
"default": 0,
"type": "integer"
},
"rotateBvecsWithCanXform": {
"description": "Rotate the b-vectors according to the canonical xForm. 0 = false, 1 = true",
"default": 0,
"type": "integer"
},
"noiseCalcMethod": {
"description": "Noise calculation method for robust tensor fitting. ['corner', 'b0' (default)]. There are 2 ways to calculate the noise. The first is based on the standard deviation of the signal in the corner of the image (noiseCalcMethod = 'corner'). This method works well as long as the corner of the image has not been padded with zeros. Currently GE zeros out the pixel intensity outside of the brain. So for new GE data we calculate the noise by taking the standard deviation of the b=0 images (noiseCalcMethod = 'b0') which means that we need a number of b0 acquisitions. If you are using robust tensor fitting you must decide how to calculate the image noise. If the corner of the image is padded with zeros then you should use the 'b0' method which calculates the noise based on the std of the b0 image.",
"type": "string",
"default": "b0"
}
}
}
41 changes: 41 additions & 0 deletions parse_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#! /usr/bin/env python

# Parse a config file and create a dtiInit params json file.
def parse_config(input_file, output_file, input_dir, output_dir):
import json

# Read the config json file
with open(input_file, 'r') as jsonfile:
config = json.load(jsonfile)

# Rename the config key to params
config['params'] = config.pop('config')

# Combine to build the dwOutMm array ( This can be removed once support for arrays is added in the schema. )
dwOutMm = [config['params']['dwOutMm-1'], config['params']['dwOutMm-2'], config['params']['dwOutMm-3']]
config['params']['dwOutMm'] = dwOutMm

# Remove the other dwOutMm fields
del config['params']['dwOutMm-1']
del config['params']['dwOutMm-2']
del config['params']['dwOutMm-3']

# Add input directory for dtiInit
config['input_dir'] = input_dir
config['output_dir'] = output_dir

# Write out the modified configuration
with open(output_file, 'w') as config_json:
json.dump(config, config_json)

if __name__ == '__main__':

import argparse
ap = argparse.ArgumentParser()
ap.add_argument('--input_file', default='/flwywheel/v0/config.json', help='Full path to the input file.')
ap.add_argument('--output_file', default='/flywheel/v0/json/dtiinit_params.json', help='Full path to the output file.')
ap.add_argument('--input_dir', default='/flwywheel/v0/input', help='Full path to the input file.')
ap.add_argument('--output_dir', default='/flywheel/v0/output', help='Full path to the output file.')
args = ap.parse_args()

parse_config(args.input_file, args.output_file, args.input_dir, args.output_dir)
16 changes: 12 additions & 4 deletions run
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Run dtiinit Gear
# Built to flywheel-v0 spec.
#
CONTAINER="[scitran-apps/dtiinit]"
CONTAINER="[scitran/dtiinit]"

# Configure the ENV
export FSLOUTPUTTYPE=NIFTI_GZ
Expand All @@ -26,10 +26,19 @@ if [[ ! -d "$OUTPUT_DIR" ]]
exit 1
fi

# Do the work
# Make the directories
mkdir $WORK_DIR
mkdir $JSON_DIR

# Convert the config json to a dtiinit_params json file
$FLYWHEEL_BASE/parse_config.py --input_file ${FLYWHEEL_BASE}/config.json --output_file ${JSON_DIR}/dtiInit-params.json --input_dir ${WORK_DIR} --output_dir ${OUTPUT_DIR}

# Make sure the params file is saved with the output
cp ${JSON_DIR}/dtiInit-params.json ${OUTPUT_DIR}

# Do the work
cp $NIFTI_DIR/* $BVEC_DIR/* $BVAL_DIR/* $JSON_DIR/* $WORK_DIR
/usr/local/bin/dtiInit $WORK_DIR 2>&1 | tee $OUTPUT_DIR/dtiinit-log.txt
/usr/local/bin/dtiInit $WORK_DIR 2>&1 | tee $OUTPUT_DIR/dtiInit-log.txt

# Get a list of the files in the output directory
outputs=$(find $OUTPUT_DIR/* -maxdepth 0 -type f)
Expand All @@ -47,4 +56,3 @@ if [[ -z $outputs ]]
fi

exit 0

0 comments on commit 52f3d60

Please sign in to comment.