File: vcf2bed.py

package info (click to toggle)
libvcflib 1.0.12%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 70,520 kB
  • sloc: cpp: 39,837; python: 532; perl: 474; ansic: 317; ruby: 295; sh: 254; lisp: 148; makefile: 123; javascript: 94
file content (17 lines) | stat: -rwxr-xr-x 466 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/usr/bin/env python3
# Transform VCF to BED file
#
import sys

for line in sys.stdin:
    if line.startswith('#'):
        continue
    fields = line.strip().split()
    # VCF is 1-based, BED is 0-based half open
    # print out chrom, start, end, 
    chrom = fields[0]
    start = int(fields[1]) - 1
    span = len(fields[3]) # handle multi-base alleles
    end = start + span
    name = fields[2]
    print("\t".join(str(x) for x in [chrom, start, end, name]))