Created
October 22, 2015 14:09
-
-
Save martijnvermaat/c414b85af6c400fee19d to your computer and use it in GitHub Desktop.
CSV with allele frequencies from GoNL VCF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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