add VAF or FREQ in vcf file from read depth
1
0
Entering edit mode
4.2 years ago

Hi,

I have a vcf file with these values GT:VR:RR:DP:GQ in the format field. I would like to add the Variant Allele frequency tag (Frequency of alternate allele). I know that I can calculate it manually from the read depth information FREQ=(DP-RR)100/DP where DP: read depth and RR: reference read depth. Do you know any way to do it with commands (bcftools,vcftools or awk)?

Thanks!

next-gen • 1.6k views
ADD COMMENT
0
Entering edit mode
4.2 years ago

(not tested) using VcfFilterJdk http://lindenb.github.io/jvarkit/VcfFilterJdk.html

$ bcftools view in.vcf.gz |\
awk '/^#CHROM/ {printf("##FORMAT=<ID=FREQ,Number=1,Type=Float,Description=\"\">\n");} {print;}' |
java -jar dist/vcffilterjdk.jar -e 'final List<Genotype> gts = new ArrayList<>();for(final Genotype gt:variant.getGenotypes()) {final GenotypeBuilder gb=new GenotypeBuilder(gt);if(gt.hasDP() && gt.hasAnyAttribute("RR")){double rr =  gt.getAttributeAsDouble("RR",0.0);gb.attribute("FREQ",((gt.getDP()-rr)*100.0)/gt.getDP());}gts.add(gb.make());}return new VariantContextBuilder(variant).genotypes(gts).make();'
ADD COMMENT

Login before adding your answer.

Traffic: 4034 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6