The solution is posted on GitHub: https://github.com/samtools/bcftools/issues/345
1, get the latest htslib and BCFtools, and set-up the BCFtools plugins:
git clone git://github.com/samtools/htslib.git
git clone git://github.com/samtools/bcftools.git
cd bcftools; make
sudo make install
Note the directory where the plugins were installed: /usr/local/libexec/bcftools
export BCFTOOLS_PLUGINS=/usr/local/libexec/bcftools
--------------------------------------
NB - if you don't have root / super-user privileges, then you can avoid the make install
command and set the BCFTOOLS_PLUGINS environmental variable to the 'plugins' directory, which will be located under bcftools/ where you downloaded the program. For example export BCFTOOLS_PLUGINS=/Programs/bcftools/plugins/
---------------------------------
2, View the VCF without AF
bcftools view test.vcf | tail -5
[W::bcf_hdr_check_sanity] PL should be declared as Number=G
5 135337248 . CT C . PASS END=135337249;HOMLEN=3;HOMSEQ=TTT;SVLEN=-1;SVTYPE=DEL;AC=1;AN=2 GT:AD 0/1:205,118
5 135337259 . AG A . PASS END=135337260;HOMLEN=4;HOMSEQ=GGGG;SVLEN=-1;SVTYPE=DEL;AC=1;AN=2 GT:AD 0/1:190,220
5 135337259 . A AG . PASS END=135337259;HOMLEN=5;HOMSEQ=GGGGG;SVLEN=1;SVTYPE=INS;AC=1;AN=2 GT:AD 0/1:192,71
5 135337264 . GA G . PASS END=135337265;HOMLEN=1;HOMSEQ=A;SVLEN=-1;SVTYPE=DEL;AC=1;AN=2 GT:AD 0/1:184,83
5 135337274 . A ATTATTGCATCAACTCCTCCGACATCTCTTCCCCTGCAAGAGTTCAGGCCCACAGGTTCTGGTGTGGGCTTGCTCAGCTGGAGGTAGCCTGAGGTGAGCTGGAG .PASS END=135337274;HOMLEN=23;HOMSEQ=TTATTGCATCAACTCCTCCGACA;SVLEN=103;SVTYPE=INS;AC=1;AN=2 GT:AD 0/1:130,17
3, Now add the AF
bcftools +fill-tags test.vcf -- -t AF | tail -5
[W::bcf_hdr_check_sanity] PL should be declared as Number=G
5 135337248 . CT C . PASS END=135337249;HOMLEN=3;HOMSEQ=TTT;SVLEN=-1;SVTYPE=DEL;AC=1;AN=2;AF=0.5 GT:AD 0/1:205,118
5 135337259 . AG A . PASS END=135337260;HOMLEN=4;HOMSEQ=GGGG;SVLEN=-1;SVTYPE=DEL;AC=1;AN=2;AF=0.5 GT:AD 0/1:190,220
5 135337259 . A AG . PASS END=135337259;HOMLEN=5;HOMSEQ=GGGGG;SVLEN=1;SVTYPE=INS;AC=1;AN=2;AF=0.5 GT:AD 0/1:192,71
5 135337264 . GA G . PASS END=135337265;HOMLEN=1;HOMSEQ=A;SVLEN=-1;SVTYPE=DEL;AC=1;AN=2;AF=0.5 GT:AD 0/1:184,83
5 135337274 . A ATTATTGCATCAACTCCTCCGACATCTCTTCCCCTGCAAGAGTTCAGGCCCACAGGTTCTGGTGTGGGCTTGCTCAGCTGGAGGTAGCCTGAGGTGAGCTGGAG .PASS END=135337274;HOMLEN=23;HOMSEQ=TTATTGCATCAACTCCTCCGACA;SVLEN=103;SVTYPE=INS;AC=1;AN=2;AF=0.5 GT:AD 0/1:130,17
4, add all available tags in plugin
bcftools +fill-tags test.vcf | tail -5
[W::bcf_hdr_check_sanity] PL should be declared as Number=G
5 135337248 . CT C . PASS END=135337249;HOMLEN=3;HOMSEQ=TTT;SVLEN=-1;SVTYPE=DEL;AC=1;AN=2;NS=1;AF=0.5;MAF=0.5;AC_Het=1;AC_Hom=0;AC_Hemi=0;HWE=1;ExcHet=1 GT:AD 0/1:205,118
5 135337259 . AG A . PASS END=135337260;HOMLEN=4;HOMSEQ=GGGG;SVLEN=-1;SVTYPE=DEL;AC=1;AN=2;NS=1;AF=0.5;MAF=0.5;AC_Het=1;AC_Hom=0;AC_Hemi=0;HWE=1;ExcHet=1 GT:AD 0/1:190,220
5 135337259 . A AG . PASS END=135337259;HOMLEN=5;HOMSEQ=GGGGG;SVLEN=1;SVTYPE=INS;AC=1;AN=2;NS=1;AF=0.5;MAF=0.5;AC_Het=1;AC_Hom=0;AC_Hemi=0;HWE=1;ExcHet=1 GT:AD 0/1:192,71
5 135337264 . GA G . PASS END=135337265;HOMLEN=1;HOMSEQ=A;SVLEN=-1;SVTYPE=DEL;AC=1;AN=2;NS=1;AF=0.5;MAF=0.5;AC_Het=1;AC_Hom=0;AC_Hemi=0;HWE=1;ExcHet=1 GT:AD 0/1:184,83
5 135337274 . A ATTATTGCATCAACTCCTCCGACATCTCTTCCCCTGCAAGAGTTCAGGCCCACAGGTTCTGGTGTGGGCTTGCTCAGCTGGAGGTAGCCTGAGGTGAGCTGGAG .PASS END=135337274;HOMLEN=23;HOMSEQ=TTATTGCATCAACTCCTCCGACA;SVLEN=103;SVTYPE=INS;AC=1;AN=2;NS=1;AF=0.5;MAF=0.5;AC_Het=1;AC_Hom=0;AC_Hemi=0;HWE=1;ExcHet=1 GT:AD 0/1:130,17
Kevin
Shortcut just to filter on AF:
from here
Works as long as you have the fields
INFO/AC
andINFO/AN
alreadyThis is not a relevant answer to the top level question. This command filters on AF when AF information is already available in the VCF, whereas the question is on calculating AF from AC and AN. I'm moving this post to a comment. Please be careful and read the question carefully before adding answers - especially on older questions.