Question: Extract columns from VCF file using bcftools preserving all the header info
0
gravatar for nikitavlassenko
4 months ago by
nikitavlassenko50 wrote:

I am trying to extract only the columns I need from VCF preserving VCF structure, its header, its formatting. I am using bcftools. I tried doing:

bcftools annotate -c CHROM,POS,ID,REF,ALT,QUAL,FILTER,INFO/AF,INFO/AC,INFO/AN Holland.vcf -o Holland_selected_cols.vcf

But the output file just stays the same. Then I tried query:

bcftools query -f'[%CHROM\t%POS\t%ID\t%REF\t%ALT\t%QUAL\t%FILTER\t%INFO/AF;%INFO/AC;%INFO/AN\n]' -H Holland.vcf -o Holland_selected_cols.vcf

But it does not preserve VCF header. What would be the right bcftools command for that?

bcftools vcf • 422 views
ADD COMMENTlink modified 4 months ago by finswimmer13k • written 4 months ago by nikitavlassenko50
2
gravatar for finswimmer
4 months ago by
finswimmer13k
Germany
finswimmer13k wrote:

Use bcftools annotate -x to remove all fields, except those you want to keep:

bcftools annotate -x ^INFO/AF,^INFO/AC,^INFO/AN,^FORMAT input.vcf
ADD COMMENTlink written 4 months ago by finswimmer13k

It can also be added that if genotypes need to be removed, then a different command bcftools view -G input.vcf > output.vcf can be used. Genotypes are also sort of columns.

ADD REPLYlink written 8 weeks ago by nikitavlassenko50
Please log in to add an answer.

Help
Access

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