samtools / bcftools

This is the official development repository for BCFtools. See installation instructions and other documentation here http://samtools.github.io/bcftools/howtos/install.html
http://samtools.github.io/bcftools/
Other
653 stars 240 forks source link

Bcftools annotate overwrite existing tag #2016

Open valeandri opened 11 months ago

valeandri commented 11 months ago

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

pd3 commented 11 months ago

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

valeandri commented 11 months ago

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!