-
Notifications
You must be signed in to change notification settings - Fork 0
/
ftdmp-plot-jury-diagnostics
executable file
·110 lines (85 loc) · 2.22 KB
/
ftdmp-plot-jury-diagnostics
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
#!/bin/bash
function print_help_and_exit
{
cat >&2 << 'EOF'
'ftdmp-plot-jury-scores' plots jury scores from a scoring table
Options:
--input-prefix string * input file path prefix
--output-prefix string * output plot file path prefix
--help | -h flag to display help message and exit
Example:
ftdmp-plot-jury-diagnostics --input-prefix ./scores/scoring_diagnostic_ --output ./plot.png
EOF
exit 1
}
################################################################################
if [ -z "$1" ]
then
print_help_and_exit
fi
INPUT_PREFIX=""
OUTPUT_PREFIX=""
HELP_MODE="false"
while [[ $# > 0 ]]
do
OPTION="$1"
OPTARG="$2"
shift
case $OPTION in
--input-prefix)
INPUT_PREFIX="$OPTARG"
shift
;;
--output-prefix)
OUTPUT_PREFIX="$OPTARG"
shift
;;
-h|--help)
HELP_MODE="true"
;;
*)
echo >&2 "Error: invalid command line option '$OPTION'"
exit 1
;;
esac
done
if [ "$HELP_MODE" == "true" ]
then
print_help_and_exit
fi
if [ -z "$INPUT_PREFIX" ]
then
echo >&2 "Error: input file path prefix not specified"
exit 1
fi
if [ -z "$OUTPUT_PREFIX" ]
then
echo >&2 "Error: output plot file prefix not specified"
exit 1
fi
command -v R &> /dev/null || { echo >&2 "Error: 'R' executable not in binaries path"; exit 1; }
CLUSTER_COUNTS_FILE="${INPUT_PREFIX}cluster_counts_by_threshold.txt"
if [ ! -s "$CLUSTER_COUNTS_FILE" ]
then
echo >&2 "Error: missing input file '$CLUSTER_COUNTS_FILE'"
exit 1
fi
################################################################################
readonly TMPLDIR=$(mktemp -d)
trap "rm -r $TMPLDIR" EXIT
cp "$CLUSTER_COUNTS_FILE" "$TMPLDIR/cluster_counts.txt"
cd "$TMPLDIR"
R --vanilla > /dev/null << 'EOF'
dt=read.table("cluster_counts.txt", header=FALSE, stringsAsFactors=FALSE);
png("cluster_counts.png", width=1000, height=600, units="px", pointsize=14);
plot(dt$V1, dt$V2, xlab="threshold", ylab="clusters", main="Cluster counts vs thresholds");
dev.off();
EOF
if [ ! -s "${TMPLDIR}/cluster_counts.png" ]
then
echo >&2 "Error: no output plot produced for '$CLUSTER_COUNTS_FILE'"
exit 1
fi
cd - &> /dev/null
mkdir -p "$(dirname ${OUTPUT_PREFIX}suffix)"
mv "${TMPLDIR}/cluster_counts.png" "${OUTPUT_PREFIX}cluster_counts.png"