1
$\begingroup$

I have 3 VCF files.

A1.vcf
A2.vcf
A3.vcf

I want to get the common SNPs that are present in all these three files. And output must be in vcf format.

output:

common_A.vcf
$\endgroup$
3
  • 1
    $\begingroup$ Do you mean SNPs in terms of shared variants or shared positions? $\endgroup$
    – user438383
    Apr 17, 2021 at 13:16
  • $\begingroup$ google intersect or overlap between VCF files, -> bcftools isec $\endgroup$
    – JRodrigoF
    Apr 19, 2021 at 21:18
  • $\begingroup$ I have tried isec, but the produced files do not contains the VCF file contains common file $\endgroup$ May 23 at 16:47

1 Answer 1

3
$\begingroup$

A potential solution is to compress and index the files using bgzip and tabix, then use bcftools isec to find SNPs common to all three files, e.g.

for files in A1.vcf A2.vcf A3.vcf
  do
  bgzip "$files"
  tabix "$files"
done

bcftools isec -n=3 -c all -o all_common_SNPs.vcf A1.vcf.gz A2.vcf.gz A3.vcf.gz
```
$\endgroup$
2
  • $\begingroup$ Hi @Jared_mamrot - can you please explain -c all I've seen -c none -c all/both I'm unable to understand/follow this flag. $\endgroup$ Aug 24 at 22:59
  • 1
    $\begingroup$ As I understand it @Death-Metal, if you have two vcfs, one with the variant T->CCA at chr1 pos10001 and the other with the variant T->A at chr1 pos10001 , the -c all flag will treat these as a 'common to the two files' (i.e. there is a variant at chr1:10001 and it will be 'kept' when you isec). If you specify -c none, the REF/ALTs need to match exactly (i.e. both vcfs need to be e.g. T->A to be kept). With -c both, the variant must be the same type e.g. both SNPs or both INDELs, regardless of the ALTs. More details here: samtools.github.io/bcftools/bcftools.html#common_options $\endgroup$ Aug 24 at 23:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.