Created
June 23, 2022 11:33
-
-
Save stephenturner/9f80b8e07bd160b237b51fcbdd9c06a1 to your computer and use it in GitHub Desktop.
Adds AD=2 to VCF on a stream
This file contains hidden or 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 | |
# Adds allelic depth (AD)=2 to a VCF. | |
# Usage: bcftools view my.vcf.gz | addad.py | bcftools sort -Oz -o my.ad.vcf.gz && tabix my.ad.vcf.gz | |
import pysam | |
vcf_in=pysam.VariantFile("-","r") | |
vcf_in.header.formats.add("AD",".","Integer","Allelic depth, hard-coded as 2") | |
print(vcf_in.header, end='') | |
for variant in vcf_in: | |
for sample in variant.samples: | |
variant.samples[sample]['AD']=2 | |
print(variant, end='') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment