This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Extract a list of SNPs from a BCF file

Hi there, I have a very large BCF file from which I want to extract a list of SNPs (also very large). The SNPs of interest are in a tab delimited file with two columns chromosome and position. I have tried the bcftools by using view function and the options -T and -R like bellow but I haven't had success.

bcftools view -T mylist.txt file.bcf -Ou -o filteredfile.bcf

Thanks in advance

bcf snp

but I haven't had success

What does that mean? What is the exact problem you're facing? Can you also paste the first few lines of your mylist.txt file?

HI Ram,

can you please share with me what should be the format of this mylist.txt file?

is it ok to do something like this:

vcftools --bcf gokind.bcf --snps mySNPs.txt --recode --recode-INFO-all --out SNPs_only

where mySNPs.txt looks like this:

rs12121
rs242343
rs2348724

What do your questions have to do with my comment?

Is it ok to do something like this

Did you try it? Did it work? Did the results match your expectations?

Hi,

I tried it and this is what I got:

Outputting VCF file...
Error: Expected type 7 for string. Found type 9.
Error: Expected type 7 for string. Found type 0.
Error: Expected type 7 for string. Found type 0.
Error: Expected type 7 for string. Found type 0.
Error: Expected type 7 for string. Found type 0.
Error: Expected type 7 for string. Found type 0.
After filtering, kept 0 out of a possible 3 Sites
No data left for analysis!

I also tried this:

bcftools view -T mylist.txt gokind2.bcf -Ou -o filteredfile.bcf

where mylist.txt was a tab separated file:

20  33371323
12  73950313
1   216957281

but I got this error:

[E::bcf_sr_regions_init] Could not parse the file mylist.txt, using the columns 1,2[,-1]
Failed to read the targets: mylist.txt

Can you please advise how mylist.txt should be formatted?

Thanks

Does using -R mylist.txt (instead of -T mylist.txt) work? What is the output to cat -te mylist.txt?

I tried what you suggested:

$ bcftools view -R mylist.txt gokind2.bcf -Ou -o filteredfile.bcf
[E::bcf_sr_regions_init] Could not parse the file mylist.txt, using the columns 1,2[,-1]
Failed to read the regions: mylist.txt

and:

 cat -te mylist.txt

gives me:

20^I33371323$
12^I73950313$
1^I216957281$
5^I174820027$
...

Your mylist.txt looks fine. What is the bcftools version you're using? bcftools --version should give you the version info.

it's this one:

bcftools --version
bcftools 1.10.2-32-ge677391
Using htslib 1.10.2-46-g9a10355
Copyright (C) 2019 Genome Research Ltd.

That's a new version. I have no idea what's going on here. Is there any chance you could go back to bcftools 1.9 and try this? It should not make a difference but just in case.

I am doing this on some cluster so ...but anyway thank you so much for debugging tips!

0 answers

No answers yet.

Log in to answer this question.