File: bedpe_sort.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 (57 lines) | stat: -rwxr-xr-x 933 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
#!/usr/bin/env python
import sys
import numpy as np
from operator import itemgetter
from optparse import OptionParser

parser = OptionParser()

parser.add_option("-b",
    "--bedpe_file",
    dest="bedpe_file",
    help="BEDPE file")

parser.add_option("-g",
    "--genome_file",
    dest="genome_file",
    help="Genome file")


(options, args) = parser.parse_args()

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

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

B = {}

for l in f:
    A = l.rstrip().split('\t')

    if not A[0] in B:
        B[A[0]] = []

    B[A[0]].append([int(A[1]), l.rstrip()])

f.close()

order=[]

if options.genome_file:
    f = open(options.genome_file,'r')

    for l in f:
        A = l.rstrip().split('\t')
        order.append(A[0])

    f.close()
else:
    order = sorted(B.keys())



for c in order:
    if c in B:
        for l in sorted(B[c], key=itemgetter(0)):
            print(l[1])