-
Notifications
You must be signed in to change notification settings - Fork 9
/
12h.py
executable file
·89 lines (77 loc) · 1.94 KB
/
12h.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
# Uses : python 20101206_cluster_analysis.py /Users/vikas0633/Desktop/plant/20101204_gtf/all_compose_sorted.gtf /Users/vikasgupta/Desktop/plant/20101115_sRNA_cluster/all_sRNA_cluster.bed cluster_position_on_genome.xls
import sys, time
start = time.clock()
infile2 = sys.argv[2] ### cluster.bed
count=0
def hash(last_id,id,last_ch,last_st,last_en,ch,st,en):
if(id!=last_id):
exon[st,en,ch]='exonic-intergenic overlap'
inter[last_en,st,ch]='exon-intergenic overlap'
else:
exon[st,en,ch]='exon-intron overlap'
intron[last_en,st,ch]='exon-intron overlap'
return id,ch,st,en,exon,intron,inter
### hash the compose genome into hash
exon={}
intron={}
inter={}
last_id=''
last_ch=0
last_st=0
last_en=0
### all_compose_sorted.gtf
for line in open(sys.argv[1],'r'):
line = line.strip()
token= line.split('\t')
if token[2] == 'exon':
id=token[8]
ch= token[0]
st=int(token[3])
en=int(token[4])
last_id,last_ch,last_st,last_en,exon,intron,inter=hash(last_id,id,last_ch,last_st,last_en,ch,st,en)
### cluster.bed
header=True
for line in open(sys.argv[2],'r'):
line=line.strip()
flag=0
if(header==True):
header=False
print (line+'\t'+'genomic region')
else:
token=line.split('\t')
ch=token[0]
st=int(token[1])
en=int(token[2])
### check where start lies
for key in exon:
if((key[0] < en < key[1])&(key[2]==token[0])):
if(key[0] < st):
print(line+'\t'+'exonic')
flag=1
else:
print(line+'\t'+exon[key])
flag=1
else:
continue
for key in intron:
if((key[0] < en < key[1])&(key[2]==token[0])):
if(key[0] < st):
print (line+'\t'+"intronic")
flag=1
else:
print(line+'\t'+intron[key])
flag=1
else:
continue
for key in inter:
if((key[0] <= en <= key[1])&(key[2]==token[0])):
if(key[0] <= st):
print(line+'\t'+'intergenic')
flag=1
else:
print(line+'\t'+inter[key])
flag=1
else:
continue
if(flag==0):
print(line+'\t'+'overlapping')