-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRemoveOverlappingGenes.py
More file actions
executable file
·50 lines (41 loc) · 1.04 KB
/
RemoveOverlappingGenes.py
File metadata and controls
executable file
·50 lines (41 loc) · 1.04 KB
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
#!/usr/bin/env python
import sys
def GetForwardCoordinates(aln):
# pdb.set_trace()
return (int(aln[1]), int(aln[2]))
def FractionOverlap(alnsA, alnsB):
if alnsA[0] != alnsB[0]:
return 0
fa=GetForwardCoordinates(alnsA)
fb=GetForwardCoordinates(alnsB)
ovp=0
la=fa[1]-fa[0]
lb=fb[1]-fb[0]
if (fa[0] <= fb[0] and fa[1] >= fb[0]):
ovp=min(fb[1], fa[1]) - fb[0]
if (fa[0] >= fb[0] and fa[0] <= fb[1]):
ovp = min(fb[1], fa[1]) - fa[0]
return max(ovp/la, ovp/lb)
prevGene=None
inFile=sys.stdin
lines = inFile.readlines()
i=0
j=0
keep=[True] * len(lines)
while i < len(lines):
vals=lines[i].split()
curGene=vals[3]
j=i+1
while (j < len(lines)):
nextVals=lines[j].split()
nextGene=nextVals[3]
if nextGene == curGene:
if FractionOverlap(vals, nextVals) > 0.1:
keep[j] = False
j+=1
else:
break
i+=1
for i in range(0,len(lines)):
if keep[i]:
sys.stdout.write(lines[i])