This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How can I get an allele count table from a .vcf file?

What's the most efficient way to generate a table of allele counts from a .vcf file? Ideally columns Chrom, Position, ref counts, and alt counts, across all sites in a vcf file? I think what I'm looking for is basically CollectAllelicCounts from GATK but on a vcf rather than bam file. Thanks.

gatk calling variant vcf

3 answers

$ bcftools stats in.vcf.gz | grep -wF ST
# ST, Substitution types:
# ST    [2]id   [3]type [4]count
ST  0   A>C 5
ST  0   A>G 5
ST  0   A>T 3
ST  0   C>A 5
ST  0   C>G 2
ST  0   C>T 0
ST  0   G>A 1
ST  0   G>C 4
ST  0   G>T 2
ST  0   T>A 4
ST  0   T>C 4
ST  0   T>G 5

With plink2:

plink2 --vcf in.vcf.gz --freq counts cols=chrom,pos,ref,alt,reffreq,altfreq

With TileDB-VCF (where uri is a TileDB-VCF dataset)

tiledbvcf.read_allele_frequency(uri, region=None)

Log in to answer this question.