edu.uconn.mcb.lineageevolver
Class AATranslator

java.lang.Object
  extended byedu.uconn.mcb.lineageevolver.AATranslator

public class AATranslator
extends java.lang.Object

Serves as a translator between AminoAcid naming schemes.

Author:
Hasan Khalil, Lina Pezzella

Nested Class Summary
static class AATranslator.InvalidAminoAcid
          Base class for exceptions generated during amino acid encoding/decoding.
 
Field Summary
private static char[] _intToChar
          Provides mapping between char and int encodings for AminoAcids.
 
Constructor Summary
AATranslator()
           
 
Method Summary
static byte getByte(char aa)
          Returns the byte encoding for the AminoAcid encoded by the provided character.
static byte getByte(int aa)
          Returns the byte encoding for the AminoAcid encoded by the provided integer.
static char getChar(byte aa)
          Returns the character encoding for the AminoAcid encoded by the provided byte.
static char getChar(int aa)
          Returns the character encoding for the AminoAcid encoded by the provided integer.
static int getInt(byte aa)
          Returns the integer encoding for the AminoAcid encoded by the provided byte.
static int getInt(char aa)
          Returns the integer encoding for the AminoAcid encoded by the provided character.
static void sanityCheck(byte aa)
          Checks if a byte encodes for a given amino acid.
static void sanityCheck(char aa)
          Checks if a character encodes for a given amino acid.
static void sanityCheck(int aa)
          Checks if an integer encodes for a given amino acid.
private static byte toByte(char aa)
          Returns the byte representation of a given char, without error checking.
private static byte toByte(int aa)
          Converts an int AminoAcid encoding to its corresponding byte encoding, without error checking.
private static char toChar(byte aa)
          Returns the char representation of a given byte, without error checking.
private static char toChar(int aa)
          Converts an int AminoAcid encoding to its corresponding char encoding, without error checking.
private static int toInt(byte aa)
          Converts a byte AminoAcid encoding to its corresponding int encoding, without error checking.
private static int toInt(char aa)
          Converts a char AminoAcid encoding to its corresponding int encoding, without error checking.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_intToChar

private static final char[] _intToChar
Provides mapping between char and int encodings for AminoAcids.

Constructor Detail

AATranslator

public AATranslator()
Method Detail

toInt

private static int toInt(char aa)
Converts a char AminoAcid encoding to its corresponding int encoding, without error checking. Uses a simple switch statement.

Parameters:
aa - the char encoding for a given AminoAcid. Should be upper-case, as always.
Returns:
the int encoding corresponding to the AminoAcid encoded by the provided char, or -1 if there was a decoding error.

toInt

private static int toInt(byte aa)
Converts a byte AminoAcid encoding to its corresponding int encoding, without error checking. Delegates to toInt(char) via toChar(byte).

Parameters:
aa - the byte encoding for a given AminoAcid.
Returns:
the int encoding corresponding to the AminoAcid encoded by the provided byte, or -1 if there was a decoding error.
See Also:
toChar(byte), toInt(char)

toChar

private static char toChar(int aa)
                    throws java.lang.ArrayIndexOutOfBoundsException
Converts an int AminoAcid encoding to its corresponding char encoding, without error checking. Uses the _intToChar array.

Parameters:
aa - the int encoding for a given AminoAcid.
Returns:
the char encoding corresponding to the AminoAcid encoded by the provided byte.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the provided integer is < 0 or > 19.
See Also:
_intToChar

toChar

private static char toChar(byte aa)
Returns the char representation of a given byte, without error checking. Uses a simple cast.

Parameters:
aa - any byte.
Returns:
the char representation of the given byte.

toByte

private static byte toByte(int aa)
Converts an int AminoAcid encoding to its corresponding byte encoding, without error checking. Delegates to toByte(char) via toChar(int).

Parameters:
aa - the int encoding for a given AminoAcid.
Returns:
the byte encoding corresponding to the AminoAcid encoded by the provided int.
See Also:
toChar(int), toByte(char)

toByte

private static byte toByte(char aa)
Returns the byte representation of a given char, without error checking. Uses a simple cast.

Parameters:
aa - any char.
Returns:
the byte representation of the given char.

sanityCheck

public static void sanityCheck(int aa)
                        throws AATranslator.InvalidAminoAcid
Checks if an integer encodes for a given amino acid. Throws an InvalidAminoAcidInt exception if not.

Parameters:
aa - the integer to check.
Throws:
AATranslator.InvalidAminoAcid - If the integer does not correctly encode an AminoAcid.

sanityCheck

public static void sanityCheck(byte aa)
                        throws AATranslator.InvalidAminoAcid
Checks if a byte encodes for a given amino acid. Throws an InvalidAminoAcidByte exception if not. This method converts the byte to a character, and then delegates to the character sanity check.

Parameters:
aa - the byte to check.
Throws:
AATranslator.InvalidAminoAcid - If the byte does not correctly encode an AminoAcid.
See Also:
toChar(byte), sanityCheck(char)

sanityCheck

public static void sanityCheck(char aa)
                        throws AATranslator.InvalidAminoAcid
Checks if a character encodes for a given amino acid. Throws an InvalidAminoAcidChar exception if not. This method delegates to the toInt(char) method.

Parameters:
aa - the character to check.
Throws:
AATranslator.InvalidAminoAcid - If the character does not correctly encode an AminoAcid.
See Also:
toInt(char)

getChar

public static char getChar(int aa)
Returns the character encoding for the AminoAcid encoded by the provided integer.

Parameters:
aa - the integer encoding of an AminoAcid.
Returns:
the character encoding for the AminoAcid specified by the aa parameter.

getInt

public static int getInt(char aa)
Returns the integer encoding for the AminoAcid encoded by the provided character.

Parameters:
aa - the character encoding of an AminoAcid.
Returns:
the integer encoding for the AminoAcid specified by the aa parameter.

getByte

public static byte getByte(int aa)
Returns the byte encoding for the AminoAcid encoded by the provided integer.

Parameters:
aa - the integer encoding of an AminoAcid.
Returns:
the byte encoding for the AminoAcid specified by the aa parameter.

getInt

public static int getInt(byte aa)
Returns the integer encoding for the AminoAcid encoded by the provided byte.

Parameters:
aa - the byte encoding of an AminoAcid.
Returns:
the integer encoding for the AminoAcid specified by the aa parameter.

getChar

public static char getChar(byte aa)
Returns the character encoding for the AminoAcid encoded by the provided byte.

Parameters:
aa - the byte encoding of an AminoAcid.
Returns:
the character encoding for the AminoAcid specified by the aa parameter.

getByte

public static byte getByte(char aa)
Returns the byte encoding for the AminoAcid encoded by the provided character.

Parameters:
aa - the character encoding of an AminoAcid.
Returns:
the byte encoding for the AminoAcid specified by the aa parameter.