Question: How To Plot A Dot Matrix When I Have A Matrix Of 0'S And 1'S
gravatar for Anish
8.9 years ago by
Anish20 wrote:

Hi All, I m quiet new to R Programming. My question may not be very wise, but would like to have some help as I explore more on R. Thanks in advance!

I have a matrix which was constructed based on comparing two sequences (say A and B) A="ATGCTAC" and B="ATCAGAT" and the matrix will be like M(1,1)=1,M(1,2)=1,M(1,3)=0. i.e., similar base positions with 1 and non-similar ones with 0. How can I construct a Dot Matrix plot?

Also if there is any code for Dot Matrix Alignment that uses window and stringency.


matrix plot • 3.5k views
ADD COMMENTlink written 8.9 years ago by Anish20
gravatar for Sean Davis
8.9 years ago by
Sean Davis26k
National Institutes of Health, Bethesda, MD
Sean Davis26k wrote:

You might have a look at the seqinr package.

This will give you a dot plot, though it uses boxes instead of dots.


And with your example:

ADD COMMENTlink written 8.9 years ago by Sean Davis26k
gravatar for brentp
8.9 years ago by
Salt Lake City, UT
brentp23k wrote:

Here's an ascii answer in python for kicks:

import sys

def draw(A, B):
    return " %s\n" % A + "\n".join(b + "".join("\x1B[42m \x1b[0m" \
           if a == b else "\x1B[41m \x1B[0m" for a in A) for b in B)

print draw(sys.argv[1], sys.argv[2])

If you call it like:


It gives ascii output like:

alt text

ADD COMMENTlink written 8.9 years ago by brentp23k

Thank you very much for your solutions. Both did serve the purpose

ADD REPLYlink written 8.8 years ago by Anish20
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1562 users visited in the last hour