DNA Visualization

Screen capture from R.M's code.
Screen capture from R.M’s code.

Another interesting project that came out of the Creativity Interim was a VPython program that uses the DNA Writer translation table to convert text into a DNA sequence that is represented as a series of colored spheres in a helix.

The code, by R.M. with some help from myself, is below. It’s pretty rough but works.

dna_translator.py

from visual import *
import string

xaxis = curve(pos=[(0,0),(10,0)])

inp = raw_input("enter text: ")
inp = inp.upper()


t_table={}



t_table['0']="ATA"
t_table['1']="TCT"
t_table['2']="GCG"
t_table['3']="GTG"
t_table['4']="AGA"
t_table['5']="CGC"
t_table['6']="ATT"
t_table['7']="ACC"
t_table['8']="AGG"
t_table['9']="CAA"
t_table['start']="TTG"
t_table['stop']="TAA"
t_table['A']="ACT"
t_table['B']="CAT"
t_table['C']="TCA"
t_table['D']="TAC"
t_table['E']="CTA"
t_table['F']="GCT"
t_table['G']="GTC"
t_table['H']="CGT"
t_table['I']="CTG"
t_table['J']="TGC"
t_table['K']="TCG"
t_table['L']="ATC"
t_table['M']="ACA"
t_table['N']="CTC"
t_table['O']="TGT"
t_table['P']="GAG"
t_table['Q']="TAT"
t_table['R']="CAC"
t_table['S']="TGA"
t_table['T']="TAG"
t_table['U']="GAT"
t_table['V']="GTA"
t_table['W']="ATG"
t_table['X']="AGT"
t_table['Y']="GAC"
t_table['Z']="GCA"
t_table[' ']="AGC"
t_table['.']="ACG"

dna=""

for i in inp:
    
    dna=dna+t_table[i]
print dna

m=0
r=3.0
f=0.5
n=0.0
dn=1.5


start_pos = 1
for i in dna:
    rate(10)
    n+=dn
    m+=1
    x = n
    y=r*sin(f*n)
    z=r*cos(f*n)
    a=sphere(pos=(x,y,z))
    #print x, y, z
    if (i == "A"):
        a.color=color.blue
    elif (i== "G"):
        a.color=color.red
    elif (i== "C"):
        a.color=color.green

Leave a Reply