bcftools icon indicating copy to clipboard operation
bcftools copied to clipboard

Bcftools annotate overwrite existing tag

Open valeandri opened this issue 2 years ago • 2 comments

Hi,

I am trying to add the FORMAT/DP tag to a vcf taking the depth information from a bed file. I only want to add the tag if not already present in the vcf.

The code I am using is the following:

echo -e '##FORMAT=<ID=DP,Number=1,Type=Integer,Description="Read depth">' >> hdr.txt
bcftools annotate -a coverage.bed.gz -h hdr.tx -c CHROM,FROM,TO,+FORMAT/DP sample.vcf.gz | bgzip > sample.DP.vcf.gz

The coverage.bed.gz looks like the following:

zcat coverage.bed.gz
chr1	10000	10005	0
chr1	10005	10008	3
chr1	10008	10019	4
chr1	10019	10035	6
chr1	10035	10052	7
chr1	10052	10094	8
chr1	10094	10106	7
chr1	10106	10109	5
chr1	10109	10110	4
chr1	10110	10118	1

I tested both 1.15.1 and 1.10.2 versions.

Even if using the "+TAG" option, the FORMAT:DP is overwritten even if it already exists. Here an example:

Original file:

chr1	10904	.	G	A	15.93	PASS	AC=2;AF=1.000;AN=2;DP=11;FS=0.000;MQ=28.72;MQRankSum=1.733;QD=4.23;ReadPosRankSum=0.480;SOR=0.859;FractionInformativeReads=0.909	GT:AD:AF:DP:F1R2:F2R1:GQ:PL:GP:PRI:SB:MB:PS	1|1:2,8:0.8000:10:1,5:1,3:8:53,12,0:1.5931e+01,9.3190e+00,6.6765e-01:0.00,34.77,37.77:0,2,5,3:1,1,8,0:10904

Output file:

chr1	10904	.	G	A	15.93	PASS	AC=2;AF=1;AN=2;DP=11;FS=0;MQ=28.72;MQRankSum=1.733;QD=4.23;ReadPosRankSum=0.48;SOR=0.859;FractionInformativeReads=0.909	GT:AD:AF:DP:F1R2:F2R1:GQ:PL:GP:PRI:SB:MB:PS	1|1:2,8:0.8:0:1,5:1,3:8:53,12,0:15.931,9.319,0.66765:0,34.77,37.77:0,2,5,3:1,1,8,0:10904

As you can see, the value 10 is replaced with 0.

Is this an expected behaviour? How can i avoid that and obtain the wanted result?

Thanks, Valentina

valeandri avatar Oct 11 '23 12:10 valeandri

What is the version of bcftools you are using? I just tested with the latest and it seems to be working as expected.

pd3 avatar Oct 13 '23 12:10 pd3

Hi @pd3

I tested both 1.15.1 and 1.10.2 bedtools versions, since I had these already installed. I'll test as soon as I can the latest version and let you know!

valeandri avatar Oct 13 '23 13:10 valeandri

i am also finding similar behavior for bcftools annotate with bcftools v1.9, when applying to format fields. is there any update here?

anoronh4 avatar Mar 10 '25 21:03 anoronh4

We are at version of bcftools 1.21, please update http://samtools.github.io/bcftools/howtos/install.html

pd3 avatar Mar 17 '25 14:03 pd3