Visualize DNA sequence as a dot plot?
2
0
Entering edit mode
3.0 years ago
jaydu • 0

Hi!

Is there a very, very simple tool to visualize DNA in a dot plot or something like that?

I am basically looking to get an image where each base is represented by a 'dot' with a specific color, so red for A's, green for C's and so on. A single pixel dot might be to small to see, so maybe something like 4x4 pixels or maybe even the ability to set the size?

Thanks so much for your help!

plot visualization DNA dot • 1.4k views
ADD COMMENT
1
Entering edit mode

Dot plot has a special meaning in bioinformatics. Are you simply looking for a linear representation of DNA as dots?

ADD REPLY
2
Entering edit mode
3.0 years ago

You could use Python PIL (Pillow) to make one:

#!/usr/bin/env python

'''
pearl_plot.py
'''

import sys
from PIL import Image
from PIL import ImageDraw

# classic coloring scheme for DNA consensus sequence or logo
# ref. http://weblogo.threeplusone.com/manual.html 
#      https://github.com/WebLogo/weblogo/blob/master/weblogo/colorscheme.py
classic = {
    'G' : "orange",
    'T' : "red",
    'U' : "red",
    'C' : "blue",
    'A' : "green",
}

diameter = 20

for line in sys.stdin:
    line = line.rstrip().upper()
    img = Image.new("RGB", (diameter * len(line), diameter), color = "white")
    draw = ImageDraw.Draw(img)
    (x0, y0, x1, y1) = (0, 0, diameter, diameter)
    outline = "white"
    width = 1
    for char in line:
        bb = [x0, y0, x1, y1]
        fill = classic[char]
        draw.ellipse(bb, fill, outline, width)
        x0 += diameter
        x1 += diameter
    img.save("output.png")
    sys.exit(0)

Example:

$ echo "gaacgtacaacctatcaaataagggtcctctt" | ./pearl_plot.py
$ open output.png

example output from pearl_plot.py

To install Pillow:

https://pillow.readthedocs.io/en/stable/installation.html

Dot plots have a different meaning to biologists. Consider a different name to avoid confusion.

ADD COMMENT
0
Entering edit mode
3.0 years ago

A text-based option might also be handy. Here's a Python script that uses the sty library:

#!/usr/bin/env python

'''
biostars9465050.py
'''

import sys
from sty import bg, rs

bg.orange = bg(202)

classic = {
    'G' : bg.orange,
    'T' : bg.red,
    'U' : bg.red,
    'C' : bg.blue,
    'A' : bg.green,
}

be = rs.bg

for line in sys.stdin:
    line = line.rstrip().upper()
    for char in line:
        if char in classic:
            sys.stdout.write(classic[char] + ' ' + be)
    sys.stdout.write('\n')

To install sty:

• https://sty.mewo.dev/intro/install.html

Example:

Screenshot of sty script test run

ADD COMMENT

Login before adding your answer.

Traffic: 2393 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