File: prob_bedpe_to_bedgraph.py

package info (click to toggle)
lumpy-sv 0.3.1%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 296,072 kB
  • sloc: cpp: 9,908; python: 1,768; sh: 1,384; makefile: 365; ansic: 322; perl: 58
file content (67 lines) | stat: -rwxr-xr-x 1,315 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python
import sys
import numpy as np

from optparse import OptionParser

parser = OptionParser()

parser.add_option("-i",
    "--bedpe",
    dest="bedpe",
    help="BEDPE file")

parser.add_option("-n",
    "--name",
    default="LUMPY BedGraph",
    dest="name",
    help="Name")


(options, args) = parser.parse_args()

if not options.bedpe:
    parser.error('BEDPE file not given')

f = open(options.bedpe,'r')

print('track type=bedGraph name="' + options.name + '"')

for line in f:
    if line[0] == '#':
        continue

    v = line.rstrip().split('\t')
    info = dict()
    for s in v[12].split(';'):
        s_v = s.split('=')
        if len(s_v) == 2:
            info[s_v[0]] = s_v[1]

    L=[float(x) for x in info['PRPOS'].split(',')]
    R=[float(x) for x in info['PREND'].split(',')]

    l_chr = v[0]
    l_start = int(v[1])

    r_chr = v[3]
    r_start = int(v[4])

    c = 0
    for p in L:
        print('\t'.join( [l_chr,
                          str(l_start + c),
                          str(l_start + c + 1),
                          str(p)]))
        c+=1

    c = 0
    for p in R:
        print('\t'.join( [r_chr,
                          str(r_start + c),
                          str(r_start + c + 1),
                          str(p)]))
        c+=1


f.close()