Plot a circos plot to show the consistency between 2 samples

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 • 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. Apr 1 '19 at 13:12
• 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 Apr 1 '19 at 13:16
• Then you could use a confusion matrix, e.g. i66.tinypic.com/eanz9c.jpg Apr 1 '19 at 13:22
• I've posted my suggestion as an answer to not clutter the comments here. Apr 1 '19 at 13:44
• I agree that maybe a confusion matrix would be better, however there is a nice circos package in R github.com/jokergoo/circlize. You can use the spread function in dplyr to change the dataframe into a square matrix.
– TW93
Apr 1 '19 at 14:26

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][v.gt_types] += 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")