-
Notifications
You must be signed in to change notification settings - Fork 0
/
drawStringGraph.sh
executable file
·167 lines (152 loc) · 4.23 KB
/
drawStringGraph.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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/env bash
dir="sample-reads"
if [[ $# -ne 2 && $# -ne 3 ]]
then
echo "Usage: drawStringGraph.sh <sample-basename> <overlap-basename> [overlap-extension]"
echo "Example: drawStringGraph.sh sim-e-coli-pb-le20k-nosub sim-e-coli-pb-le20k-nosub-n60-k42-t0/unionPos 10"
echo "Will use files $dir/sim-e-coli-pb-le10k-nosub.{header-sorted|irr-edges} and $dir/sim-e-coli-pb-le20k-nosub-n60-k42-t0/unionPos.{all-pair|correct|irr-edges}10"
exit 1
fi
#check all needed files exist
header="$dir/$1.header-sorted"
if [[ ! -f $header ]]
then
echo "cannot read node file: $header" >&2
exit 1
fi
all_irr="$dir/$1.irr-edges"
if [[ ! -f $all_irr ]]
then
echo "cannot read all irreducible file: $all_irr" >&2
exit 1
fi
found_prefix="$dir/$2"
found_irr="$found_prefix.irr-edges"
found_correct="$found_prefix.correct"
found_all="$found_prefix.all-pair"
if [[ $# -eq 3 ]]
then
found_irr=$found_irr$3
found_correct=$found_correct$3
found_all=$found_all$3
fi
if [[ ! -f $found_irr ]]
then
echo "cannot read found irreducible file: $found_irr" >&2
exit 1
fi
if [[ ! -f $found_correct ]]
then
echo "cannot read found correct file: $found_correct" >&2
exit 1
fi
if [[ ! -f $found_all ]]
then
echo "cannot read found all file: $found_all" >&2
exit 1
fi
#generate dot file, from dot to svg
#dot -Knop2 -Tsvg xxx.dot > xxx.svg
echo 'digraph{'
echo 'graph [splines=line];'
echo 'node [width=1.2, height=.1];'
#store y-coordinate of all the reads for later use
loc=()
#plot nodes from the sorted header file
cur_y=0
step=-80
while read name remain
do
name=${name#>}
echo "r$name [pos=\"80,$cur_y\", label=\"$name\"];"
loc[$name]=$cur_y
((cur_y+=step))
done <$header
echo 'edge [penwidth=2.0];'
#plot all irreducible edges -- found:green, missed:black
found=false;
while read -u3 read1 read2 len
do
if [[ "$found" = false ]]
then
if read -u4 fread1 fread2 len weight
then
found=true
fi
fi
if [[ "$found" = true && $read1 -eq $fread1 && $read2 -eq $fread2 ]]
then
echo "r$read1 -> r$read2 [color=\"lime\", fontcolor=\"limegreen\", label=\"$weight\"];"
found=false
else
echo "r$read1 -> r$read2 [color=\"black\"];"
fi
done 3<$all_irr 4<$found_irr
#plot all transitive edges -- i.e., correct \setminus irr-edges
echo "edge [color=\"cyan\"];"
found=false;
while read -u3 read1 read2 len weight
do
if [[ "$found" = false ]]
then
if read -u4 fread1 fread2 remain
then
found=true
fi
fi
if [[ "$found" = true && $read1 -eq $fread1 && $read2 -eq $fread2 ]]
then
#is an irreducible edge, has been plotted
found=false
else
((cur_y=(loc[$read1]+loc[$read2])/2))
if [[ ${loc[$read1]} -gt ${loc[$read2]} ]]
then
((cur_x=140-loc[$read1]+loc[$read2]))
else
((cur_x=140+loc[$read1]-loc[$read2]))
fi
echo "r$read1""midr$read2 [pos=\"$cur_x,$cur_y\", shape=\"plaintext\", fontcolor=\"blue\", label=\"$weight\"];"
echo "r$read1:w -> r$read1""midr$read2:c [dir=\"none\"];"
echo "r$read1""midr$read2:c -> r$read2:w;"
fi
done 3<$found_correct 4<$found_irr
#plot all wrong edges
echo "edge [color=\"red\"];"
found=false;
while read -u3 read1 read2 weight
do
if [[ "$found" = false ]]
then
if read -u4 fread1 fread2 remain
then
found=true
fi
fi
if [[ "$found" = true && $read1 -eq $fread1 && $read2 -eq $fread2 ]]
then
#is a correct edge, has been plotted
found=false
else
((cur_y=(loc[$read1]+loc[$read2])/2))
if [[ ${loc[$read1]} -gt ${loc[$read2]} ]]
then
((cur_x=160+(loc[$read1]-loc[$read2])/20))
else
((cur_x=160+(-loc[$read1]+loc[$read2])/20))
fi
#handle short wrong edges pointing in the opposite direction
if [[ $cur_x -le 164 ]]
then
#echo "r$read1""midr$read2 [pos=\"$cur_x,$cur_y\", shape=none, fontcolor=\"red\", label=\"$weight\"];"
#echo "r$read1:ne -> r$read1""midr$read2:c [dir=\"none\"];"
#echo "r$read1""midr$read2:c -> r$read2:se;"
echo "r$read1:ne -> r$read2:se [fontcolor=\"red\", label=\"$weight\"];"
else
echo "r$read1""midr$read2 [pos=\"$cur_x,$cur_y\", shape=none, fontcolor=\"red\", label=\"$weight\"];"
echo "r$read1:e -> r$read1""midr$read2:c [dir=\"none\"];"
echo "r$read1""midr$read2:c -> r$read2:e;"
fi
fi
done 3<$found_all 4<$found_correct
echo '}' #end of graph