-
Notifications
You must be signed in to change notification settings - Fork 1
/
bed2pip
executable file
·50 lines (43 loc) · 1.28 KB
/
bed2pip
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
#!/usr/bin/env python
from sys import *
import sys
from re import *
if len(argv)==2 and argv[1]=="-h":
print "converts ucsc bed GENE extract to pip-acceptable feature-file"
print "needs BLOCKS (whole gene models) as input."
print " syntax: "
print " cat test.bed | bed2pip"
exit()
#f = open(argv[1], 'r')
lines = stdin.readlines()
#convert lines
for line in lines:
if line.startswith("track"):
continue
if line.strip()=="":
continue
fields = line.split()
bedstart = int(fields[1])
if bedstart < 0:
stderr.write("warning: replaced negative coordinates with 0\n")
bedstart = 0
bedend = int(fields[2])
name = "exon"
strand = ""
if (len(fields)>3):
name = fields[3]
if (len(fields)>4):
strand = fields[5]
if (len(fields)>8):
blockStarts=fields[11].strip(",").split(",")
blockSizes=fields[10].strip(",").split(",")
if strand.strip() == "+":
vistastrand="> "
else:
if (strand.strip() == "-"):
vistastrand="< "
else:
vistastrand=""
print vistastrand+" ".join([str(bedstart)," ",str(bedend)," ",name])
for start,size in zip(blockStarts,blockSizes):
print bedstart+int(start), bedstart+int(start)+int(size)+1