<p>A potential solution is to compress and index the files using <a href="http://www.htslib.org/doc/bgzip.html" rel="nofollow noreferrer">bgzip</a> and <a href="http://www.htslib.org/doc/tabix.html" rel="nofollow noreferrer">tabix</a>, then use <a href="https://samtools.github.io/bcftools/bcftools.html#isec" rel="nofollow noreferrer">bcftools isec</a> to find SNPs common to all three files, e.g.</p>
<pre><code>for files in A1.vcf A2.vcf A3.vcf
  do
  bgzip &quot;<span class="math-container">$files"
  tabix "$</span>files&quot;
done

bcftools isec -n=3 -c all -o all_common_SNPs.vcf A1.vcf.gz A2.vcf.gz A3.vcf.gz
<span class="math-container">```</span>
</code></pre>

CC BY-SA 4.0
2023-08-24T22:59:28.197Z
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.
Death Metal
CC BY-SA 4.0
2023-08-24T23:29:30.590Z
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: https://samtools.github.io/bcftools/bcftools.html#common_options
jared_mamrot
CC BY-SA 4.0
2021-04-20T00:22:17.707Z
2021-04-20T00:22:17.707Z
jared_mamrot
<p>I have 3 VCF files.</p>
<pre><code>A1.vcf
A2.vcf
A3.vcf
</code></pre>
<p>I want to get the common SNPs that are present in all these three files. And output must be in vcf format.</p>
<p>output:</p>
<pre><code>common_A.vcf
</code></pre>

CC BY-SA 4.0
2021-04-17T13:16:41.523Z
Do you mean SNPs in terms of shared variants or shared positions?
user438383
CC BY-SA 4.0
2021-04-19T21:18:30.853Z
google intersect or overlap between VCF files, -> bcftools isec
JRodrigoF
CC BY-SA 4.0
2023-05-23T16:47:32.210Z
I have tried isec, but the produced files do not contains the VCF file contains common file
Mohamed Samir
<vcf><snp><variants>
Find common SNPs in multiple VCF files
# Find common SNPs in multiple VCF files

(Asked by: username_0 on 2021-04-17)

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

**Tags:** vcf, snp, variants
> **Comments:**
> **username_1**: Do you mean SNPs in terms of shared variants or shared positions?  
> **username_2**: google intersect or overlap between VCF files, -> bcftools isec  
> **username_3**: I have tried isec, but the produced files do not contains the VCF file contains common file  

---

## 1 answers

### Answer by username_4 on 2021-04-20. Score: 3

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
```

> **Comments:**
> **username_5**: 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.  
> **username_4**: 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: https://samtools.github.io/bcftools/bcftools.html#common_options  

---

