File: get_exclude_regions.py

package info (click to toggle)
lumpy-sv 0.3.1%2Bdfsg-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 296,072 kB
  • sloc: cpp: 9,908; python: 1,768; sh: 1,384; makefile: 365; ansic: 322; perl: 58
file content (34 lines) | stat: -rwxr-xr-x 770 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
#!/usr/local/bin/python
import sys
import subprocess
import os
import numpy as np

if len(sys.argv) < 3:
    print('usage:' + sys.argv[0] + ' <max> <out file> <in bam 1> <in bam 2> <..>')
    exit(1)

max_c = int(sys.argv[1])
out_file = sys.argv[2]

o = open('.exclude.tmp','w')

for i in range(3,len(sys.argv)):
    bam_file = sys.argv[i]
    coverage_file = bam_file + '.coverage'

    f = open(coverage_file, 'r')
    for l in f:
        a = l.rstrip().split('\t')
        if (int(a[3]) > max_c):
            o.write(l)
    f.close()
o.close()

p = subprocess.Popen(\
        'cat .exclude.tmp | ' \
        'sort -S 20G -k1,1 -k2,2n | ' \
        'bedtools merge -i stdin -d 50 ' \
        '> ' + out_file, shell=True)
os.waitpid(p.pid, 0)
os.unlink('.exclude.tmp')