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

Hi! I just got started with bioinformatics, so I just barely got used to what a VCF file or bcftools is. But yeah I am trying to create a new VCF file that only consists of passed SNP/SNVs from a very large VCF file, using bcftools. Thanks!

vcf

2 answers

For such a simple task there's no need for bcftools. Pure bash solution

grep "#" whole_snv.vcf > filtered_snv.vcf && grep -v '#' whole_snv.vcf | awk -F'\t' '{if ($7=="PASS") print $0}' >> filtered_snv.vcf

With bcftools:

bcftools view -f 'PASS' whole_snv.vcf

Please check if already asked on this forum, as this is a very common question. It was already answered here

bcftools view --apply-filters 'PASS,.' --types 'snps' in.vcf

So I'm actually trying to create a passed SNV file into its complements and intersections, so I tried doing:

bcftools isec -f 'PASS,.' --types 'snps' [file1.vcf.gz] [file2.vcf.gz] -p dir

But obviously, this is different than view. Is there are a way I can still filter out the passed SNVs using isec? Thanks!

Log in to answer this question.