-
Notifications
You must be signed in to change notification settings - Fork 2
/
pairwise-ttest.sh
executable file
·58 lines (49 loc) · 1.25 KB
/
pairwise-ttest.sh
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
#!/usr/bin/env bash
# Perform pairwise t-test with Bonferroni correction
SPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
TMPA=$(mktemp -p .)
TMPB=$(mktemp -p .)
HEADER="qid"
COUNTER=0
SYSMAP="System mapping:"$'\n'
PREV=""
err() {
echo "$1" 1>&2
}
check_topic_count() {
local prev=$1
local curr=$2
local prev_len=$(wc -l $prev | awk '{print $1}')
local curr_len=$(wc -l $curr | awk '{print $1}')
if [ $prev_len -ne $curr_len ]; then
err "error: different number of topics found"
err "$prev_len $(basename $prev)"
err "$curr_len $(basename $curr)"
exit 1
fi
}
for i in $@; do
name="Sys$COUNTER"
SYSMAP="$SYSMAP $name $(basename $i)"$'\n'
HEADER="$HEADER $name"
if [ $COUNTER -eq 0 ]; then
cat $i > $TMPA
elif [ $((COUNTER % 2)) -eq 0 ]; then
check_topic_count $PREV $i
join $TMPB $i > $TMPA
else
check_topic_count $PREV $i
join $TMPA $i > $TMPB
fi
COUNTER=$((COUNTER + 1))
PREV=$i
done
# flip the modulus, the counter was incremented on the last iteration
if [ $((COUNTER % 2)) -eq 0 ]; then
cp $TMPB $TMPA
fi
echo $HEADER > $TMPB
cat $TMPA >> $TMPB
echo "$SYSMAP"
Rscript $SPATH/pairwise.r $TMPB
rm $TMPA $TMPB