This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Select variants that exist in all samples from a merged VCF file using bcftools

Hi, Is there a way to select only variants that exist in all samples?

Assume that I merged to VCF files, and I want to select variants that exist in both using bcftools.

bcftools view -i 'GT[0]!="./." && GT[1]!="./."' my.input.vcf.gz

This will do the work, but this way is not efficient if we have more than two samples, I tried:
bcftools view -i 'GT[*]!="./."'

But, it did not work.

The same task could be achieved using:
SnpSift.jar filter -f my.input.vcf.gz "( GEN[?].GT[?] != './.' )"

Any suggestions?

Thanks!!

Update

Using this code "( GEN[?].GT[?] != './.' ) & ( GEN[?].GT[?] != '0/0' )" solved the difference between the answer method and the SnpSift method.

snvs bcftools

1 answer

bcftools view -i 'count(GT="RR")==0 && count(GT="mis")==0' 

?

That worked! But, there are seven variants more in your case (I need to debug that).

i just select the variant where the number of hom-ref genotypes is 0 and the number of no-call genotypes is 0

Thank you for the clarificarion!

Log in to answer this question.