This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to extract entire info column from VCF file using bcftools

I want to extract the whole info column, and the documentation indicates that %INFO should extract the whole info column.

https://samtools.github.io/bcftools/bcftools.html#query

I've tried the following:

bcftools query -f '%CHROM\t%POS\t%REF\t%ALT\t%INFO[\t%SAMPLE=%AD]\n' file.vcf

But I get an error saying it cannot parse format string.

The reason I want the whole info column is that there are about 20 different fields there and I don't want to extract them one by one.

bcftools software error snp

1 answer

Hello,

unfortunately this is not possible. See here: https://github.com/samtools/bcftools/issues/637

If you have a good reason why you need it and cut isn't enough, please leave a comment in this issue. Maybe it will be implemented.

fin swimmer

Indeed, and, with cut or awk, you can still merge these via paste to output of bcftools query, which is still very useful to use to extract tag information that is embedded in INFO or FORMAT:

paste \
  <(bcftools view test.bcf | \
    awk '!/^#/ {print $1":"$2":"$4":"$5}') \
  <(bcftools query --samples 2610,2661,6313,6318 -f '%CHROM\t%POS\t%REF\t%ALT\t%DP\t[%AD\t]\n' test.bcf) \
  | head -10
1:65797:T:C 1   65797   T   C   5012    .   .   .   .   
1:65841:T:G 1   65841   T   G   3234    .   .   .   .   
1:65851:C:T 1   65851   C   T   3271    .   .   .   .   
1:65872:T:G 1   65872   T   G   32370   236,39  .   .   205,47  
1:65918:C:T 1   65918   C   T   8629    .   .   .   232,0   
1:65974:A:G 1   65974   A   G   7623    .   .   .   .   
1:65999:G:C 1   65999   G   C   1767    .   .   .   .   
1:66162:A:T 1   66162   A   T   805 1,1 3,1 .   1,2 
1:69270:A:G 1   69270   A   G   1064    .   .   .   .   
1:69428:T:G 1   69428   T   G   870 .   .   .   .

Log in to answer this question.