This is a test version of Biostars. For the public version, visit https://www.biostars.org.
error on extracting a snp from vcf file using bcftools

Hello,

I am trying to extract a SNP based on POS column from a multisample vcf file.
I need the entire line with all the calls for all samples for the respective SNP.
I used:

bcftools view --include POS==41766 input.vcf -o SNP_41766

But the output file shows vcf header only.
Thank you for any help!

snp

Hi, it should work as you are running it. Are you sure that there is a record at this position? What if you simply grep the line:

bcftools view input.vcf | grep -P "\t41766\t"

Note that you can also extract the header with grep by using:

bcftools view input.vcf | grep -P "\t41766\t|^#"


Note: if your VCF is indeed uncompressed, then this will also work:

grep -P "\t41766\t" input.vcf
grep -P "\t41766\t|^#" input.vcf

That will select only the variant in chr1, but I think the question refers to all events.

Hello everyone! Thank you for your suggestions! I tried most of the suggestions but it is weird that I am still getting the header only (not the desired SNP row).

Any error? maybe try to use other position if you did not already, make sure you copy it from your vcf file.

1 answer

To use bcftools, I would write it in this the way:
bcftools view --include 'POS=41766' input.vcf -o SNP_41766

This also will work, but I prefer the previous one:
bcftools view --include POS=41766 input.vcf -o SNP_41766

Log in to answer this question.