Skip to content

Instantly share code, notes, and snippets.

@martijnvermaat
Created October 22, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martijnvermaat/c414b85af6c400fee19d to your computer and use it in GitHub Desktop.
Save martijnvermaat/c414b85af6c400fee19d to your computer and use it in GitHub Desktop.
CSV with allele frequencies from GoNL VCF
#!/usr/bin/env python
#
# CSV with allele frequencies from GoNL VCF.
#
# https://molgenis26.target.rug.nl/downloads/gonl_public/variants/release5/
import sys
from vcf import Reader
def main(filenames):
print '%s\t%s\t%s\t%s\t%s\t%s\t%s' % (
'CHROM', 'POS', 'REF', 'ALT', 'TOTAL_ALLELES', 'ALT_ALLELES', 'ALT_FREQ')
for filename in filenames:
reader = Reader(filename=filename)
for record in reader:
if record.var_type != 'snp':
continue
for alt, ac, af in zip(record.ALT,
record.INFO['AC'],
record.INFO['AF']):
print '%s\t%d\t%s\t%s\t%d\t%d\t%f' % (record.CHROM,
record.POS,
record.REF,
alt,
record.INFO['AN'],
ac,
af)
if __name__ == '__main__':
main(sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment