forked from albertwcheng/RNASeqMappingScripts3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ebedToTophatJuncsFile.py
executable file
·78 lines (59 loc) · 1.69 KB
/
ebedToTophatJuncsFile.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
from sys import *
def printUsageAndExit(programName):
print >> stderr,programName,"inebed outjuncs"
exit(1)
if __name__=='__main__':
programName=argv[0]
args=argv[1:]
try:
inebed,outjuncs=args
except:
printUsageAndExit(programName)
juncSet=set()
fil=open(inebed)
fout=open(outjuncs,"w")
for lin in fil:
lin=lin.rstrip("\r\n")
if len(lin)<0:
continue
if lin[0]=='#':
continue
if lin[0:5]=='track':
continue
fields=lin.split("\t")
try:
chrom,chromStartG0,chromEndG1,name,score,strand,thickStartG0,thickEndG1,itemRGB,blockCount,blockSizes,blockStarts0=fields
chromStartG0=int(chromStartG0)
chromEndG1=int(chromEndG1)
thickStartG0=int(thickStartG0)
thickEndG1=int(thickEndG1)
blockCount=int(blockCount)
blockSizeSplits=blockSizes.split(",")
blockSizes=[]
for s in blockSizeSplits:
s=s.strip()
if len(s)>0:
blockSizes.append(int(s))
blockStarts0Splits=blockStarts0.split(",")
blockStarts0=[]
for s in blockStarts0Splits:
s=s.strip()
if len(s)>0:
blockStarts0.append(int(s))
if len(blockStarts0)!=blockCount or len(blockSizes)!=blockCount:
print >> stderr,"block count not consistent with blockStarts or blockSizes data"
raise ValueError
except:
print >> stderr,"format error",fields
raise ValueError
exonStartsG0=[]
exonEndsG1=[]
for bStart0,bSize in zip(blockStarts0,blockSizes):
exonStartsG0.append(bStart0+chromStartG0)
exonEndsG1.append(bStart0+chromStartG0+bSize)
for i in range(0,blockCount-1):
juncSet.add((chrom,exonEndsG1[i]-1,exonStartsG0[i+1],strand))
for a,b,c,d in juncSet:
print >> fout,"%s\t%d\t%d\t%s" %(a,b,c,d)
fil.close()
fout.close()