Skip to content

Commit 52f3d60

Browse files
committed
v0.1.0: adds full support for configuration with defaults
1 parent b0729cf commit 52f3d60

7 files changed

Lines changed: 129 additions & 22 deletions

File tree

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ RUN chmod +x ${FLYWHEEL}/run
4141
COPY manifest.json ${FLYWHEEL}/manifest.json
4242
ADD https://raw.githubusercontent.com/scitran/utilities/daf5ebc7dac6dde1941ca2a6588cb6033750e38c/metadata_from_gear_output.py ${FLYWHEEL}/metadata_create.py
4343
RUN chmod +x ${FLYWHEEL}/metadata_create.py
44+
COPY parse_config.py ${FLYWHEEL}/parse_config.py
45+
RUN chmod +x ${FLYWHEEL}/parse_config.py
4446

4547
# Configure entrypoint
4648
ENTRYPOINT ["/flywheel/v0/run"]
47-

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Builds the gear/container
33
# The container can be exported using the export.sh script
44

5-
GEAR=scitran-apps/dtiinit
5+
GEAR=scitran/dtiinit
66

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

export.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# Exports the container in the cwd.
33
# The container can be exported once it's started with
44
gear=dtiinit
5-
version=0.0.1
5+
version=0.1.0
66
outname=$gear-$version.tar
77
container=$gear
8-
image=scitran-apps/$gear
8+
image=scitran/$gear
99

1010
# Check if input was passed in.
1111
if [[ -n $1 ]]; then

help.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
%
22
% 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).
3+
% and run dtiInit inside of a docker container (scitran/dtiinit).
44
%
55
%
66
% INPUTS:
@@ -67,13 +67,13 @@
6767
% dtiInit processing run (see INPUT section for JSON schema):
6868
%
6969
% % Using a JSON file
70-
% docker run --rm -ti -v `pwd`/input:/input -v `pwd`/output:/output scitran-apps/dtiinit /input/<JSON_filename>.json
70+
% docker run --rm -ti -v `pwd`/input:/input -v `pwd`/output:/output scitran/dtiinit /input/<JSON_filename>.json
7171
%
7272
% % 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"}'
73+
% docker run --rm -ti -v `pwd`/input:/input -v `pwd`/output:/output scitran/dtiinit '{"input_dir":"/input", "output_dir": "/output"}'
7474
%
7575
% % 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/
76+
% docker run --rm -ti -v `pwd`/input:/input -v `pwd`/output:/output scitran/dtiinit /input/
7777
%
7878
%
7979
%

manifest.json

Lines changed: 67 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
"source": "https://github.com/scitran-apps/dtiinit",
88
"license": "GPL-2.0",
99
"flywheel": "0",
10-
"version": "0.0.1",
11-
"config": {
12-
},
10+
"version": "0.1.0",
1311
"inputs": {
1412
"nifti": {
1513
"base": "file",
@@ -34,14 +32,73 @@
3432
"bval"
3533
]
3634
}
35+
}
36+
},
37+
"config": {
38+
"flipLrApFlag": {
39+
"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.",
40+
"default": 0,
41+
"type": "integer"
3742
},
38-
"json": {
39-
"base": "file",
40-
"type": {
41-
"enum": [
42-
"json"
43-
]
44-
}
43+
"numBootStrapSamples": {
44+
"description": "Number of boostrap interations.",
45+
"default": 500,
46+
"type": "integer"
47+
},
48+
"fitMethod": {
49+
"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. ",
50+
"default": "ls",
51+
"type": "string"
52+
},
53+
"nStep": {
54+
"description": "The number of steps for the restore algorithm in the robust tensor fitting case. (dtiRawFitTensorRobust).",
55+
"default": 50,
56+
"type": "integer"
57+
},
58+
"eddyCorrect": {
59+
"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.",
60+
"default": 1,
61+
"type": "integer"
62+
},
63+
"bsplineInterpFlag": {
64+
"description": "Method used for interpolation during resampling (dtiRawResample). 1 = bspline. 0 = trilinear (default)",
65+
"default": 0,
66+
"type": "integer"
67+
},
68+
"phaseEncodeDir": {
69+
"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.",
70+
"type": "integer",
71+
"default": 2
72+
},
73+
"dwOutMm-1": {
74+
"description": "Resolution of the output in mm.",
75+
"type": "integer",
76+
"default": 2
77+
},
78+
"dwOutMm-2": {
79+
"description": "Resolution of the output in mm.",
80+
"type": "integer",
81+
"default": 2
82+
},
83+
"dwOutMm-3": {
84+
"description": "Resolution of the output in mm.",
85+
"type": "integer",
86+
"default": 2
87+
},
88+
"rotateBvecsWithRx": {
89+
"description": "Rotate the b-vectors according to the scanner perscription. 0 = false, 1 = true",
90+
"default": 0,
91+
"type": "integer"
92+
},
93+
"rotateBvecsWithCanXform": {
94+
"description": "Rotate the b-vectors according to the canonical xForm. 0 = false, 1 = true",
95+
"default": 0,
96+
"type": "integer"
97+
},
98+
"noiseCalcMethod": {
99+
"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.",
100+
"type": "string",
101+
"default": "b0"
45102
}
46103
}
47104
}

parse_config.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#! /usr/bin/env python
2+
3+
# Parse a config file and create a dtiInit params json file.
4+
def parse_config(input_file, output_file, input_dir, output_dir):
5+
import json
6+
7+
# Read the config json file
8+
with open(input_file, 'r') as jsonfile:
9+
config = json.load(jsonfile)
10+
11+
# Rename the config key to params
12+
config['params'] = config.pop('config')
13+
14+
# Combine to build the dwOutMm array ( This can be removed once support for arrays is added in the schema. )
15+
dwOutMm = [config['params']['dwOutMm-1'], config['params']['dwOutMm-2'], config['params']['dwOutMm-3']]
16+
config['params']['dwOutMm'] = dwOutMm
17+
18+
# Remove the other dwOutMm fields
19+
del config['params']['dwOutMm-1']
20+
del config['params']['dwOutMm-2']
21+
del config['params']['dwOutMm-3']
22+
23+
# Add input directory for dtiInit
24+
config['input_dir'] = input_dir
25+
config['output_dir'] = output_dir
26+
27+
# Write out the modified configuration
28+
with open(output_file, 'w') as config_json:
29+
json.dump(config, config_json)
30+
31+
if __name__ == '__main__':
32+
33+
import argparse
34+
ap = argparse.ArgumentParser()
35+
ap.add_argument('--input_file', default='/flwywheel/v0/config.json', help='Full path to the input file.')
36+
ap.add_argument('--output_file', default='/flywheel/v0/json/dtiinit_params.json', help='Full path to the output file.')
37+
ap.add_argument('--input_dir', default='/flwywheel/v0/input', help='Full path to the input file.')
38+
ap.add_argument('--output_dir', default='/flywheel/v0/output', help='Full path to the output file.')
39+
args = ap.parse_args()
40+
41+
parse_config(args.input_file, args.output_file, args.input_dir, args.output_dir)

run

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Run dtiinit Gear
44
# Built to flywheel-v0 spec.
55
#
6-
CONTAINER="[scitran-apps/dtiinit]"
6+
CONTAINER="[scitran/dtiinit]"
77

88
# Configure the ENV
99
export FSLOUTPUTTYPE=NIFTI_GZ
@@ -26,10 +26,19 @@ if [[ ! -d "$OUTPUT_DIR" ]]
2626
exit 1
2727
fi
2828

29-
# Do the work
29+
# Make the directories
3030
mkdir $WORK_DIR
31+
mkdir $JSON_DIR
32+
33+
# Convert the config json to a dtiinit_params json file
34+
$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}
35+
36+
# Make sure the params file is saved with the output
37+
cp ${JSON_DIR}/dtiInit-params.json ${OUTPUT_DIR}
38+
39+
# Do the work
3140
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
41+
/usr/local/bin/dtiInit $WORK_DIR 2>&1 | tee $OUTPUT_DIR/dtiInit-log.txt
3342

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

4958
exit 0
50-

0 commit comments

Comments
 (0)