org.concord.biologica.engine
Class AlgorithmicNucleicAcid

java.lang.Object
  |
  +--org.xml.sax.HandlerBase
        |
        +--org.concord.biologica.engine.EngineObject
              |
              +--org.concord.biologica.engine.AlgorithmicNucleicAcid
All Implemented Interfaces:
org.xml.sax.DocumentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler, INucleicAcid, java.io.Serializable

public final class AlgorithmicNucleicAcid
extends EngineObject
implements INucleicAcid, java.io.Serializable

This class represents a nucleic acid whose bases are algorithmically and randomly generated. The acid is guaranteed to have a length which is a multiple of 3 bases. It is NOT guaranteed that the acid will not contain start and stop codons. Nor is it guaranteed that the acid will not contain a promoter region, although the odds of it having one are very low.

We do this by forcing the creator of this object to specify the length, in codons, of the nucleic acid. Then we generate a random seed and use that random seed to choose from the finite set of possible codons (excluding start and stop codons) for the nucleic acids.

An object of this class will generate the following property change events:

Version:
$Revision: 1.1.1.1 $ $Date: 2001/04/28 00:39:11 $
Author:
$Author: ed $
See Also:
EngineProp.DELETED, EngineProp.ID, EngineProp.IN_DNA_OR_RNA, EngineProp.LENGTH_IN_BASES, EngineProp.LOCKED_STATE, EngineProp.SEED, EngineProp.START_INDEX_IN_HOLDER, PropertyChangeListener, Serialized Form

Fields inherited from class org.concord.biologica.engine.EngineObject
AUTOMATIC_LOCKED, AUTOMATIC_LOCKED_STRING, changes, deleted, FALSE, id, lockedState, MANUAL_AND_AUTOMATIC_LOCKED, MANUAL_AND_AUTOMATIC_LOCKED_STRING, MANUAL_LOCKED, MANUAL_LOCKED_STRING, NULL_ID, TRUE, UNLOCKED, UNLOCKED_STRING, xmlElementContext
 
Constructor Summary
AlgorithmicNucleicAcid(INucleicAcidHolder aHolder, int startIndexInHolder, AlgorithmicNucleicAcid anAlgorithmicNucleicAcid)
          Create a new algorithmic nucleic acid given another algorithmic nucleic acid to copy.
AlgorithmicNucleicAcid(INucleicAcidHolder aHolder, int startIndexInHolder, int lengthInBases, int inDNAorRNA)
          Create a new algorithmic nucleic acid given a length in codons.
 
Method Summary
 void delete()
          Delete this object, notifying parent objects and deleting any child objects.
 void delete(boolean notifyChange)
          Delete this nucleic acid - redundant with EngineObject in most cases.
 byte getBase(int index)
          Returns the base value at the given index in this raw nucleic acid.
 INucleicAcidHolder getHolder()
          Returns the raw nucleic acid's holder.
 int getInDNAOrRNA()
          Returns whether this nucleic acid is in DNA or RNA.
 int getLengthInBases()
          Returns the length of the algorithmic nucleic acid in bases.
 int getLengthInCodons()
          Returns the length of the algoritmic nucleic acid in codons.
 long getSeed()
          Returns the seed value of this algorithmic nucleic acid.
 int getStartIndexInHolder()
          Returns the start index of this nucleic acid in its holder.
 World getWorld()
          Returns the world containing this nucleic acid.
 void setLengthInBases(int aLengthInBases)
          Set the length in bases of this nucleic acid.
 void setSeed(long aSeed)
          Set the seed of this nucleic acid.
 void setStartIndexInHolder(int anIndex)
          Set the start index of this nucleic acid in its holder.
 java.lang.String toString()
          Return a string representation of this object, usually the object's name.
 void writeToStream(java.io.PrintWriter stream)
          Writes this object to the given stream in XML format.
 
Methods inherited from class org.concord.biologica.engine.EngineObject
addPropertyChangeListener, getID, getLockedState, getLockedStateAsString, isAutomaticLocked, isDeleted, isLocked, isManualLocked, notifySelected, release, removePropertyChangeListener, setAutomaticLocked, setID, setLockedState, setLockedStateAsString, setManualLocked
 
Methods inherited from class org.xml.sax.HandlerBase
characters, endDocument, endElement, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, startDocument, startElement, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.concord.biologica.engine.INucleicAcid
setAutomaticLocked, setLockedState, setManualLocked
 

Constructor Detail

AlgorithmicNucleicAcid

public AlgorithmicNucleicAcid(INucleicAcidHolder aHolder,
                              int startIndexInHolder,
                              int lengthInBases,
                              int inDNAorRNA)
Create a new algorithmic nucleic acid given a length in codons.

A random seed is generated and saved with this nucleic acid for use in generating base values.

Parameters:
aHolder - INucleicAcidHolder - holder of this nucleic acid (e.g. allele), may not be null
startIndexInHolder - int - index of the raw nucleic acid in its holder
lengthInBases - int - length of nucleic acid in bases, must be a multiple of 3
inDNAorRNA - int - indicates if this nucleic acid is in RNA or DNA (Base.IN_DNA or Base.IN_RNA)
Throws:
java.lang.IllegalArgumentException - - input argument(s) illegal

AlgorithmicNucleicAcid

public AlgorithmicNucleicAcid(INucleicAcidHolder aHolder,
                              int startIndexInHolder,
                              AlgorithmicNucleicAcid anAlgorithmicNucleicAcid)
Create a new algorithmic nucleic acid given another algorithmic nucleic acid to copy.

Parameters:
aHolder - INucleicAcidHolder - holder of this nucleic acid (e.g. allele), may not be null
startIndexInHolder - int - index of the raw nucleic acid in its holder
anAlgorithmicNucleicAcid - AlgorithmicNucleicAcid - nucleic acid to copy, may not be null
Throws:
java.lang.IllegalArgumentException - - input argument(s) illegal
Method Detail

delete

public void delete()
Delete this object, notifying parent objects and deleting any child objects.

When this method is called, a property change event is generated for the property named EngineProp.DELETED.

Specified by:
delete in interface INucleicAcid
Overrides:
delete in class EngineObject

delete

public void delete(boolean notifyChange)
Description copied from interface: INucleicAcid
Delete this nucleic acid - redundant with EngineObject in most cases.

Specified by:
delete in interface INucleicAcid

toString

public java.lang.String toString()
Return a string representation of this object, usually the object's name.

Overrides:
toString in class EngineObject
Returns:
String - string representation of object

getHolder

public INucleicAcidHolder getHolder()
Returns the raw nucleic acid's holder.

Specified by:
getHolder in interface INucleicAcid
Returns:
INucleicAcidHolder - raw nucleic acid's holder, never null

getWorld

public World getWorld()
Returns the world containing this nucleic acid.

Overrides:
getWorld in class EngineObject
Returns:
World - world containing this object

getLengthInBases

public int getLengthInBases()
Returns the length of the algorithmic nucleic acid in bases.

Specified by:
getLengthInBases in interface INucleicAcid
Returns:
int - length of this nucleic acid in bases

setLengthInBases

public void setLengthInBases(int aLengthInBases)
Set the length in bases of this nucleic acid.

When this property is changed, a property change event is generated for the property named EngineProp.LENGTH_IN_BASES.

Parameters:
aLengthInBases - int - new length in bases for object.

getLengthInCodons

public int getLengthInCodons()
Returns the length of the algoritmic nucleic acid in codons. If the number of bases doesn't divide evenly by 3, then the remainder bases are ignored. We do not round up in any sense.

Specified by:
getLengthInCodons in interface INucleicAcid
Returns:
int - length of this nucleic acid in codons

getSeed

public long getSeed()
Returns the seed value of this algorithmic nucleic acid.

Returns:
long - seed value of this nucleic acid

setSeed

public void setSeed(long aSeed)
Set the seed of this nucleic acid. This should be done only very carefully, as it will change the base values.

When this property is changed, a property change event is generated for the property named EngineProp.LENGTH_IN_BASES.

Parameters:
aSeed - long - new seed

getBase

public byte getBase(int index)
Returns the base value at the given index in this raw nucleic acid. Note that this value is along one strand. If the value of the other strand is desired, use Base.getPairBase().

This base is calculated by creating a new seed based on the given index, getting the first random number using that seed and then masking out all but the 2 least significant digits to get a number between 0 and 3 to use to choose a base value.

This isn't a great algorithm, as it's not clear that we'll get truly random sequences of base values. But it's a fine start for now and we'll improve it as necessary in the future.

Specified by:
getBase in interface INucleicAcid
Parameters:
index - int - index into autosome, must be 0 to length of autosome-1
Throws:
java.lang.IllegalArgumentException - - input argument(s) illegal
See Also:
Base.getPairBase(byte, int)

getStartIndexInHolder

public int getStartIndexInHolder()
Returns the start index of this nucleic acid in its holder.

Specified by:
getStartIndexInHolder in interface INucleicAcid
Returns:
int - index in holder, in bases

setStartIndexInHolder

public void setStartIndexInHolder(int anIndex)
Set the start index of this nucleic acid in its holder.

When this property is changed, a property change event is generated for the property named EngineProp.START_INDEX_IN_HOLDER.

Parameters:
int - - new index in holder, must be between 0 and the length in bases

getInDNAOrRNA

public int getInDNAOrRNA()
Returns whether this nucleic acid is in DNA or RNA.

Returns:
int - in DNA or RNA (Base.IN_DNA or Base.IN_RNA)
See Also:
Base.IN_DNA, Base.IN_RNA

writeToStream

public void writeToStream(java.io.PrintWriter stream)
                   throws java.io.IOException
Writes this object to the given stream in XML format. Usually this method is used to write the object to a file for saving it, but that is potentially not the only use.

We could supply a default implementation that knows how to write the id value. But that convenience is not chosen because it's never correct to use just this implementation of these methods, so I'd rather have a compilation fail if a derived class fails to implement this method.

The inverse of this method is a constructor that takes a org.xml.sax.Parser argument and other arguments.

Specified by:
writeToStream in interface INucleicAcid
Overrides:
writeToStream in class EngineObject
Parameters:
stream - PrintWriter - print stream
Throws:
java.lang.IllegalArgumentException - - input arguments illegal
java.io.IOException - - an IO error occurred in java libraries