-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdebug.go
248 lines (220 loc) · 6.96 KB
/
debug.go
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
//---------------------------------------------------------------------------------------------------
// IVC: debug.go
// Debug variables and functions.
// Copyright 2015 Nam Sy Vo.
//---------------------------------------------------------------------------------------------------
package ivc
import (
"fmt"
"log"
"math"
"os"
"runtime"
"strconv"
)
// Global variable for turnning on/off info profiling
var (
PRINT_MEMSTATS = false
PRINT_EDIT_DIST_INFO = false
PRINT_EDIT_DIST_MAT_INFO = false
PRINT_VAR_CALL_INFO = false
PRINT_ALIGN_TRACE_INFO = false
PRINT_UNALIGN_INFO = false
)
// Global variable for cpu and memory profiling
var (
CPU_FILE *os.File
MEM_FILE *os.File
MEM_STATS *runtime.MemStats
)
// Printing memory information
func PrintMemStats(mesg string) {
if PRINT_MEMSTATS {
runtime.ReadMemStats(MEM_STATS)
log.Printf(mesg+"\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f",
float64(MEM_STATS.Alloc)/(math.Pow(1024, 3)), float64(MEM_STATS.TotalAlloc)/(math.Pow(1024, 3)),
float64(MEM_STATS.Sys)/(math.Pow(1024, 3)), float64(MEM_STATS.HeapAlloc)/(math.Pow(1024, 3)),
float64(MEM_STATS.HeapSys)/(math.Pow(1024, 3)))
}
}
// Printing unaligned-reads info
var UNALIGN_READ_INFO = make([]*UnAlnReadInfo, 0)
func ProcessNoAlignReadInfo() {
if PRINT_UNALIGN_INFO {
fmt.Println("Processing noaligned read info...")
file, _ := os.Create(PARA.Var_call_file + ".unalign")
defer file.Close()
for _, uai := range UNALIGN_READ_INFO {
file.WriteString(string(uai.read_info1) + "\t" + string(uai.read_info2) + "\n")
}
fmt.Println("Finish processing noaligned read info.")
}
}
//--------------------------------------------------------------------------------------------------
// Printing Alignment info
//--------------------------------------------------------------------------------------------------
func PrintLoopTraceInfo(loop_num int, mess string) {
if PRINT_ALIGN_TRACE_INFO {
fmt.Println("Loop\t", loop_num, "\t", mess)
}
}
func PrintSeedTraceInfo(mess string, e_pos, s_pos int, read []byte) {
if PRINT_ALIGN_TRACE_INFO {
fmt.Println(mess+" has seed\t", e_pos, "\t", s_pos, "\t", string(read[e_pos:s_pos+1]))
}
}
func PrintPairedSeedInfo(mess string, match_pos_r1, match_pos_r2 int) {
if PRINT_ALIGN_TRACE_INFO {
fmt.Println(mess, "\t", match_pos_r1, "\t", match_pos_r2)
}
}
func PrintExtendTraceInfo(mess string, match []byte, e_pos, s_pos, match_num int, match_pos []int) {
if PRINT_ALIGN_TRACE_INFO {
fmt.Println(mess, " extend\t", string(match), "\t", e_pos, "\t", s_pos, "\t", match_num)
fmt.Print(mess, " match pos\t")
for i := 0; i < match_num; i++ {
fmt.Print(match_pos[i], "\t")
}
fmt.Println()
}
}
func PrintMatchTraceInfo(pos, left_most_pos int, dis float64, left_var_pos []int, read []byte) {
if PRINT_ALIGN_TRACE_INFO {
fmt.Print("Match\t", pos, "\t", dis, "\t", left_most_pos, "\t", string(read), "\t")
for _, pos := range left_var_pos {
fmt.Print(pos, "\t")
}
fmt.Println()
}
}
//--------------------------------------------------------------------------------------------------
//Printing variant calling info
//--------------------------------------------------------------------------------------------------
func PrintComparedReadRef(l_read_flank, l_ref_flank, r_read_flank, r_ref_flank []byte) {
if PRINT_VAR_CALL_INFO {
fmt.Println("l_read_flank", string(l_read_flank))
fmt.Println("l_ref_flank", string(l_ref_flank))
fmt.Println("r_read_flank", string(r_read_flank))
fmt.Println("r_ref_flank", string(r_ref_flank))
}
}
func PrintRefPosMap(l_ref_pos_map, r_ref_pos_map []int) {
if PRINT_VAR_CALL_INFO {
fmt.Println("l_ref_pos_map", l_ref_pos_map)
fmt.Println("r_ref_pos_map", r_ref_pos_map)
}
}
func PrintGetVariants(mess string, paired_prob, prob1, prob2 float64, vars1, vars2 []*VarInfo) {
if PRINT_VAR_CALL_INFO {
fmt.Println(mess)
fmt.Println("Dis to get vars: paired_prob, prob1 (1st-end), prob2 (2nd-end)", paired_prob, prob1, prob2)
fmt.Println("1st-end variants")
for _, s := range vars1 {
fmt.Println(s.Pos, string(s.Bases), string(s.BQual))
}
fmt.Println("2nd-end variants")
for _, s := range vars2 {
fmt.Println(s.Pos, string(s.Bases), string(s.BQual))
}
}
}
func PrintVarInfo(mess string, var_pos []int, var_val, var_qlt [][]byte) {
if PRINT_VAR_CALL_INFO {
fmt.Println(mess)
for i := 0; i < len(var_pos); i++ {
fmt.Println(var_pos[i], string(var_val[i]), string(var_qlt[i]))
}
}
}
//--------------------------------------------------------------------------------------------------
//Printing edit distance calculation info
//--------------------------------------------------------------------------------------------------
func PrintEditDisInput(mess string, pos int, str_val ...[]byte) {
if PRINT_EDIT_DIST_INFO {
fmt.Println(mess)
fmt.Println(strconv.Itoa(pos))
if str_val != nil {
for _, v := range str_val {
fmt.Println(string(v))
}
}
}
}
func PrintEditDisMat(mess string, D [][]float64, m, n int, read, ref []byte) {
if PRINT_EDIT_DIST_MAT_INFO {
fmt.Println(mess)
fmt.Print("\t\t")
for j := 1; j <= n; j++ {
fmt.Print(string(ref[j-1]), "\t")
}
fmt.Println()
fmt.Print("\t")
for j := 0; j <= n; j++ {
fmt.Print(D[0][j], "\t")
}
fmt.Println()
for i := 1; i <= m; i++ {
fmt.Print(string(read[i-1]) + "\t")
for j := 0; j <= n; j++ {
fmt.Print(D[i][j], "\t")
}
fmt.Println()
}
}
}
// BT[i][j][0]: direction, can be 0: diagonal arrow (back to i-1,j-1), 1: up arrow (back to i-1,j), 2: left arrow (back to i,j-1)
// BT[i][j][1]: matrix, can be 0: matrix for D, 1: matrix for IS, 2: matrix for IT
// BT[i][j][2]: number of shift (equal to length of called variant) at known variant loc, can be any integer number, for example 5 means back to i-5,j-1
func PrintEditTraceMat(mess string, BT [][][]int, m, n int) {
if PRINT_EDIT_DIST_MAT_INFO {
fmt.Println(mess)
for i := 0; i <= m; i++ {
for j := 0; j <= n; j++ {
fmt.Print("[")
if BT[i][j][0] == 0 {
fmt.Print("d ")
} else if BT[i][j][0] == 1 {
fmt.Print("u ")
} else if BT[i][j][0] == 2 {
fmt.Print("l ")
} else {
fmt.Print("n ")
}
if BT[i][j][1] == 0 {
fmt.Print("D ")
} else if BT[i][j][1] == 1 {
fmt.Print("S ")
} else if BT[i][j][1] == 2 {
fmt.Print("T ")
} else {
fmt.Print("N ")
}
fmt.Print(BT[i][j][2], "]\t")
}
fmt.Println()
}
}
}
func PrintDisInfo(mess string, i, j int, d float64) {
if PRINT_EDIT_DIST_INFO {
fmt.Println(mess, i, j, d)
}
}
func GetEditTrace(mess string, i, j int, read, ref byte) {
if PRINT_EDIT_DIST_INFO {
fmt.Println(mess, i, j, string(read), string(ref))
}
}
func GetEditTraceKnownLoc(mess string, i, j int, read []byte, ref byte) {
if PRINT_EDIT_DIST_INFO {
fmt.Println(mess, i, j, string(read), string(ref))
}
}
func PrintEditAlignInfo(mess string, aligned_read, aligned_qual, aligned_ref []byte) {
if PRINT_EDIT_DIST_INFO {
fmt.Println(mess)
fmt.Println(string(aligned_read))
fmt.Println(string(aligned_qual))
fmt.Println(string(aligned_ref))
}
}