This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Count all variants from vcf file

I have vcf files from gatk pipleline, now I want to count all the variants in a file. Can anyone help? Thanks

variants vcf count
zgrep -cv "^#" <vcf_file>

2 answers

Hello! You can use bcftools query -f "A\n" <your_vcf> | wc -l

I tried this and it worked. Thanks alot

bcftools query -N -f '.' in.vcf | wc -c

or

  bcftools index -s indexed.vcf.gz |  cut -f 3 |  paste -s -d '+' | bc

EDIT 2024: there is now a new behavior in bcftools query:

    -N, --disable-automatic-newline   Disable automatic addition of newline character when not present

Log in to answer this question.