org.concord.biologica.engine
Class NucleicAcid

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

public class NucleicAcid
extends EngineObject
implements INucleicAcid, INucleicAcidHolder, java.io.Serializable

This class represents a container nucleic acid, which is little more than a collection of other nucleic acids, some of which are alleles, some algorithmic sequences, some containers, etc.

This class may be used for both DNA and RNA.

This class hides the different types of nucleic acids from casual users of the class, creating children of the various types as needed and storing them in a vector. For example, an autosome just needs to store a reference to an instance of this class and doesn't need to worry about what form of nucleic acid object is stored within this object (raw, etc.).

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

Version:
$Revision: 1.1.1.1 $ $Date: 2001/04/28 00:39:13 $
Author:
$Author: ed $
See Also:
EngineProp.DELETED, EngineProp.ID, EngineProp.IN_DNA_OR_RNA, EngineProp.LOCKED_STATE, EngineProp.NAME, EngineProp.NUCLEIC_ACID_ADDED, EngineProp.NUCLEIC_ACID_REMOVED, 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
NucleicAcid(INucleicAcidHolder aHolder, int startIndexInHolder, byte[] baseValues, int inDNAorRNA)
          Creates a new nucleic acid from the given base values.
NucleicAcid(INucleicAcidHolder aHolder, int startIndexInHolder, java.util.Vector nucleicAcids, int inDNAorRNA)
          Creates a new nucleic acid from the given vector of nucleic acids, which is handy when the vector is created during meiosis.
 
Method Summary
 void addNucleicAcid(INucleicAcid aNucleicAcid)
          Adds a nucleic acid to the holder.
 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 sequence.
 INucleicAcidHolder getHolder()
          Returns the raw nucleic acid's holder.
 int getLengthInBases()
          Returns the length of the nucleic acid by summing up the lengths of all of the child nucleic acids.
 int getLengthInCodons()
          Returns the length of the nucleic acid in codons by summing up the lengths in codons of all of the child nucleic acids.
 int getStartIndexInHolder()
          Returns the start index of this nucleic acid in its holder.
 World getWorld()
          Returns the world containing this nucleic acid.
 boolean removeNucleicAcid(INucleicAcid aNucleicAcid)
          Removes a nucleic acid from the holder.
 void setAutomaticLocked(boolean automaticLocked)
          Set or unset the automatic locked state of this object, leaving other components of the locked state untouched.
 void setLockedState(int aLockedState)
          Set the lock state of the object, recursively setting the lock state of children objects.
 void setManualLocked(boolean manualLocked)
          Set or unset the manual locked state of this object, leaving other components of the locked state untouched.
 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, setID, setLockedStateAsString
 
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.INucleicAcidHolder
endElement, getID
 

Constructor Detail

NucleicAcid

public NucleicAcid(INucleicAcidHolder aHolder,
                   int startIndexInHolder,
                   byte[] baseValues,
                   int inDNAorRNA)
Creates a new nucleic acid from the given base values.

Parameters:
aHolder - INucleicAcidHolder - holder of this nucleic acid, may not be null
startIndexInHolder - int - start index of this nucleic acid in holder
baseValues - byte[] - base values array, may not be null or zero length
inDNAorRNA - int - in DNA or RNA?, must be Base.IN_DNA or Base.IN_RNA
Throws:
java.lang.IllegalArgumentException - - input argument(s) illegal

NucleicAcid

public NucleicAcid(INucleicAcidHolder aHolder,
                   int startIndexInHolder,
                   java.util.Vector nucleicAcids,
                   int inDNAorRNA)
Creates a new nucleic acid from the given vector of nucleic acids, which is handy when the vector is created during meiosis.

Parameters:
aHolder - INucleicAcidHolder - holder of this nucleic acid, may not be null
startIndexInHolder - int - start index of this nucleic acid in holder
nucleicAcids - Vector - vector of existing nucleic acids, may be null or empty
inDNAorRNA - int - in DNA or RNA?, must be Base.IN_DNA or Base.IN_RNA
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

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.

Specified by:
getWorld in interface INucleicAcidHolder
Overrides:
getWorld in class EngineObject
Returns:
World - world containing this object

setAutomaticLocked

public void setAutomaticLocked(boolean automaticLocked)
Set or unset the automatic locked state of this object, leaving other components of the locked state untouched. Recursively sets the automatic locked state of children of this object.

When this property is changed, a property change event is fired for the property named EngineProp.LOCKED_STATE.

Specified by:
setAutomaticLocked in interface INucleicAcid
Overrides:
setAutomaticLocked in class EngineObject
Parameters:
automaticLocked - boolean - object should be automatic locked (true) or not (false)

setManualLocked

public void setManualLocked(boolean manualLocked)
Set or unset the manual locked state of this object, leaving other components of the locked state untouched. Recursively sets the manual locked state of children of this object.

When this property is changed, a property change event is fired for the property named EngineProp.LOCKED_STATE.

Specified by:
setManualLocked in interface INucleicAcid
Overrides:
setManualLocked in class EngineObject
Parameters:
manualLocked - boolean - object should be manually locked (true) or not (false)

setLockedState

public void setLockedState(int aLockedState)
Set the lock state of the object, recursively setting the lock state of children objects.

When this property is changed, a property change event is fired for the property named EngineProp.LOCKED_STATE.

Specified by:
setLockedState in interface INucleicAcid
Overrides:
setLockedState in class EngineObject
Parameters:
aLockedState - int - new locked state of this object
Throws:
java.lang.IllegalArgumentException - - new locked state invalid

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

getLengthInBases

public int getLengthInBases()
Returns the length of the nucleic acid by summing up the lengths of all of the child nucleic acids.

Specified by:
getLengthInBases in interface INucleicAcid
Returns:
int - length of this acid in bases, may be zero

getLengthInCodons

public int getLengthInCodons()
Returns the length of the nucleic acid in codons by summing up the lengths in codons of all of the child nucleic acids.

Specified by:
getLengthInCodons in interface INucleicAcid
Returns:
int - length of this acid in codons, may be zero

getBase

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

Specified by:
getBase in interface INucleicAcid
Parameters:
index - int - index into acid (in bases), must be 0 to length of acid in bases-1
Returns:
byte - base value at given index
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

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

addNucleicAcid

public void addNucleicAcid(INucleicAcid aNucleicAcid)
Adds a nucleic acid to the holder.

This SHOULD be package protected because this is only to be called from the nucleic acid's constructor. Creating a nucleic acid automatically adds it to the holder via this method.

BUT, Java has some wierd idea that interface methods are always public, so I can't make this package protected. So PLEASE don't use them method from outside of the engine package!!

Specified by:
addNucleicAcid in interface INucleicAcidHolder
Parameters:
aNucleicAcid - INucleicAcid - a new nucleic acid, may not be null
Throws:
java.lang.IllegalArgumentException - - input argument illegal

removeNucleicAcid

public boolean removeNucleicAcid(INucleicAcid aNucleicAcid)
Removes a nucleic acid from the holder.

This SHOULD be package protected because this is only to be called from the nucleic acid's delete method. Deleting a nucleic acid automatically removes it from the holder via this method.

BUT, Java has some wierd idea that interface methods are always public, so I can't make this package protected. So please don't use them method from outside of the engine package!!

Specified by:
removeNucleicAcid in interface INucleicAcidHolder
Parameters:
aNucleicAcid - INucleicAcid - a nucleic acid, may not be null
Returns:
boolean indicating whether or not the nucleic acid was found and removed
Throws:
java.lang.IllegalArgumentException - - input argument illegal

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