0
$\begingroup$

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

or

enter image description here

$\endgroup$
9
  • 2
    $\begingroup$ 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. $\endgroup$
    – Joe Healey
    Apr 1 '19 at 13:12
  • $\begingroup$ 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 $\endgroup$
    – Exhausted
    Apr 1 '19 at 13:16
  • 1
    $\begingroup$ Then you could use a confusion matrix, e.g. i66.tinypic.com/eanz9c.jpg $\endgroup$ Apr 1 '19 at 13:22
  • 1
    $\begingroup$ I've posted my suggestion as an answer to not clutter the comments here. $\endgroup$ Apr 1 '19 at 13:44
  • 1
    $\begingroup$ 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. $\endgroup$
    – TW93
    Apr 1 '19 at 14:26
1
$\begingroup$

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

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()
$\endgroup$
2
  • $\begingroup$ Thank you, for example if I have filtered t_005.vcf anf o_005.vcf files in a directory, how this code locate them? $\endgroup$
    – Exhausted
    Apr 1 '19 at 13:46
  • $\begingroup$ It needs a single vcf with both samples. For that you'll need bcftools merge to combine your vcf files. $\endgroup$ Apr 1 '19 at 13:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.