This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Fill a VCF record field that is partially annotated

I have a VCF like:

chr1    65310489    .   T   C   3483.8  PASS AF=0.476857;AO=441;DP=931;FAO=443;FDP=929;FDVR=5 [...] AF_gnomAD=0.353 [...]

chr1    65310518    .  A    T 96.8  PASS AF=0.00107066;AO=1;DP=934;FAO=1;FDP=934;FDVR=10 [...]

...

Where I added an extra field with the AF using the gnomAD database and vcfanno (https://github.com/brentp/vcfanno). This package adds the AF of the coincident coordinates to the vcf but it does not include any field into the ones that do not appear in gnomAD (I know some of this variant will be false positives in the postprocessing).

I would like to add a field in the records that are not annotated something like "AF_gnomAD=0" (or a very low number).

Any suggestions? Thanks!

vcf snp vcfanno gnomad

1 answer

assuming there is only one ALT allele:

awk -F '\t' '/^#/ {print; next} ($8 ~ /AF_gnomAD=/) {print;next;} {OFS="\t"; $8=sprintf("%s;AF_gnomAD=0",$8);print;}' input.vcf

It works great! Thanks! Also, if there is more than one ALT allele and they are separated with commas (,) there is no problem with this command :)

Also, if there is more than one ALT allele and they are separated with commas (,) there is no problem with this command

yes but an AF tag should have the same number of values than the number of ALT alleles (one frequency for each allele)

Log in to answer this question.