Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-08-24T22:59:28.197Z
Answers.Text: 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.
Answers.UserDisplayName: Death Metal
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-08-24T23:29:30.590Z
Answers.Text: 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
Answers.UserDisplayName: jared_mamrot
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-20T00:22:17.707Z
Answers.LastActivityDate: 2021-04-20T00:22:17.707Z
Answers.UserDisplayName: jared_mamrot
Body: <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>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-04-17T13:16:41.523Z
Comments.Text: Do you mean SNPs in terms of shared variants or shared positions?
Comments.UserDisplayName: user438383
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-04-19T21:18:30.853Z
Comments.Text: google intersect or overlap between VCF files, -> bcftools isec
Comments.UserDisplayName: JRodrigoF
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-05-23T16:47:32.210Z
Comments.Text: I have tried isec, but the produced files do not contains the VCF file contains common file
Comments.UserDisplayName: Mohamed Samir
Tags: <vcf><snp><variants>
Title: Find common SNPs in multiple VCF files
ThreadText: # 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](http://www.htslib.org/doc/bgzip.html) and [tabix](http://www.htslib.org/doc/tabix.html), then use [bcftools isec](https://samtools.github.io/bcftools/bcftools.html#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 @username_5-username_5, 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  
  
  ---
  
  