-
Notifications
You must be signed in to change notification settings - Fork 1
/
confusionMatrix.py
executable file
·137 lines (119 loc) · 2.96 KB
/
confusionMatrix.py
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
#!/usr/bin/python
###########################################################################
# Confusion matrix. This code generates a confusion matrix using the first alignment result in the each tomatoaligns file.
# path = tomatoaligns directory (/Users/annebozack/Documents/genomics/upload/ubiq_genome/tomatoaligns/)
###########################################################################
import sys
import os
path = sys.argv[1]
files = os.listdir(''+path+'')
ref = ''
read = ''
for i in range(0, len(files)):
f = open(''+path+''+files[i]+'')
lines = f.readlines()
ref = ref + lines[4]
read = read + lines[2]
ref = list(ref)
read = list(read)
# Determining matches/mismatches/indels
trueA = 0
AtoC = 0
AtoT = 0
AtoG = 0
Ainsert= 0
Adel = 0
trueC = 0
CtoA = 0
CtoT = 0
CtoG = 0
Cinsert = 0
Cdel = 0
trueT = 0
TtoA = 0
TtoC = 0
TtoG = 0
Tinsert = 0
Tdel = 0
trueG = 0
GtoA = 0
GtoC = 0
GtoT = 0
Ginsert = 0
Gdel = 0
noClass = 0
for i in range(0, len(ref)):
if ref[i] == 'A' and read[i] == 'A':
trueA +=1
elif ref[i] == 'A' and read[i] == 'C':
AtoC +=1
elif ref[i] == 'A' and read[i] == 'T':
AtoT +=1
elif ref[i] == 'A' and read[i] == 'G':
AtoG +=1
elif ref[i] == 'A' and read[i] == '-':
Adel +=1
elif ref[i] == '-' and read[i] == 'A':
Ainsert +=1
elif ref[i] == 'C' and read[i] == 'C':
trueC +=1
elif ref[i] == 'C' and read[i] == 'A':
CtoA +=1
elif ref[i] == 'C' and read[i] == 'T':
CtoT +=1
elif ref[i] == 'C' and read[i] == 'G':
CtoG +=1
elif ref[i] == 'C' and read[i] == '-':
Cdel +=1
elif ref[i] == '-' and read[i] == 'C':
Cinsert +=1
elif ref[i] == 'T' and read[i] == 'T':
trueT +=1
elif ref[i] == 'T' and read[i] == 'A':
TtoA +=1
elif ref[i] == 'T' and read[i] == 'C':
TtoC +=1
elif ref[i] == 'T' and read[i] == 'G':
TtoG +=1
elif ref[i] == 'T' and read[i] == '-':
Tdel +=1
elif ref[i] == '-' and read[i] == 'T':
Tinsert +=1
elif ref[i] == 'G' and read[i] == 'G':
trueG +=1
elif ref[i] == 'G' and read[i] == 'A':
GtoA +=1
elif ref[i] == 'G' and read[i] == 'C':
GtoC +=1
elif ref[i] == 'G' and read[i] == 'T':
GtoT +=1
elif ref[i] == 'G' and read[i] == '-':
Gdel +=1
elif ref[i] == '-' and read[i] == 'G':
Ginsert +=1
else:
noClass +=1
# print trueA
# print AtoC
# print AtoT
# print AtoG
# print trueC
# print CtoA
# print CtoT
# print CtoG
# print trueT
# print TtoA
# print TtoC
# print TtoG
# print trueG
# print GtoA
# print GtoC
# print GtoT
# print insert
# print delete
# print noClass
total = trueA + AtoC + AtoT + AtoG + Ainsert + Adel + trueC + CtoA + CtoT + CtoG + Cinsert + Cdel + trueT + TtoA + TtoC + TtoG + Tinsert + Tdel + trueG + GtoA + GtoT + GtoC + Ginsert + Gdel
print total
# Making table
from tabulate import tabulate
print tabulate([['A', trueA, AtoC, AtoG, AtoT, Adel], ['C', CtoA, trueC, CtoG, CtoT, Cdel], ['G', GtoA, GtoC, trueG, GtoT, Gdel], ['T', TtoA, TtoC, TtoG, trueT, Tdel], ['Insertion', Ainsert, Cinsert, Ginsert, Tinsert, '-']], headers=['Reference', 'A', 'C', 'G', 'T', 'Deletion'])