File: vcf_sample_filter.py

package info (click to toggle)
python-pyvcf 0.6.8%2Bgit20170215.476169c-9
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,816 kB
  • sloc: python: 2,924; makefile: 124; sh: 19
file content (39 lines) | stat: -rw-r--r-- 1,264 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
#!/usr/bin/env python

# Author: Lenna X. Peterson
# github.com/lennax
# arklenna at gmail dot com

import argparse
import logging

from vcf import SampleFilter


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("file", help="VCF file to filter")
    parser.add_argument("-o", metavar="outfile",
                       help="File to write out filtered samples")
    parser.add_argument("-f", metavar="filters",
                       help="Comma-separated list of sample indices or names \
                        to filter")
    parser.add_argument("-i", "--invert", action="store_true",
                       help="Keep rather than discard the filtered samples")
    parser.add_argument("-q", "--quiet", action="store_true",
                       help="Less output")

    args = parser.parse_args()

    if args.quiet:
        log_level = logging.WARNING
    else:
        log_level = logging.INFO
    logging.basicConfig(format='%(message)s', level=log_level)

    sf = SampleFilter(infile=args.file, outfile=args.o,
                      filters=args.f, invert=args.invert)
    if args.f is None:
        print("Samples:")
        for idx, val in enumerate(sf.samples):
            print("{0}: {1}".format(idx, val))