This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to get per sample read depth from VCF with no DP field

I have a VCF file that has no DP info only AD (allelic depth). Does anyone know of a way that I can get per sample mean read depth using only the AD filter? I want a custom script that sums the two AD values for each site. example for two individuals: GT:AD 0|1:6,5 0|0:12,0

vcf

I want a custom script that sums the two AD values for each site. example for two individual

why do you want this DP ? what's the next step ?

Without the DP, I can not upload this file to a specific software

AD = Allele Depth, is not enough to calculate depth

If you don't have DP, you need RD = Reference Depth

1 answer

Using vcffilterjdk: http://lindenb.github.io/jvarkit/VcfFilterJdk.html

awk '/^#CHROM/ {printf("##FORMAT=<ID=DP,Number=1,Type=Integer,Description=\"depth\">\n");} {print}' input.vcf |\
java -jar dist/vcffilterjdk.jar -e 'return new VariantContextBuilder(variant).genotypes(variant.getGenotypes().stream().map(G->new GenotypeBuilder(G).DP(G.hasAD()?Arrays.stream(G.getAD()).sum():0).make()).collect(Collectors.toList())).make();'

Log in to answer this question.