-
Notifications
You must be signed in to change notification settings - Fork 0
/
FishProbeFinderAD.py
198 lines (188 loc) · 8.16 KB
/
FishProbeFinderAD.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
#!/usr/bin/env python
#This script will take blast output to and decide output the number of hits that fall within the range of the centromere and those that dont
import numpy as np
import sys
from collections import Counter
import pandas as pd
from collections import defaultdict
infile = open(sys.argv[1], 'r')
#outfile = open(sys.argv[2], "w")
defined = []
for line in infile:
col1 = line.split("\t")[0]
col2 = line.split("\t")[1]
col3 = line.split("\t")[8]
position = int(col3)
positionA = 0
positionB = 1000000
if col2 == "A01" or col2 == "Chr1" or col2== "At_chr1":
while not position <= positionA and position >= positionB:
positionA += 1000000
positionB += 1000000
defined.append(col1 + "\t " + col2 + "\t" + str(positionA))
if col2 == "A02" or col2 == "Chr2" or col2== "At_chr2" :
while not position <= positionA and position >= positionB:
positionA += 1000000
positionB += 1000000
defined.append(col1 + "\t " + col2 + "\t" + str(positionA))
if col2 == "A03" or col2 == "Chr3" or col2== "At_chr3":
while not position <= positionA and position >= positionB:
positionA += 1000000
positionB += 1000000
defined.append(col1 + "\t" + col2 + "\t" + str(positionA))
if col2 == "A04" or col2 == "Chr4" or col2== "At_chr4":
while not position <= positionA and position >= positionB:
positionA += 1000000
positionB += 1000000
defined.append( col1 + "\t" + col2 + "\t" + str(positionA))
if col2 == "A05" or col2 == "Chr5" or col2== "At_chr5":
while not position <= positionA and position >= positionB:
positionA += 1000000
positionB += 1000000
defined.append(col1 + "\t" + col2 + "\t " + str(positionA))
if col2 == "A06" or col2 == "Chr6" or col2== "At_chr6":
while not position <= positionA and position >= positionB:
positionA += 1000000
positionB += 1000000
defined.append(col1 + "\t" + col2 + "\t" + str(positionA))
if col2 == "A07" or col2 == "Chr7" or col2== "At_chr7":
while not position <= positionA and position >= positionB:
positionA += 1000000
positionB += 1000000
defined.append(col1 + "\t" + col2 + "\t" + str(positionA))
if col2 == "A08" or col2 == "Chr8" or col2== "At_chr8":
while not position <= positionA and position >= positionB:
positionA += 1000000
positionB += 1000000
defined.append(col1 + "\t" + col2 + "\t" + str(positionA))
if col2 == "A09" or col2 == "Chr9" or col2== "At_chr9":
while not position <= positionA and position >= positionB:
positionA += 1000000
positionB += 1000000
defined.append(col1 + "\t" + col2 + "\t" + str(positionA))
if col2 == "A10" or col2 == "At_chr10":
while not position <= positionA and position >= positionB:
positionA += 1000000
positionB += 1000000
defined.append(col1 + "\t" + col2 + "\t" + str(positionA))
if col2 == "A11" or col2== "At_chr11":
while not position <= positionA and position >= positionB:
positionA += 1000000
positionB += 1000000
defined.append(col1 + "\t" + col2 + "\t" + str(positionA))
if col2 == "A12" or col2== "At_chr12":
while not position <= positionA and position >= positionB:
positionA += 1000000
positionB += 1000000
defined.append(col1 + "\t" + col2 + "\t" + str(positionA))
if col2 == "A13" or col2== "At_chr13":
while not position <= positionA and position >= positionB:
positionA += 1000000
positionB += 1000000
defined.append(col1 + "\t" + col2 + "\t" + str(positionA))
if col2== "Dt_chr1" or col2 == "D01":
while not position <= positionA and position >= positionB:
positionA += 1000000
positionB += 1000000
defined.append(col1 + "\t " + col2 + "\t" + str(positionA))
if col2== "Dt_chr2" or col2 == "D02":
while not position <= positionA and position >= positionB:
positionA += 1000000
positionB += 1000000
defined.append(col1 + "\t " + col2 + "\t" + str(positionA))
if col2== "Dt_chr3" or col2 == "D03":
while not position <= positionA and position >= positionB:
positionA += 1000000
positionB += 1000000
defined.append(col1 + "\t" + col2 + "\t" + str(positionA))
if col2== "Dt_chr4" or col2 == "D04":
while not position <= positionA and position >= positionB:
positionA += 1000000
positionB += 1000000
defined.append( col1 + "\t" + col2 + "\t" + str(positionA))
if col2 == "Dt_chr5"or col2 == "D05":
while not position <= positionA and position >= positionB:
positionA += 1000000
positionB += 1000000
defined.append(col1 + "\t" + col2 + "\t " + str(positionA))
if col2== "Dt_chr6"or col2 == "D06":
while not position <= positionA and position >= positionB:
positionA += 1000000
positionB += 1000000
defined.append(col1 + "\t" + col2 + "\t" + str(positionA))
if col2 == "Dt_chr7" or col2 == "D07":
while not position <= positionA and position >= positionB:
positionA += 1000000
positionB += 1000000
defined.append(col1 + "\t" + col2 + "\t" + str(positionA))
if col2 == "Dt_chr8" or col2 == "D08":
while not position <= positionA and position >= positionB:
positionA += 1000000
positionB += 1000000
defined.append(col1 + "\t" + col2 + "\t" + str(positionA))
if col2 == "Dt_chr9" or col2 == "D09":
while not position <= positionA and position >= positionB:
positionA += 1000000
positionB += 1000000
defined.append(col1 + "\t" + col2 + "\t" + str(positionA))
if col2 == "Dt_chr10" or col2 == "D10":
while not position <= positionA and position >= positionB:
positionA += 1000000
positionB += 1000000
defined.append(col1 + "\t" + col2 + "\t" + str(positionA))
if col2== "Dt_chr11" or col2 == "D11":
while not position <= positionA and position >= positionB:
positionA += 1000000
positionB += 1000000
defined.append(col1 + "\t" + col2 + "\t" + str(positionA))
if col2 == "Dt_chr12" or col2 == "D12":
while not position <= positionA and position >= positionB:
positionA += 1000000
positionB += 1000000
defined.append(col1 + "\t" + col2 + "\t" + str(positionA))
if col2== "Dt_chr13" or col2 == "D13":
while not position <= positionA and position >= positionB:
positionA += 1000000
positionB += 1000000
defined.append(col1 + "\t" + col2 + "\t" + str(positionA))
counter = defaultdict(int)
##counts the number of blast hits in each bin
for row in defined:
counter[row] += 1
##converts dictionary to list
sums = []
for key in counter:
combine = key + "\t" + str(counter[key])
sums.append(combine)
prevent = []
for entry in sums:
zap = entry.split("\t")[0]
# print entry
prevent.append(zap)
unique = set(prevent)
#print unique
### associates total number of blast hits for each query to the query name
recount = []
for entry in unique:
total = 0
for row in sums:
col1 = row.split("\t")[0]
col4 = row.split("\t")[3]
if col1 == entry:
total = total + int(col4)
recount.append(entry + "\t" + str(total))
# print recount
##prints list of top hits if greater than 25% of blast hits fall into one bin
for row in recount:
column1 = row.split("\t")[0]
column2 = row.split("\t")[1]
for line in sums:
indivcol1 = line.split("\t")[0]
indivcol4 = line.split("\t")[3]
# print indivcol4
if column1 == indivcol1:
percent = float(indivcol4)/float(column2)
# print indivcol1 + str(percent)
if percent >= .002:
if int(indivcol4) > 9:
print line + "\t" + str(percent)