How To Plot A Dot Matrix When I Have A Matrix Of 0'S And 1'S
2
2
Entering edit mode
12.6 years ago
Anish ▴ 20

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.

Anish

matrix plot • 4.7k views
ADD COMMENT
7
Entering edit mode
12.6 years ago

You might have a look at the seqinr package.

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

library(seqinr)
help(dotPlot)
example(dotPlot)

And with your example:

dotPlot(seq1=strsplit("ATGCTAC","")[[1]],seq2=strsplit("ATCAGAT","")[[1]])
ADD COMMENT
5
Entering edit mode
12.6 years ago
brentp 24k

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:

python ansidot.py ATGCTAC ATCAGAT

It gives ascii output like:

alt text

ADD COMMENT
0
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 1911 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6