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

CC BY-SA 4.0
2019-04-01T13:46:31.847Z
Thank you, for example if I have filtered t_005.vcf anf o_005.vcf files in a directory, how this code locate them?
Zizogolu
CC BY-SA 4.0
2019-04-01T13:48:18.907Z
It needs a single vcf with both samples. For that you'll need bcftools merge to combine your vcf files.
Wouter De Coster
CC BY-SA 4.0
2019-04-01T13:43:42.953Z
2019-04-01T13:43:42.953Z
Wouter De Coster
<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>

CC BY-SA 4.0
2019-04-01T13:12:52.227Z
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.
Joe Healey
CC BY-SA 4.0
2019-04-01T13:16:06.187Z
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
Zizogolu
CC BY-SA 4.0
2019-04-01T13:22:50.070Z
Then you could use a confusion matrix, e.g. http://i66.tinypic.com/eanz9c.jpg
Wouter De Coster
CC BY-SA 4.0
2019-04-01T13:32:18.260Z
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  :(
Zizogolu
CC BY-SA 4.0
2019-04-01T13:37:36.820Z
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.
Wouter De Coster
CC BY-SA 4.0
2019-04-01T13:43:41.573Z
Sorry do you know any blog of tutorial to showing use case?
Zizogolu
CC BY-SA 4.0
2019-04-01T13:44:19.563Z
I've posted my suggestion as an answer to not clutter the comments here.
Wouter De Coster
CC BY-SA 4.0
2019-04-01T14:26:08.243Z
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.
TW93
CC BY-SA 4.0
2019-04-01T15:05:37.420Z
Sorry I could not find any vignette for that to adapt my data
Zizogolu
<r><mutations><wgs><software-usage>
Plot a circos plot to show the consistency between 2 samples
# 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 

or

**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:

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.  

---

