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
aminoAcids- All the amino acids as strings
bases- All the DNA bases as single characters
code- The DNA translation code, associating triplets with amino acids
decode- An array for finding DNA triplets from an amino acid.
instance- Use getInstance() to load (lazy singleton pattern)
triplets- DNA triplets or codons.
vars- The number of triplets for each amino acid (or "stop")
TwoWayLookUp()
- Private constructor for the singleton.
getAcidsFromDNA(String)
- Given 1, 2, or 3 ordered DNA bases, list all amino acids
that are encoded.
getAminoAcidFromTriplet(String)
- Used in converting from DNA to amino acid.
getDNAFromAminoAcid(String)
- Returns a list of DNA triplets given an amino
acid.
getInstance()
- Initialize this class as a singleton
getPossibles(int)
- Used in converting from Amino Acid to DNA.
instance
private static TwoWayLookUp instance
Use getInstance() to load (lazy singleton pattern)
aminoAcids
protected static final java.lang.String[] aminoAcids
All the amino acids as strings
bases
protected static final char[] bases
All the DNA bases as single characters
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.
code
protected static final int[] code
The DNA translation code, associating triplets with amino acids
vars
protected static final int[] vars
The number of triplets for each amino acid (or "stop")
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).
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.
getInstance
public static TwoWayLookUp getInstance()
Initialize this class as a singleton
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.
getPossibles
protected int[] getPossibles(int i)
Used in converting from Amino Acid to DNA.
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.
getAminoAcidFromTriplet
protected int getAminoAcidFromTriplet(java.lang.String s)
Used in converting from DNA to amino acid.