Question: add VAF or FREQ in vcf file from read depth
gravatar for nikimourtzi23
8 months ago by
nikimourtzi230 wrote:


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)?


next-gen • 288 views
ADD COMMENTlink modified 8 months ago by Pierre Lindenbaum131k • written 8 months ago by nikimourtzi230
gravatar for Pierre Lindenbaum
8 months ago by
France/Nantes/Institut du Thorax - INSERM UMR1087
Pierre Lindenbaum131k wrote:

(not tested) using VcfFilterJdk

$ 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 COMMENTlink written 8 months ago by Pierre Lindenbaum131k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1204 users visited in the last hour