org.concord.biologica.engine
Class RawNucleicAcid

java.lang.Object
  |
  +--org.xml.sax.HandlerBase
        |
        +--org.concord.biologica.engine.EngineObject
              |
              +--org.concord.biologica.engine.RawNucleicAcid
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 RawNucleicAcid
extends EngineObject
implements INucleicAcid, java.io.Serializable

This class represents a nucleic acid stored as a sequence of base values.

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

Version:
$Revision: 1.1.1.1 $ $Date: 2001/04/28 00:39:14 $
Author:
$Author: ed $
See Also:
EngineProp.BASE_VALUES, EngineProp.DELETED, EngineProp.ID, EngineProp.IN_DNA_OR_RNA, EngineProp.LOCKED_STATE, 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
RawNucleicAcid(INucleicAcidHolder aHolder, int startIndexInHolder, byte[] baseValues, int inDNAorRNA)
          Create a new raw nucleic acid given some base values.
RawNucleicAcid(INucleicAcidHolder aHolder, int startIndexInHolder, RawNucleicAcid aRawNucleicAcid, int inDNAorRNA)
          Create a new raw nucleic acid in the given holder from a given raw nucleic acid.
RawNucleicAcid(INucleicAcidHolder aHolder, java.lang.String anElementName, int anElementID, com.sun.xml.parser.Parser anXMLParser, ImportContext importContext)
          Create a new raw nucleic acid and start handling XML parsing events to set the properties of this object.
 
Method Summary
 void characters(char[] ch, int start, int length)
          Receive notification of character data.
 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.
 void endElement(java.lang.String anElementName)
          Handle notification that the parsing of the given element has ended.
 byte getBase(int index)
          Returns the base value at the given index in this raw nucleic acid.
 byte[] getBases()
          Get the bases of this raw nucleic acid as an array of bytes.
 INucleicAcidHolder getHolder()
          Returns the raw nucleic acid's holder.
 int getLengthInBases()
          Returns the length of the raw nucleic acid in bases.
 int getLengthInCodons()
          Returns the length of the raw nucleic acid in codons, which is calculated by dividing the length in bases by 3, ignoring any remainder.
 int getStartIndexInHolder()
          Returns the start index of this nucleic acid in its holder.
 World getWorld()
          Returns the world containing this nucleic acid.
 void ignorableWhitespace(char[] ch, int start, int length)
          Receive notification of ignorable white space character data.
 void setBase(int index, byte newBase)
          Sets the base value at the given index in this nucleic acid.
 void setBases(byte[] newBases)
          Sets the base values array for this nucleic acid.
 void setStartIndexInHolder(int anIndex)
          Set the start index of this nucleic acid in its holder.
 void startElement(java.lang.String anElementName, org.xml.sax.AttributeList amap)
          Handle notification that the parser has hit the start of a new element with the given name and attributes.
 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
endDocument, error, fatalError, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, startDocument, 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

RawNucleicAcid

public RawNucleicAcid(INucleicAcidHolder aHolder,
                      int startIndexInHolder,
                      byte[] baseValues,
                      int inDNAorRNA)
Create a new raw nucleic acid given some 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
baseValues - byte[] - base values array, may be null or zero length
inDNAorRNA - int - Base.IN_DNA or Base.IN_RNA
Throws:
java.lang.IllegalArgumentException - - input argument(s) illegal

RawNucleicAcid

public RawNucleicAcid(INucleicAcidHolder aHolder,
                      int startIndexInHolder,
                      RawNucleicAcid aRawNucleicAcid,
                      int inDNAorRNA)
Create a new raw nucleic acid in the given holder from a given raw nucleic acid.

Parameters:
aHolder - INucleicAcidHolder - holder of this nucleic acid (e.g. allele, chromosome), may not be null
startIndexInHolder - int - start index of raw nucleic acid in the given holder
RawNucleicAcid - aRawNucleicAcid - an existing raw nucleic acid
inDNAorRNA - int - Base.IN_DNA or Base.IN_RNA
Throws:
java.lang.IllegalArgumentException - - input argument(s) illegal

RawNucleicAcid

public RawNucleicAcid(INucleicAcidHolder aHolder,
                      java.lang.String anElementName,
                      int anElementID,
                      com.sun.xml.parser.Parser anXMLParser,
                      ImportContext importContext)
Create a new raw nucleic acid and start handling XML parsing events to set the properties of this object.

Parameters:
aHolder - INucleicAcidHolder - the enclosing holder for this raw nucleic acid
anElementName - String - the element name
anElementID - int - the element id
anXMLParser - com.sun.xml.parser.Parser - the element parser
importContext - ImportContext - import context for mapping ids from file to this world
Throws:
java.lang.IllegalArgumentException - - input arguments illegal
Method Detail

startElement

public void startElement(java.lang.String anElementName,
                         org.xml.sax.AttributeList amap)
                  throws org.xml.sax.SAXException
Handle notification that the parser has hit the start of a new element with the given name and attributes.

For internal elements (elements that are non-EngineObject instance variables of this object), call xmlElementContext.startElement() and xmlElementContext will receive the remaining element notifications. For external elements (elements that are EngineObject instance variables of this object), create an object of the appropriate class and that object will receive the remaining element notifications.

Overrides:
startElement in class org.xml.sax.HandlerBase
Parameters:
anElementName - String - name of element
amap - AttributeList - an attribute list

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws org.xml.sax.SAXException
Receive notification of character data.
Overrides:
characters in class org.xml.sax.HandlerBase
Parameters:
ch - char[] - characters
start - int - start of string
length - int - length of string

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws org.xml.sax.SAXException
Receive notification of ignorable white space character data.
Overrides:
ignorableWhitespace in class org.xml.sax.HandlerBase
Parameters:
ch - char[] - characters
start - int - start of string
length - int - length of string

endElement

public void endElement(java.lang.String anElementName)
                throws org.xml.sax.SAXException
Handle notification that the parsing of the given element has ended.
Overrides:
endElement in class org.xml.sax.HandlerBase
Parameters:
anElementName - String - the element name

delete

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

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 raw nucleic acid in bases.

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

getLengthInCodons

public int getLengthInCodons()
Returns the length of the raw nucleic acid in codons, which is calculated by dividing the length in bases by 3, ignoring any remainder.

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

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().

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

setBase

public void setBase(int index,
                    byte newBase)
Sets the base value at the given index in this nucleic acid.

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

Parameters:
index - int - index into allele, must be 0 to length of nucleic acid-1
newBase - byte - new base value at given index
Throws:
java.lang.IllegalArgumentException - - input argument(s) illegal

getBases

public byte[] getBases()
Get the bases of this raw nucleic acid as an array of bytes.
Returns:
byte[] - array of byte base values

setBases

public void setBases(byte[] newBases)
Sets the base values array for this nucleic acid.

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

Parameters:
newBases - byte[] - new base values array, may be null

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

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