-
Notifications
You must be signed in to change notification settings - Fork 1
/
run
executable file
·115 lines (88 loc) · 3.41 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
#! /bin/bash
#
CONTAINER="[ stanfordcni/pfile-mr-classifier ]"
##############################################################################
# Configure paths
FLYWHEEL_BASE=/flywheel/v0
OUTPUT_DIR=$FLYWHEEL_BASE/output
INPUT_DIR=$FLYWHEEL_BASE/input/pfile
##############################################################################
# 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 && ln -snf /usr/share/zoneinfo/"$TZ" /etc/localtime
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
input_file=`find $INPUT_DIR -type f -name "*.7*" | head -1`
if [[ -f $input_file ]]; then
# Generate the truncated header from the zip file, or other, and export to csv
echo -e "${CONTAINER} Extracting header from $input_file"
header_file=/tmp/pfile_header
if echo "$input_file" | grep -q ".7.zip"; then
echo -e "${CONTAINER} Found pfile zip archive - unzipping, extracting, and generating truncated header..."
unzip -p "$input_file" "*/*.7.gz" | head -c 1000000 | gunzip > $header_file 2>/dev/null
elif echo "$input_file" | grep -q ".7.gz"; then
echo -e "${CONTAINER} Found gzipped pfile - extracting and generating truncated header..."
cat $input_file | head -c 1000000 | gunzip > $header_file 2>/dev/null
elif echo "$input_file" | grep -q ".7"; then
echo -e "${CONTAINER} Found pfile - generating truncated header..."
cat $input_file | head -c 1000000 > $header_file 2>/dev/null
fi
# Generate header file
/opt/pfile-tools/pfile_tools/scripts/dump_pfile_header.py $header_file --separator=, > $header_file.csv
if [[ $? != 0 ]]; then
echo -e "${CONTAINER} Error generating header!"
exit 11
fi
# Generate the metadata
echo -e "${CONTAINER} Generating metadata..."
PYHONPATH=$PYTHONPATH:/flywheel/v0/ python $FLYWHEEL_BASE/pfile-mr-classifier.py \
"${input_file}" \
"${header_file}" \
"${header_file}.csv" \
"$OUTPUT_DIR"
if [[ $? != 0 ]]; then
echo -e "${CONTAINER} Error generating metadata!"
exit 1
fi
else
echo -e "${CONTAINER} No inputs were provided and $INPUT_DIR has no valid input files!"
exit 1
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