-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpython_read_coodenate
152 lines (67 loc) · 1.88 KB
/
python_read_coodenate
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
from Bio import AlignIO
import re
alnfile = "S_aa_MSA_pathogenic_v2.fasta"
OGlycTab = "O_S_glyc_all.txt"
InTab1 = open(OGlycTab, "r")
selected = []
with InTab1:
for line in InTab1:
lineArray = line.split()
id = lineArray[0]
coord = lineArray[3]
score = lineArray[5]
#print(id, coord, score) ### DIAG
#score = float(score)
#if (score < 0.5): continue ### If filter is applied
score = str(score)
selected.append(id + "\t" + coord+ "\t" + score)
### in case of empty line
if 'str' in line:
break
### close
InTab1.close()
###### MORE
##### OPENING fasta
alnfileObj = AlignIO.read(alnfile, "fasta")
for record in alnfileObj:
### Defining variants
seqAln = record.seq
NameSeqAln = record.id
length = len(record.seq)
length = int(length) ### this number will be useful
#print (NameSeqAln)
# One by one
gaps = 0
for x in range(length):
y = int(x - gaps + 1) ### This number is required for the number for every set
a = seqAln[x:x+1:1] ### moving residue by residue
a = (a.upper())
if (a == '-'):
gaps = (gaps + 1) ### Considerating gaps
print (NameSeqAln, end="")
print ("\t", end="")
print ( x+1 , end="")
print ("\t", end="")
print (y , end="")
print ("\t", end="")
print (a , end="")
### Review for a score
currscor = 0
for alpha in selected:
lineArray = alpha.split("\t")
dd = lineArray[0]
coordd = lineArray[1]
scoree = lineArray[2]
temp = dd.split(".") #New string to take dd before the underscore
dd2 = temp[0]
temp2 = NameSeqAln.split("_")
NameSeqAln2 = temp2[0]
if (NameSeqAln == dd): ### If the id from the fasta is the same as the tab id
if (coordd == y):
currscor = scoree
if (a == '-'): ### Put a zero if the character is a gap
currscor = 0
print ("\t", end="")
print (currscor , end="")
print ( "" , end="\n")
### End.