Class TwoWayLookUp

java.lang.Object
    |
    +----TwoWayLookUp

public class TwoWayLookUp
extends java.lang.Object
A look-up utility for converting to and from DNA sequences and amino acids. Hard-coded so there is no overhead (or benefit) due to the Java Collections interface/libraries.

I wrote this for fun and to demonstrate for computer science folks how simple are the underpinnings of the genetic code. Compiles to c. 2,800 bytes. Uses an int array to link the two String arrays. Also for fun, I included the ability to list all the amino acids that start with just a single DNA base pair.

No threading issues as no variables are changed (outside the constructor), but you might want to rethink the Singleton design, especially if you want to improve performance on multiple processor platforms. Thinking of potential improvements to run-time performance, one could use knowledge of the frequency of each amino acid to re-order the list of amino acids and thereby shorten the look-up times. Same for the DNA codons. (I did not take time to look at either of these.) And the issue of whether the code produced by the Java JIT compiler is as good as what one could get with C or assembler code for the same thing seems interesting.

Other questions in this area are suggested by code like this. Like, how many different DNA sequences there are which would code for a known protein of say, 200 amino acids. And, if someone patents a DNA sequence, well, let's just use code like this to produce millions of unpatented sequences that produce the same protein. ;)

A good primer on DNA and protein synthesis is here. An interesting table of Amino Acids is here. Freeware: not warranted in any way as to fitness for a particular purpose, implied or not. Use at your own risk.

Version:
1.0 2005/03/23
Author:
Tony Dahlman

Variable Index

 o aminoAcids
All the amino acids as strings
 o bases
All the DNA bases as single characters
 o code
The DNA translation code, associating triplets with amino acids
 o decode
An array for finding DNA triplets from an amino acid.
 o instance
Use getInstance() to load (lazy singleton pattern)
 o triplets
DNA triplets or codons.
 o vars
The number of triplets for each amino acid (or "stop")

Constructor Index

 o TwoWayLookUp()
Private constructor for the singleton.

Method Index

 o getAcidsFromDNA(String)
Given 1, 2, or 3 ordered DNA bases, list all amino acids that are encoded.
 o getAminoAcidFromTriplet(String)
Used in converting from DNA to amino acid.
 o getDNAFromAminoAcid(String)
Returns a list of DNA triplets given an amino acid.
 o getInstance()
Initialize this class as a singleton
 o getPossibles(int)
Used in converting from Amino Acid to DNA.

Field Detail

 o instance
private static TwoWayLookUp instance
          Use getInstance() to load (lazy singleton pattern)
 o aminoAcids
protected static final java.lang.String[] aminoAcids
          All the amino acids as strings
 o bases
protected static final char[] bases
          All the DNA bases as single characters
 o triplets
protected static java.lang.String[] triplets
          DNA triplets or codons. Initialized in the constructor, but you could hard code this if you're really serious.
 o code
protected static final int[] code
          The DNA translation code, associating triplets with amino acids
 o vars
protected static final int[] vars
          The number of triplets for each amino acid (or "stop")
 o decode
protected static int[][] decode
          An array for finding DNA triplets from an amino acid. This one is also initialized by the constructor but could be hard coded (if you're really serious).

Constructor Detail

 o TwoWayLookUp
private TwoWayLookUp()
          Private constructor for the singleton. Just initializes the triplets array, and sets up the array of arrays for back conversion from amino acid to DNA.

Method Detail

 o getInstance
public static TwoWayLookUp getInstance()
          Initialize this class as a singleton
 o getAcidsFromDNA
public java.lang.String[] getAcidsFromDNA(java.lang.String input)
          Given 1, 2, or 3 ordered DNA bases, list all amino acids that are encoded.
 o getPossibles
protected int[] getPossibles(int i)
          Used in converting from Amino Acid to DNA.
 o getDNAFromAminoAcid
public java.lang.String[] getDNAFromAminoAcid(java.lang.String s)
          Returns a list of DNA triplets given an amino acid. Use the abbreviations, e.g., Phe, Ala, STOP.
 o getAminoAcidFromTriplet
protected int getAminoAcidFromTriplet(java.lang.String s)
          Used in converting from DNA to amino acid.