-
Notifications
You must be signed in to change notification settings - Fork 9
/
12e.py
executable file
·313 lines (290 loc) · 13.7 KB
/
12e.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
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
### for sRNA sequences
# script for calculating number of mistaches in Blast hits against PMRD
## updated on 20110101
## uses: 20110506_count_mismatch.py /Users/vikasgupta/Desktop/tools/ncbi-blast-2.2.24+/db/PMRD_all.fa /Users/vikasgupta/Desktop/plant/2011_week4/20110128_PMRD_mapping/PMRD_species_wise_dataset.txt 2010-03-26_GHD-5-16_19-38_all.profile_ext.cut20.norm.scores.fasta_blastout >2010-03-26_GHD-5-16_19-38_all.profile_ext.cut20.norm.scores.fasta_blastout_mismatch_count
import sys
PMRD = open(sys.argv[1],'r')
#### just for using name of miRNA, nothing to do with mapping
PMRD_seq = {}
for line in PMRD.readlines():
line = line.strip()
token=line.split()
if(line[0]=='>'):
key = token[0][1:]
else:
PMRD_seq[key] = line
#print(key,(PMRD_seq[key]))
#print len(PMRD_seq)
### inout for couting mismatches
f = open(sys.argv[2],'r')
last_seq = '1'
count_0 = 0
count_1 = 0
count_2 = 0
count_3 = 0
number = 1
### best hit equals best match
score = 0
best_match = "none"
best_family = "none"
for line in f.readlines():
line =line.strip()
token = line.split()
token_part = token[0].split('_')
#print(line)
parts = last_seq.split('_')
if(number < int(parts[0])):
for i in range(number,int(parts[0])):
print (str(i)+'\t'+'0:0:0:0'+'\t'+"none"+'\t'+"none")
m = 3
number = int(parts[0])
#print(line)
min_len = min(int(len(PMRD_seq[token[1]])),int(token_part[2]))
#print(min_len,int(token[3]))
if( last_seq == token[0]):
## Case1: No mis-matches
if( (int(token[3])==int(min_len))&(int(token[4])==0)):
#print("match",min_len,int(token[3]),int(PMRD_seq[token[1]]),int(token_part[2]))
count_0 += 1
score = 1000
best_match = PMRD_seq[token[1]]
best_family = token[1]
## Case2: Exactly one mis-matches allowed ( min of both query and target seq are allowed to have one mismatch of start/end layoff
if((int(token[3])+1-int(token[4]))==int(min_len)):
count_1 +=1
if ( score < 100):
best_match = PMRD_seq[token[1]]
best_family = token[1]
score = 100
#print(best_match,best_family)
## Case3: Exactly two mis-matches allowed ( min of both query and target seq are allowed to have one mismatch of start/end layoff
if((int(token[3])+2-int(token[4]))==int(min_len)):
count_2 +=1
if ( score < 10):
best_match = PMRD_seq[token[1]]
best_family = token[1]
score = 10
## Case4: Exactly three mis-matches allowed ( min of both query and target seq are allowed to have one mismatch of start/end layoff
if((int(token[3])+3-int(token[4]))==int(min_len)):
count_3 +=1
if ( score < 1):
best_match = PMRD_seq[token[1]]
best_family = token[1]
score = 1
else:
continue
else:
#print score
print(last_seq+'\t'+str(count_0)+':'+str(count_1)+':'+str(count_2)+':'+str(count_3)+'\t'+best_match+'\t'+best_family)
score = 0
count_0 = 0
count_1 = 0
count_2 = 0
count_3 = 0
best_match = "none"
best_family = "none"
method_used = "none"
number += 1
## Case2: One mis-matches allowed ( min of both query and target seq are allowed to have one mismatch of start/end layoff
last_seq = token[0]
"""
### for mirDeep header
# script for calculating number of mistaches in Blast hits against PMRD
total_match_count = 0
PMRD = open('/Users/vikasgupta/Desktop/tools/ncbi-blast-2.2.24+/db/PMRD_all.fa','r')
PMRD_seq = {}
for line in PMRD.readlines():
line = line.strip()
if(line[0]=='>'):
key = line[1:]
else:
PMRD_seq[key] = line
#print(key,(PMRD_seq[key]))
f = open('/Users/vikasgupta/Desktop/plant/2011_week1/20110103/miRNA_list_predictions_PMRD_v5_blast_output.fasta','r')
last_seq = '1'
count_0 = 0
count_1 = 0
count_2 = 0
count_3 = 0
number = 1
### best hit equals best match
score = 0
best_match = "none"
best_family = "none"
for line in f.readlines():
line =line.strip()
token = line.split()
token_part = token[0].split('size')
parts = last_seq.split('size')
parts[0]=parts[0].replace('.','')
if(number < int(parts[0])):
for i in range(number,int(parts[0])):
print (str(i)+'\t'+'0:0:0:0'+'\t'+"none"+'\t'+"none")
number = int(parts[0])
#print(line)
min_len = min(int(len(PMRD_seq[token[1]])),int(token_part[1][0:2]))
#print(min_len,int(token[3]))
if( last_seq == token[0]):
## Case1: No mis-matches
if( int(token[3])==int(min_len)&(int(token[4])==0)):
#print("match",min_len,int(token[3]),int(PMRD_seq[token[1]]),int(token_part[2]))
count_0 += 1
score = 1000
best_match = PMRD_seq[token[1]]
best_family = token[1]
## Case2: Exactly one mis-matches allowed ( min of both query and target seq are allowed to have one mismatch of start/end layoff
if((int(token[3])+1-int(token[4]))==int(min_len)):
count_1 +=1
if ( score < 100):
best_match = PMRD_seq[token[1]]
best_family = token[1]
score = 100
## Case3: Exactly two mis-matches allowed ( min of both query and target seq are allowed to have one mismatch of start/end layoff
if((int(token[3])+2-int(token[4]))==int(min_len)):
count_2 +=1
if ( score < 10):
best_match = PMRD_seq[token[1]]
best_family = token[1]
score = 10
## Case4: Exactly three mis-matches allowed ( min of both query and target seq are allowed to have one mismatch of start/end layoff
if((int(token[3])+3-int(token[4]))==int(min_len)):
count_3 +=1
if ( score < 1):
best_match = PMRD_seq[token[1]]
best_family = token[1]
score = 1
else:
continue
else:
print(last_seq+'\t'+str(count_0)+':'+str(count_1)+':'+str(count_2)+':'+str(count_3)+'\t'+best_match+'\t'+best_family)
if( best_match != "none"):
total_match_count += 1
count_0 = 0
count_1 = 0
count_2 = 0
count_3 = 0
best_match = "none"
best_family = "none"
number += 1
## Case2: One mis-matches allowed ( min of both query and target seq are allowed to have one mismatch of start/end layoff
last_seq = token[0]
print ( "total_match_count: ", total_match_count)
"""
"""
## for Browsed PMRD data files
## Update on 20110104
PMRD = open('/Users/vikasgupta/Desktop/tools/ncbi-blast-2.2.24+/db/20110104_PMRD_browseBased_9229.fa','r')
PMRD_seq = {}
PMRD_family = {}
PMRD_method = {}
PMRD_reference = {}
for line in PMRD.readlines():
line = line.strip()
if(line[0]=='>'):
key = line[1:]
else:
PMRD_seq[key] = line
a = 0
PMRD_data = open('/Users/vikasgupta/Desktop/plant/2011_week1/20110104/PMRD_species_wise_dataset.txt','r')
for line in PMRD_data.readlines():
line = line.strip()
token = line.split('\t')
if(token[0]=='1'):
reference = token[5]
if token[2] in PMRD_seq:
a += 1
PMRD_family[token[2]]= token[1]
PMRD_method[token[2]]= token[4]
PMRD_reference[token[2]]= reference
#print(PMRD_family[token[2]],token[2],PMRD_seq[token[2]])
f = open('/Users/vikasgupta/Desktop/plant/2011_week1/20110104/2010_12_29_einf_var_nonred_profiles_file3_blast_output_20110104_Browsed_PMRD.fasta','r')
last_seq = '1'
count_0 = 0
count_1 = 0
count_2 = 0
count_3 = 0
number = 1
### best hit equals best match
score = 0
best_match = "none"
best_family = "none"
method = "none"
reference = "none"
for line in f.readlines():
line =line.strip('\t')
token = line.split()
token_part = token[0].split('_')
parts = last_seq.split('_')
if(number < int(parts[0])):
for i in range(number,int(parts[0])):
print (str(i)+'\t'+'0:0:0:0'+'\t'+"none"+'\t'+"none"+'\t'+"none"+'\t'+"none")
x = 0
number = int(parts[0])
#print(line)
## token[1] is sequence header name
min_len = min(int(len(PMRD_seq[token[1]])),int(token_part[2]))
#print(min_len,int(token[3]))
if( last_seq == token[0]):
## Case1: No mis-matches
if( int(token[3])==int(min_len)&(int(token[4])==0)):
#print(int(token[3]), int(min_len),PMRD_seq[token[1]],last_seq)
#print("match",min_len,int(token[3]),int(PMRD_seq[token[1]]),int(token_part[2]))
count_0 += 1
if(score < 1000):
score = 1000
best_match = PMRD_seq[token[1]]
best_family = PMRD_family[token[1]]
method = PMRD_method[token[1]]
reference = PMRD_reference[token[1]]
#print(last_seq+'\t'+str(count_0)+':'+str(count_1)+':'+str(count_2)+':'+str(count_3)+'\t'+best_match+'\t'+best_family+'\t'+method+'\t'+reference)
#print(score)
## Case2: Exactly one mis-matches allowed ( min of both query and target seq are allowed to have one mismatch of start/end layoff
if((int(token[3])+1-int(token[4]))==int(min_len)):
count_1 +=1
if ( score < 100):
best_match = PMRD_seq[token[1]]
best_family = PMRD_family[token[1]]
method = PMRD_method[token[1]]
reference = PMRD_reference[token[1]]
score = 100
#print(last_seq+'\t'+str(count_0)+':'+str(count_1)+':'+str(count_2)+':'+str(count_3)+'\t'+best_match+'\t'+best_family+'\t'+method+'\t'+reference)
#print(score)
## Case3: Exactly two mis-matches allowed ( min of both query and target seq are allowed to have one mismatch of start/end layoff
if((int(token[3])+2-int(token[4]))==int(min_len)):
count_2 +=1
if ( score < 10):
best_match = PMRD_seq[token[1]]
best_family = PMRD_family[token[1]]
method = PMRD_method[token[1]]
reference = PMRD_reference[token[1]]
score = 10
#print(last_seq+'\t'+str(count_0)+':'+str(count_1)+':'+str(count_2)+':'+str(count_3)+'\t'+best_match+'\t'+best_family+'\t'+method+'\t'+reference)
#print(score)
## Case4: Exactly three mis-matches allowed ( min of both query and target seq are allowed to have one mismatch of start/end layoff
if((int(token[3])+3-int(token[4]))==int(min_len)):
count_3 +=1
if ( score < 1):
best_match = PMRD_seq[token[1]]
best_family = PMRD_family[token[1]]
method = PMRD_method[token[1]]
reference = PMRD_reference[token[1]]
score = 1
#print(last_seq+'\t'+str(count_0)+':'+str(count_1)+':'+str(count_2)+':'+str(count_3)+'\t'+best_match+'\t'+best_family+'\t'+method+'\t'+reference)
#print(score)
else:
continue
else:
print(last_seq+'\t'+str(count_0)+':'+str(count_1)+':'+str(count_2)+':'+str(count_3)+'\t'+best_match+'\t'+best_family+'\t'+method+'\t'+reference)
count_0 = 0
count_1 = 0
count_2 = 0
count_3 = 0
best_match = "none"
best_family = "none"
method = "none"
reference = "none"
number += 1
score = 0
## Case2: One mis-matches allowed ( min of both query and target seq are allowed to have one mismatch of start/end layoff
last_seq = token[0]
"""