File: spotToBed.py

package info (click to toggle)
pbsuite 15.8.24%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 14,512 kB
  • ctags: 1,951
  • sloc: python: 10,962; sh: 147; xml: 21; makefile: 14
file content (37 lines) | stat: -rwxr-xr-x 1,167 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/python
import sys
import argparse
from pbsuite.utils import VCFIO

USAGE = "Turn .spots results into a .bed"

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description=USAGE, \
                formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument("input", metavar="SPOTS", default='-', nargs="?", \
                        help="Results to convert (stdin)")
    parser.add_argument("-b", "--brief", action="store_true",\
                        help="Only output columns 1-4 of .bed")
    
    args = parser.parse_args()
    if args.input == '-':
        fh = sys.stdin
    else:
        fh = open(args.input,'r')
       
    for line in fh.readlines():
        if line.startswith("##"):
            continue
        elif line.startswith("#"):
            h = line.strip()[1:]
            header = {}
            for pos, item in enumerate(h.split('\t')):
                header[item] = pos
            continue
        chrom, s, e, type, size, info = line.strip().split('\t')
        name = "%s.%s" % (type, size)
        print "\t".join([chrom, s, e, name, type, size])
    fh.close()