-
Notifications
You must be signed in to change notification settings - Fork 1
/
bedNumberExons
executable file
·45 lines (36 loc) · 1.36 KB
/
bedNumberExons
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
#!/usr/bin/env python
import logging, sys, optparse
from collections import defaultdict
from os.path import join, basename, dirname, isfile
from collections import defaultdict
# === COMMAND LINE INTERFACE, OPTIONS AND HELP ===
parser = optparse.OptionParser("usage: %prog [options] filename - read bed from stdin, add a number to the name field to indicate the exon")
parser.add_option("-d", "--debug", dest="debug", action="store_true", help="show debug messages")
#parser.add_option("-f", "--file", dest="file", action="store", help="run on file")
#parser.add_option("", "--test", dest="test", action="store_true", help="do something")
(options, args) = parser.parse_args()
if options.debug:
logging.basicConfig(level=logging.DEBUG)
else:
logging.basicConfig(level=logging.INFO)
# ==== FUNCTIONs =====
# ----------- MAIN --------------
#if args==[]:
#parser.print_help()
#exit(1)
beds = []
lastName = None
for line in sys.stdin:
row = line.rstrip("\n").split()
name = row[3]
if name!=lastName and lastName!=None:
for i, bed in enumerate(beds):
if bed[5]=="+":
bed[3] = bed[3]+"|exon%d" % (i+1)
else:
bed[3] = bed[3]+"|exon%d" % (len(beds)-i)
print "\t".join(bed)
beds = []
lastName = name
beds.append(row)
#chrom, start, end, name, score, strand