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!
2 answers
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
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.
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:
Log in to answer this question.
Dot plothas a special meaning in bioinformatics. Are you simply looking for a linear representation of DNA as dots?