This repository has been archived by the owner on Aug 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
run_classifier
executable file
·101 lines (78 loc) · 2.85 KB
/
run_classifier
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
#! /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
function parse_config {
CONFIG_FILE=$FLYWHEEL_BASE/config.json
MANIFEST_FILE=$FLYWHEEL_BASE/manifest.json
if [[ -f $CONFIG_FILE ]]; then
echo "$(cat $CONFIG_FILE | jq -r '.config.'$1)"
else
CONFIG_FILE=$MANIFEST_FILE
echo "$(cat $MANIFEST_FILE | jq -r '.config.'$1'.default')"
fi
}
##############################################################################
# Set Time Zone
TZ="$(parse_config 'timezone')"
echo "${CONTAINER} Setting time zone to: $TZ"
echo "$TZ" > /etc/timezone && sudo ln -snf /usr/share/zoneinfo/"$TZ" /etc/localtime
sudo dpkg-reconfigure -f noninteractive tzdata
##############################################################################
# Check I/O directories and Generate metadata
# Check that /output directory is empty
if [ "-d" "$OUTPUT_DIR" ]
then
if [ "$(ls -A $OUTPUT_DIR)" ]; then
echo -e "$CONTAINER Warning $OUTPUT_DIR is not Empty! Results may be overwritten."
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`
# Check for non-zipped files
if [[ -z $input_file ]]; then
input_file=`find $INPUT_DIR -type f -not -path '*/\.*' | head -1`
fi
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" --config-file "$CONFIG_FILE"
E_STATUS=$?
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 $@
E_STATUS=$?
fi
##############################################################################
# Check for outputs and exit
output=`find $OUTPUT_DIR -type f -name ".metadata.json"`
# If outputs exist, then go on...
if [[ -f $output ]] && [[ $E_STATUS == 0 ]]; then
chmod -R 777 $OUTPUT_DIR
echo -e "$CONTAINER Success."
else
echo -e "$CONTAINER Errors occurred during metadata generation... Exiting!"
exit 1
if [[ -f $output ]]; then
rm $output
fi
fi
exit 0