forked from scitran-apps/fsl-bet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run
executable file
·129 lines (100 loc) · 4.55 KB
/
run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#! /bin/bash
#
#
CONTAINER="[scitran/fsl-bet]"
echo -e "$CONTAINER Initiated"
# Built to flywheel-v0 spec.
FLYWHEEL_BASE=/flywheel/v0
# Configure the ENV
chmod +x /etc/fsl/5.0/fsl.sh
source /etc/fsl/5.0/fsl.sh
OUTPUT_DIR=$FLYWHEEL_BASE/output
INPUT_DIR=$FLYWHEEL_BASE/input/nifti
MANIFEST=$FLYWHEEL_BASE/manifest.json
CONFIG_FILE=$FLYWHEEL_BASE/config.json
# Initialize config parameters
skull_image=' '
vtk_surface_mesh=' '
binary_brain_mask=' '
brain_surf_outline=' '
apply_mask_thresholding=' '
fractional_intensity_threshold=' '
vertical_gradient_intensity_threshold=' '
# Generate flags from the manifest
skull_image_flag=$(jq -r <$MANIFEST '''.config.skull_image.id')
vtk_surface_mesh_flag=$(jq -r <$MANIFEST '''.config.vtk_surface_mesh.id')
binary_brain_mask_flag=$(jq -r <$MANIFEST '''.config.binary_brain_mask.id')
brain_surf_outline_flag=$(jq -r <$MANIFEST '''.config.brain_surf_outline.id')
apply_mask_thresholding_flag=$(jq -r <$MANIFEST '''.config.apply_mask_thresholding.id')
fractional_intensity_threshold_flag=$(jq -r <$MANIFEST '''.config.fractional_intensity_threshold.id')
vertical_gradient_intensity_threshold_flag=$(jq -r <$MANIFEST '''.config.vertical_gradient_intensity_threshold.id')
# Parse config options from CONFIG file or MANIFEST
if [[ -f $CONFIG_FILE ]]; then
echo "$CONFIG_FILE found. Loading config..."
if [[ $(jq -r <$CONFIG_FILE '''.config.skull_image') == 'true' ]]; then
skull_image=$skull_image_flag
fi
if [[ $(jq -r <$CONFIG_FILE '''.config.vtk_surface_mesh') == 'true' ]]; then
vtk_surface_mesh=$vtk_surface_mesh_flag
fi
if [[ $(jq -r <$CONFIG_FILE '''.config.binary_brain_mask') == 'true' ]]; then
binary_brain_mask=$binary_brain_mask_flag
fi
if [[ $(jq -r <$CONFIG_FILE '''.config.brain_surf_outline') == 'true' ]]; then
brain_surf_outline=$brain_surf_outline_flag
fi
if [[ $(jq -r <$CONFIG_FILE '''.config.apply_mask_thresholding') == 'true' ]]; then
apply_mask_thresholding=$apply_mask_thresholding_flag
fi
fractional_intensity_threshold="$fractional_intensity_threshold_flag $(jq -r <$CONFIG_FILE '''.config.fractional_intensity_threshold')"
vertical_gradient_intensity_threshold="$vertical_gradient_intensity_threshold_flag $(jq -r <$CONFIG_FILE '''.config.vertical_gradient_intensity_threshold')"
function_option=$(jq -r <$CONFIG_FILE '''.config.function_option')
else
echo "$CONFIG_FILE not found. Loading defaults from $MANIFEST..."
if [[ $(jq -r <$MANIFEST '''.config.skull_image.default') == 'true' ]]; then
skull_image=$skull_image_flag
fi
if [[ $(jq -r <$MANIFEST '''.config.vtk_surface_mesh.default') == 'true' ]]; then
vtk_surface_mesh=$vtk_surface_mesh_flag
fi
if [[ $(jq -r <$MANIFEST '''.config.binary_brain_mask.default') == 'true' ]]; then
binary_brain_mask=$binary_brain_mask_flag
fi
if [[ $(jq -r <$MANIFEST '''.config.brain_surf_outline.default') == 'true' ]]; then
brain_surf_outline=$brain_surf_outline_flag
fi
if [[ $(jq -r <$MANIFEST '''.config.apply_mask_thresholding.default') == 'true' ]]; then
apply_mask_thresholding=$apply_mask_thresholding_flag
fi
fractional_intensity_threshold="$fractional_intensity_threshold_flag $(jq -r <$MANIFEST '''.config.fractional_intensity_threshold.default')"
vertical_gradient_intensity_threshold="$vertical_gradient_intensity_threshold_flag $(jq -r <$MANIFEST '''.config.vertical_gradient_intensity_threshold.default')"
function_option=$(jq -r <$MANIFEST '''.config.function_option.default')
fi
# Compile options string
OPTIONS="$fractional_intensity_threshold $brain_surf_outline $binary_brain_mask $skull_image $vertical_gradient_intensity_threshold $apply_mask_thresholding $vtk_surface_mesh $function_option"
echo -e "bet options are: ${OPTIONS}"
# Execute the algorithm
input_file=$(find $INPUT_DIR/* -maxdepth 0 -type f -name "*.nii*")
if [[ -f $input_file ]]; then
input_file_despaced=$(echo -e "${input_file}" | tr -d '[:space:]')
mv "${input_file}" "${input_file_despaced}"
input_file=$input_file_despaced
echo "$CONTAINER Running bet2 on `basename "$input_file"`"
output_file_base=$OUTPUT_DIR/$(basename "$input_file" .nii.gz)
output_file_base=$OUTPUT_DIR/$(basename "$output_file_base" .nii)
bet "$input_file" "$output_file_base"_bet -v $OPTIONS
STATUS=$?
else
echo "$CONTAINER No inputs were provided and $INPUT_DIR has no valid input files!"
exit 1
fi
# Check exit status
if [[ $STATUS == 0 ]]
then
echo -e "$CONTAINER Wrote: `ls $OUTPUT_DIR`"
echo -e "$CONTAINER Done!"
else
echo "$CONTAINER command returned a non-zero exit code = [$STATUS]."
exit 1
fi
exit 0