-
Notifications
You must be signed in to change notification settings - Fork 2
/
crossRepFormat2ebed.py
executable file
·81 lines (56 loc) · 1.43 KB
/
crossRepFormat2ebed.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
#!/usr/bin/env python
from sys import *
def printUsageAndExit(programName):
print >> stderr,programName,"crossRepIn > outEbed"
exit(1)
def fromCrossesToEbedStruct(cross):
gStart=-1
eStart=-1
blockStarts0=[]
blockSizes=[]
for i in range(0,len(cross)):
if cross[i] in ['>','<','x']:
if gStart==-1:
gStart=i
if eStart==-1:
eStart=i-gStart
else:
if eStart>=0:
blockStarts0.append(eStart)
blockSizes.append(i-eStart-gStart)
eStart=-1
if eStart>=0:
blockStarts0.append(eStart)
blockSizes.append(len(cross)-eStart-gStart)
gend1=blockSizes[-1]+blockStarts0[-1]+gStart
return gStart,gend1,blockStarts0,blockSizes
def toStrList(L):
sL=[]
for x in L:
sL.append(str(x))
return sL
if __name__=='__main__':
programName=argv[0]
args=argv[1:]
try:
filename,=args
except:
printUsageAndExit(programName)
fil=open(filename)
for lin in fil:
lin=lin.rstrip("\r\n")
if len(lin)==0 or lin[0]=="#":
continue
name,chrom,cross=lin.split(",")
if '>' in cross:
strand="+"
elif '<' in cross:
strand="-"
else:
strand="."
gstart0,gend1,blockStarts,blockSizes=fromCrossesToEbedStruct(cross)
blockCount=len(blockStarts)
blockStarts=",".join(toStrList(blockStarts))
blockSizes=",".join(toStrList(blockSizes))
print >> stdout,"\t".join(toStrList((chrom,gstart0,gend1,name,0,strand,gstart0,gend1,"0,0,0",blockCount,blockSizes,blockStarts)))
fil.close()