Moving AF tag to new column in a VCF file
1
0
Entering edit mode
5 months ago
Christian ▴ 30

Hi,

I have called some somatic variants in tumor-only mode with Mutect2. The first line of the output VCF file looks like this:

#CHROM POS   ID   REF   ALT   QUAL  FILTER INFO  FORMAT 156390
chr1  17961  .    TG   T    .    PASS  .    GT:AD:AF:DP:F1R2:F2R1:SB    0/1:178,59:0.251:237:96,32:72,24:37,141,10,49

Where "156390" is the sample ID. For a downstream tool, I would need the variant allelic fraction (AF) to be either in column 8 (INFO) or column 11, formatted as AF=x.

I have tried to solve this with awk:

awk -F '\t' 'BEGIN{OFS="\t"} {split($10, arr, ":"); $11="AF="arr[3]; print}' test_156390.vcf > test.vcf

But this is clearly a suboptimal solution - the new column 11 looks right, but AF= is now also the column name, and is also appended to every line in the header.

Is there any better way of doing this?

Thank you

Christian

mutect2 vcf • 399 views
ADD COMMENT
3
Entering edit mode
5 months ago

extract the vcf as a tab delimited file, something like (not tested)

bcftools query -f '%CHROM\t%POS\t%REF\t%ALT[\t%FORMAT/AF]\n' in.vcf > out.tsv
bgzip out.tsv
tabix <something> out.tsv.gz

then use bcftools annotate -a out.tsv.gz <something...> in.vcf to insert back a new INFO field in the vcf

ADD COMMENT
0
Entering edit mode

Thank you for pointing me in the right direction! This is how I solved it and applied it to every VCF in dir. I could not quite get bcftools annotate to work, likely due to a local server issue, but vcf-annotate works fine as well.

for i in *.vcf; do echo "annotating $i"; 
bcftools query -f '%CHROM\t%POS\t%REF\t%ALT\t[%AF]\n' $i > tmp.tsv
bgzip -f tmp.tsv
tabix -f -b 2 -s 1 -e 2 tmp.tsv.gz 
cat $i | vcf-annotate -a tmp.tsv.gz -c CHROM,POS,REF,ALT,INFO/AF -d key=INFO,ID=AF,Number=1,Type=Float,Description='Variant allelic fraction' > "${i//.vcf}"_vaf.vcf
done
ADD REPLY

Login before adding your answer.

Traffic: 1773 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