Skip to content

Instantly share code, notes, and snippets.

@mdshw5
Last active July 25, 2016 15:42
Show Gist options
  • Save mdshw5/98a1c51e0c5f76683a63f770f48f91cb to your computer and use it in GitHub Desktop.
Save mdshw5/98a1c51e0c5f76683a63f770f48f91cb to your computer and use it in GitHub Desktop.
biostars 203117
from pyfaidx import FastaVariant
import vcf
samples = vcf.Reader(open('calls.vcf.gz', 'r')).samples
for sample in samples:
with FastaVariant('reference.fasta', 'calls.vcf.gz', sample=sample, het=True, hom=True) as consensus:
with open(sample + '.fasta', 'w') as sample_fasta:
for record in consensus:
sample_fasta.write('>' + record.long_name)
sample_fasta.write(str(record))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment