Answers.Body: <p>A circos plot is most likely not the most appropriate solution here. What I would suggest is a confusion matrix, of which you can find an example here:</p>
  
  <p><a href="https://i.sstatic.net/T4yqN.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/T4yqN.jpg" alt="enter image description here"></a></p>
  
  <p>For every variant in your vcf you'll add a number in this matrix. One sample is the columns, the other is the lines. If your variant is homozygous in both, then you add in that square +1 (the cell with 5845 in the example).</p>
  
  <p>A perfect concordant sample pair will have only variants on the diagonal.</p>
  
  <p>Here is some python code to get such a matrix. It uses cyvcf2 and pandas, and expects as input a vcf file with both samples.</p>
  
  <pre><code>from argparse import ArgumentParser
  from cyvcf2 import VCF
  import pandas as pd
  
  
  def main():
      args = get_args()
      confusion_matrix(args.vcf)
  
  
  def confusion_matrix(vcff):
      """
      First level of the dict is the "first" call, second level is the "second" sample
      0: hom_ref
      1: heterozygous
      2: unknown/nocall
      3: hom_alt
      """
      zygosities = {0: {0: 0, 1: 0, 2: 0, 3: 0},
                    1: {0: 0, 1: 0, 2: 0, 3: 0},
                    2: {0: 0, 1: 0, 2: 0, 3: 0},
                    3: {0: 0, 1: 0, 2: 0, 3: 0},
                    }
      for v in VCF(vcff):
          zygosities[v.gt_types[0]][v.gt_types[1]] += 1
      zygs = [2, 0, 1, 3]
      df = pd.DataFrame(index=zygs, columns=zygs)
      for tr in zygs:
          for te in zygs:
              df.loc[tr, te] = zygosities[tr][te]
      df.columns = ['nocall', 'hom_ref', 'het', 'hom_alt']
      df.index = ['nocall', 'hom_ref', 'het', 'hom_alt']
      print(df)
  
  
  def get_args():
      parser = ArgumentParser(description="Create confusion matrix of SNV calls")
      parser.add_argument("vcf", help="vcf containing two samples")
      return parser.parse_args()
  
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-04-01T13:46:31.847Z
Answers.Text: Thank you, for example if I have filtered t_005.vcf anf o_005.vcf files in a directory, how this code locate them?
Answers.UserDisplayName: Zizogolu
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-04-01T13:48:18.907Z
Answers.Text: It needs a single vcf with both samples. For that you'll need bcftools merge to combine your vcf files.
Answers.UserDisplayName: Wouter De Coster
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-04-01T13:43:42.953Z
Answers.LastActivityDate: 2019-04-01T13:43:42.953Z
Answers.UserDisplayName: Wouter De Coster
Body: <p>I have called SNP and INDEL in two matched samples by <em>strelka</em> and extract this information from .vcf file and I have these</p>
  
  <pre><code>CHROMOSOME  POS REF ALT SAMPLE
  1   928006  G   A   t_005
  1   1649842 G   T   t_005
  1   2020408 G   A   t_005
  1   2031677 T   A   t_005
  </code></pre>
  
  <p>and</p>
  
  <pre><code>CHROMODOME  POSITION    REF ALT SAMPLE
  1   14115   A   T   o_005
  1   541052  T   C   o_005
  1   1088123 T   G   o_005
  1   1232501 A   G   o_005
  </code></pre>
  
  <p>I need to show if and how extend the mutations between these two samples are consistent by a circos plot but really I don't know how people do that</p>
  
  <p>Something like this </p>
  
  <p><a href="https://i.sstatic.net/OuDvH.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/OuDvH.jpg" alt="enter image description here"></a></p>
  
  <p>or </p>
  
  <p><a href="https://i.sstatic.net/3DfJb.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/3DfJb.png" alt="enter image description here"></a></p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-04-01T13:12:52.227Z
Comments.Text: FWIW, I've never found a use case where a Circos plot was the best visualisation tool. They look pretty, but they don't really convey much information.
Comments.UserDisplayName: Joe Healey
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-04-01T13:16:06.187Z
Comments.Text: Thank you, I tried a waterfall to show the landscape of mutations in two samples but I failed again. I need a way to show which extend the mutations between these two samples are consistent
Comments.UserDisplayName: Zizogolu
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-04-01T13:22:50.070Z
Comments.Text: Then you could use a confusion matrix, e.g. http://i66.tinypic.com/eanz9c.jpg
Comments.UserDisplayName: Wouter De Coster
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-04-01T13:32:18.260Z
Comments.Text: What I should put in confusion matrix? For example total number of mutation? But maybe the total number of mutations is the same but the mutations are different  :(
Comments.UserDisplayName: Zizogolu
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-04-01T13:37:36.820Z
Comments.Text: nonono. Every variants gets one position in the matrix: in my example, a variant which is heterozygous in Sniffles and homozygous in the truth set ends up in the square with 516. A perfect match has only variants on the diagonal.
Comments.UserDisplayName: Wouter De Coster
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-04-01T13:43:41.573Z
Comments.Text: Sorry do you know any blog of tutorial to showing use case?
Comments.UserDisplayName: Zizogolu
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-04-01T13:44:19.563Z
Comments.Text: I've posted my suggestion as an answer to not clutter the comments here.
Comments.UserDisplayName: Wouter De Coster
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-04-01T14:26:08.243Z
Comments.Text: I agree that maybe a confusion matrix would be better, however there is a nice circos package in R https://github.com/jokergoo/circlize. You can use the spread function in dplyr to change the dataframe into a square matrix.
Comments.UserDisplayName: TW93
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-04-01T15:05:37.420Z
Comments.Text: Sorry I could not find any vignette for that to adapt my data
Comments.UserDisplayName: Zizogolu
Tags: <r><mutations><wgs><software-usage>
Title: Plot a circos plot to show the consistency between 2 samples
ThreadText: # Plot a circos plot to show the consistency between 2 samples
  
  (Asked by: username_0 on 2019-04-01)
  
  I have called SNP and INDEL in two matched samples by *strelka* and extract this information from .vcf file and I have these
  
  ```
  CHROMOSOME  POS REF ALT SAMPLE
  1   928006  G   A   t_005
  1   1649842 G   T   t_005
  1   2020408 G   A   t_005
  1   2031677 T   A   t_005
  
  ```
  
  and
  
  ```
  CHROMODOME  POSITION    REF ALT SAMPLE
  1   14115   A   T   o_005
  1   541052  T   C   o_005
  1   1088123 T   G   o_005
  1   1232501 A   G   o_005
  
  ```
  
  I need to show if and how extend the mutations between these two samples are consistent by a circos plot but really I don't know how people do that
  
  Something like this
  
  [![enter image description here](https://i.sstatic.net/OuDvH.jpg)](https://i.sstatic.net/OuDvH.jpg)
  
  or
  
  [![enter image description here](https://i.sstatic.net/3DfJb.png)](https://i.sstatic.net/3DfJb.png)
  
  **Tags:** r, mutations, wgs, software-usage
  
  > **Comments:**
  > **username_1**: FWIW, I've never found a use case where a Circos plot was the best visualisation tool. They look pretty, but they don't really convey much information.  
  > **username_0**: Thank you, I tried a waterfall to show the landscape of mutations in two samples but I failed again. I need a way to show which extend the mutations between these two samples are consistent  
  > **username_2**: Then you could use a confusion matrix, e.g. http://i66.tinypic.com/eanz9c.jpg  
  > **username_0**: What I should put in confusion matrix? For example total number of mutation? But maybe the total number of mutations is the same but the mutations are different  :(  
  > **username_2**: nonono. Every variants gets one position in the matrix: in my example, a variant which is heterozygous in Sniffles and homozygous in the truth set ends up in the square with 516. A perfect match has only variants on the diagonal.  
  > **username_0**: Sorry do you know any blog of tutorial to showing use case?  
  > **username_2**: I've posted my suggestion as an answer to not clutter the comments here.  
  > **username_3**: I agree that maybe a confusion matrix would be better, however there is a nice circos package in R https://github.com/jokergoo/circlize. You can use the spread function in dplyr to change the dataframe into a square matrix.  
  > **username_0**: Sorry I could not find any vignette for that to adapt my data  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2019-04-01. Score: 1
  
  A circos plot is most likely not the most appropriate solution here. What I would suggest is a confusion matrix, of which you can find an example here:
  
  [![enter image description here](https://i.sstatic.net/T4yqN.jpg)](https://i.sstatic.net/T4yqN.jpg)
  
  For every variant in your vcf you'll add a number in this matrix. One sample is the columns, the other is the lines. If your variant is homozygous in both, then you add in that square +1 (the cell with 5845 in the example).
  
  A perfect concordant sample pair will have only variants on the diagonal.
  
  Here is some python code to get such a matrix. It uses cyvcf2 and pandas, and expects as input a vcf file with both samples.
  
  ```
  from argparse import ArgumentParser
  from cyvcf2 import VCF
  import pandas as pd
  
  def main():
      args = get_args()
      confusion_matrix(args.vcf)
  
  def confusion_matrix(vcff):
      """
      First level of the dict is the "first" call, second level is the "second" sample
      0: hom_ref
      1: heterozygous
      2: unknown/nocall
      3: hom_alt
      """
      zygosities = {0: {0: 0, 1: 0, 2: 0, 3: 0},
                    1: {0: 0, 1: 0, 2: 0, 3: 0},
                    2: {0: 0, 1: 0, 2: 0, 3: 0},
                    3: {0: 0, 1: 0, 2: 0, 3: 0},
                    }
      for v in VCF(vcff):
          zygosities[v.gt_types[0]][v.gt_types[1]] += 1
      zygs = [2, 0, 1, 3]
      df = pd.DataFrame(index=zygs, columns=zygs)
      for tr in zygs:
          for te in zygs:
              df.loc[tr, te] = zygosities[tr][te]
      df.columns = ['nocall', 'hom_ref', 'het', 'hom_alt']
      df.index = ['nocall', 'hom_ref', 'het', 'hom_alt']
      print(df)
  
  def get_args():
      parser = ArgumentParser(description="Create confusion matrix of SNV calls")
      parser.add_argument("vcf", help="vcf containing two samples")
      return parser.parse_args()
  
  if __name__ == '__main__':
      main()
  
  ```
  
  > **Comments:**
  > **username_0**: Thank you, for example if I have filtered t_005.vcf anf o_005.vcf files in a directory, how this code locate them?  
  > **username_2**: It needs a single vcf with both samples. For that you'll need bcftools merge to combine your vcf files.  
  
  ---
  
  