Question: Hi,

I need to add into my VCFs the AF INFO field, which is not output when variant calling with samtools/bcftools.

I think this can be done with the bcftools annotate command and the AF tag is mentioned in the Expressions part of the bcftools man page. (http://www.htslib.org/doc/bcftools.html#expressions)

But I can't determine how to apply this to my vcf.

For example i've tried:

bcftools annotate -a MyVCF.vcf.gz -c FORMAT,INFO,AF -o test.vcf -O v MyVCF.vcf.gz -h annots.hdr

where `annots.hdr` is a text file with:

##INFO=

The header is added in but the calculation on AC/AN is not conducted.

Any suggestions?

Thanks.

Answer: 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