-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherror_correct.py
44 lines (42 loc) · 1.62 KB
/
error_correct.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
#! /usr/bin/python
import numpy as np
def revcomp(seq):
sdict={'A':'T','T':'A','G':'C','C':'G'}
newseq = [sdict[s] for s in seq]
return ''.join(newseq[::-1])
def cbccorrect(cbcs,qcbcs,cbcfreq_dict):
newcbcs=[]
if len(cbcs)>0:
qscores = ['!','"','#','$','%','&','\'','(',')','*','+',',','-','.','/','0','1','2','3','4','5','6','7','8','9',':',';','<','=','>','?','@','A','B','C','D','E','F','G','H','I','J','K','L','M','N']
qdict = {q:float(i) for i,q in enumerate(qscores)}
nts=['A','G','T','C']
cbclen=len(cbcs[0])
corrected=0
for cbc,qcbc in zip(cbcs,qcbcs):
if qcbc=='0':
newcbcs.append(cbc)
else:
T=0
k=0
tcbcs=[]
Llist=np.zeros(4*cbclen)
for i in range(cbclen):
pedit=max([0.0005,pow(10.0,-qdict[qcbc[i]]/10.0)])
for nt in nts:
tcbc=''.join([n if j!=i else nt for j,n in enumerate(cbc)])
tcbcs.append(tcbc)
if tcbc in cbcfreq_dict:
L = cbcfreq_dict[tcbc]*pedit
Llist[k]=L
T+=L
k+=1
if T>0:
Llist=np.array(Llist)/T
if np.max(Llist)>0.975:
newcbcs.append(tcbcs[np.argmax(Llist)])
corrected+=1
else:
newcbcs.append(cbc)
else:
newcbcs.append(cbc)
return newcbcs