forked from scitran-apps/dicom-mr-classifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun
executable file
·86 lines (66 loc) · 2.49 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
#! /bin/bash
# This script is meant to evoke the algorithm without requiring any input arguments
#
CONTAINER="[ scitran/dicom-mr-classifier ]"
##############################################################################
# Configure paths
FLYWHEEL_BASE=/flywheel/v0
OUTPUT_DIR=$FLYWHEEL_BASE/output
INPUT_DIR=$FLYWHEEL_BASE/input/dicom
CONFIG_FILE=$FLYWHEEL_BASE/config.json
MANIFEST_FILE=$FLYWHEEL_BASE/manifest.json
##############################################################################
# Parse configuration
if [[ -f $CONFIG_FILE ]]; then
eval $(jq -r '.config | to_entries[] | "config_\(.key)=\(.value)"' $CONFIG_FILE)
else
CONFIG_FILE=$MANIFEST_FILE
eval $(jq -r '.config | to_entries[] | "config_\(.key)=\(.value.default)"' $CONFIG_FILE)
fi
##############################################################################
# Set Time Zone
TZ="${config_timezone}"
echo "${CONTAINER} Setting time zone to: $TZ"
echo "$TZ" > /etc/timezone && ln -snf /usr/share/zoneinfo/"$TZ" /etc/localtime
dpkg-reconfigure -f noninteractive tzdata
##############################################################################
# Check I/O directories and Generate metadata
if [ "-d" "$OUTPUT_DIR" ]
then
if [ "$(ls -A $OUTPUT_DIR)" ]; then
echo -e "$CONTAINER $OUTPUT_DIR is not Empty! Please provide an empty directory and mount at '$OUTPUT_DIR'."
exit 1
fi
else
echo -e "$CONTAINER $OUTPUT_DIR not found. It will be created."
mkdir $OUTPUT_DIR
fi
# Check for input
if [[ -z $@ ]]
then
input_file=`find $INPUT_DIR -type f -name "*.zip*" | head -1`
if [[ -n $input_file ]]
then
bni=`basename "$input_file"`
output_file_base=$OUTPUT_DIR/${bni%_dicom.zip}
PYHONPATH=$PYTHONPATH:/flywheel/v0/ python $FLYWHEEL_BASE/dicom-mr-classifier.py "$input_file" "$output_file_base"
else
echo -e "No inputs were provided and $INPUT_DIR has no valid input files!"
exit 1
fi
else
PYHONPATH=$PYTHONPATH:/flywheel/v0/ python $FLYWHEEL_BASE/dicom-mr-classifier.py $@
fi
##############################################################################
# Check for outputs and exit
outputs=`find $OUTPUT_DIR -type f -name ".metadata.json"`
# If outputs exist, then go on...
if [[ -z $outputs ]]
then
echo -e "$CONTAINER No results found in output directory... Exiting"
exit 1
else
chmod -R 777 $OUTPUT_DIR
echo -e "$CONTAINER Success."
fi
exit 0