Mercurial > repos > jpayne > snp_pipeline
annotate snp-filter.py @ 0:eefdd97a6749
planemo upload commit b'7f6183b769772449fbcee903686b8d5ec5b7439f\n'-dirty
author | jpayne |
---|---|
date | Wed, 24 Jan 2018 14:18:21 -0500 |
parents | |
children |
rev | line source |
---|---|
jpayne@0 | 1 from Bio import SeqIO |
jpayne@0 | 2 import vcf |
jpayne@0 | 3 |
jpayne@0 | 4 |
jpayne@0 | 5 import argparse |
jpayne@0 | 6 import os |
jpayne@0 | 7 import sys |
jpayne@0 | 8 |
jpayne@0 | 9 def passes(vcf_feature, contigs, edge_length=500, window_size=1000, max_snps=3): |
jpayne@0 | 10 return True |
jpayne@0 | 11 |
jpayne@0 | 12 def main(input_vcf, input_reference, output_included, output_excluded=os.devnull, *args, **kwargs) |
jpayne@0 | 13 contigs = list(SeqIO.parse(input_reference, 'fasta')) |
jpayne@0 | 14 included = vcf.Writer(output_included) |
jpayne@0 | 15 excluded = vcf.Writer(output_excluded) |
jpayne@0 | 16 for feature in vcf.Reader(input_vcf): |
jpayne@0 | 17 if passes(feature, contigs, *args, **kwargs): |
jpayne@0 | 18 included.write(feature) |
jpayne@0 | 19 else: |
jpayne@0 | 20 excluded.write(feature) |
jpayne@0 | 21 |
jpayne@0 | 22 if __name__ == '__main__': |
jpayne@0 | 23 parser = argparse.ArgumentParser() |
jpayne@0 | 24 parser.add_argument('input_vcf', type=argparse.FileType()) |
jpayne@0 | 25 parser.add_argument('input_reference', type=argparse.FileType()) |
jpayne@0 | 26 parser.add_argument('output_included', type=argparse.FileType('w')) |
jpayne@0 | 27 parser.add_argument('--excluded', '-x', dest='output_excluded', type=argparse.FileType('w'), default=os.devnull) |