This is a test version of Biostars. For the public version, visit https://www.biostars.org.
filtering by POS in bcftools

Hi,

I have a vcf file which I would like to filter by a list of SNP positions, which are present in a positions.txt file.

 bcftools filter -i 'POS=@positions.txt' input.vcf.bgz > output.vcf

However, this says:

Error: could not parse the expression. Note that the "@file_name" syntax can be currently used with ID column only.

Is there another simple way filter by POS in bcftools?

Thanks.

software error bcftools

sorry im not sure the difference. I tried reading the manual, but I didn't follow..

I have a txt file of positions:

1324324
4325435
etc

and within the vcf file, SNPs with those positions. I would like to create a new vcf file, which is a subset of the first, only containing those SNPs and their corresponding information.

Thanks.

position alone is insufficient to locate a feature, you would need the chromosomal coordinate as well. You can use what Pierre Lindenbaum said or you may also use bedtools intersect to isolate regions, sometimes there can be differences on how tools operate when the variation is an interval. With bedtools the documentation is more explicit.

2 answers

Yeah, I figured.

Actually found the answer here, so you can close the thread

Best way to query VCF for specific variants

thanks.

Actually the best way is

bcftools view -R regions.tsv my.vcf

Where regions.tsv looks like

chr1    123
chr1    567

Log in to answer this question.