org.concord.biologica.engine
Class OrganismChromosome

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

public final class OrganismChromosome
extends EngineObject
implements java.io.Serializable

This class represents an organism chromosome - a chromosome which has a length and some organism alleles.

An instance of this class is contained by one organism.

An instance of this class may or may not be part of a diploid chromosome set and therefore may or may not have a homologous chromosome.

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

Version:
$Revision: 1.3 $ $Date: 2002/03/29 15:10:11 $
Author:
$Author: qliao $
See Also:
EngineProp.DELETED, EngineProp.ID, EngineProp.IMAGE_NUMBER, EngineProp.LOCKED_STATE, EngineProp.NUMBER_TYPE, EngineProp.ORGANISM_ALLELE_ADDED, EngineProp.ORGANISM_ALLELE_REMOVED, 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
OrganismChromosome(Organism anOrganism, ChromosomeSpecification aChromosomeSpecification)
          Create a new organism chromosome from a chromosome specification, choosing alleles based on the chromosome specification.
OrganismChromosome(Organism anOrganism, OrganismChromosome anOrganismChromosome)
          Create a new organism chromosome with another organism chromosome as a model.
OrganismChromosome(Organism anOrganism, SpeciesChromosome aSpeciesChromosome)
          Create a new organism chromosome from a species chromosome, randomly choosing alleles from the genes of the species chromosome.
OrganismChromosome(Organism anOrganism, java.lang.String anElementName, int anElementID, com.sun.xml.parser.Parser anXMLParser, ImportContext importContext)
          Create a new organism chromosome 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)
           
 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 chromosome.
 int getChromosomeType()
          Get the chromosome type (autosome or sex chromosome).
 int getChromosomeViewHeight()
           
 int getImageNumber()
          Returns the image number of this chromosome.
 int getLengthInBases()
          Returns the length of the chromosome in bases.
 int getLengthInCodons()
          Returns the length of the chromosome in codons.
 int getNumberOfOrganismAlleles()
          Return the number of organism alleles of this chromosome.
 int getNumberType()
          Returns the number or type of this chromosome.
 java.lang.String getNumberTypeAsString()
          Returns the number / type of this chromosome.
 Organism getOrganism()
          Returns the organism chromosome's organism.
 java.util.Enumeration getOrganismAlleles()
          Returns an enumeration over the chromosome's organism alleles.
 OrganismAllele[] getPStrand()
           
 java.awt.Color[] getPStrandColor()
           
 OrganismAllele[] getQStrand()
           
 java.awt.Color[] getQStrandColor()
           
 Species getSpecies()
          Returns the organism chromosome's species.
 SpeciesChromosome getSpeciesChromosome()
          Get the species chromosome for ths organism chromosome.
 World getWorld()
          Get the world containing this object.
 void ignorableWhitespace(char[] ch, int start, int length)
          Receive notification of ignorable white space character data.
 boolean isSexChromosome()
          Returns whether the chromosome is a sex chromosome.
 boolean isVisible()
          Get the visibility of this chromosome.
 void setAutomaticLocked(boolean automaticLocked)
          Set or unset the automatic locked state of this object, leaving other components of the locked state untouched.
 void setChromosomeBranchs(OrganismAllele[] P_Strand, java.awt.Color[] P_Strand_Color, OrganismAllele[] Q_Strand, java.awt.Color[] Q_Strand_Color)
          This method is used to remember the paint information for this chromosome, Special for drawing the new chromosome for the crossing over offspring.
 void setChromosomeViewHeight(int h)
           
 void setImageNumber(int anImageNumber)
          Sets the image number of this chromosome.
 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 setNumberType(int aNumberType)
          Sets the number or type of this chromosome.
 void setNumberTypeAsString(java.lang.String aNumberTypeString)
          Sets the number or type of this chromosome, using a string as input.
 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, setID, setLockedStateAsString
 
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
 

Constructor Detail

OrganismChromosome

public OrganismChromosome(Organism anOrganism,
                          SpeciesChromosome aSpeciesChromosome)
Create a new organism chromosome from a species chromosome, randomly choosing alleles from the genes of the species chromosome.

It's expected that this method will be used to create organisms from a species definition (e.g. out of thin air), as in when creating a first set of organisms at the start of editing session.

Parameters:
anOrganism - Organism - containing organism, may not be null
aSpeciesChromosome - SpeciesChromosome - a species chromosome to use as a model, may not be null
Throws:
java.lang.IllegalArgumentException - - input argument(s) illegal

OrganismChromosome

public OrganismChromosome(Organism anOrganism,
                          ChromosomeSpecification aChromosomeSpecification)
Create a new organism chromosome from a chromosome specification, choosing alleles based on the chromosome specification.

It's expected that this method will be used to create organism chromosomes produced by an explicit meiosis / fertilization process.

Parameters:
anOrganism - Organism - containing organism, may not be null
aChromosomeSpecification - ChromosomeSpecification - a chromosome specification to use, may not be null
Throws:
java.lang.IllegalArgumentException - - input argument(s) illegal

OrganismChromosome

public OrganismChromosome(Organism anOrganism,
                          OrganismChromosome anOrganismChromosome)
Create a new organism chromosome with another organism chromosome as a model.

This constructor is useful when creating an organism from another organism, as when a child is formed from the genotypes of its parents. See the Organism constructor that takes 2 parent organisms for an example of how this constructor is used.

Parameters:
anOrganism - Organism - containing organism, may not be null
anOrganismChromosome - OrganismChromosome - an organism chromosome to use as a model, may not be null
Throws:
java.lang.IllegalArgumentException - - input argument(s) illegal

OrganismChromosome

public OrganismChromosome(Organism anOrganism,
                          java.lang.String anElementName,
                          int anElementID,
                          com.sun.xml.parser.Parser anXMLParser,
                          ImportContext importContext)
Create a new organism chromosome and start handling XML parsing events to set the properties of this object.

Parameters:
anOrganism - Organism - the enclosing organism for this new organism chromosome
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.

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

Overrides:
delete in class EngineObject

delete

public void delete(boolean notifyChange)

getSpeciesChromosome

public SpeciesChromosome getSpeciesChromosome()
Get the species chromosome for ths organism chromosome.
Returns:
SpeciesChromosome - species chromosome for this organism chromosome

isVisible

public boolean isVisible()
Get the visibility of this chromosome. This is entirely determined by the species chromosome of this chromosome. In other words, you cannot set the visibility of an organism chromosome individually. Instead, you can set the visibility of that chromosome for an entire species. If speciesChromosome is null, return true.

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.

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.

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.

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

getOrganism

public Organism getOrganism()
Returns the organism chromosome's organism.

Returns:
Organism - containing organism, never null

getSpecies

public Species getSpecies()
Returns the organism chromosome's species.

Returns:
Species - organism chromosome's species, may not be null

getWorld

public World getWorld()
Get the world containing this object.

Overrides:
getWorld in class EngineObject
Returns:
World - the world containing this object, never null.

getLengthInBases

public int getLengthInBases()
Returns the length of the chromosome in bases.

Returns:
int - length of this chromosome in bases

getLengthInCodons

public int getLengthInCodons()
Returns the length of the chromosome in codons.

Returns:
int - length of this chromosome in codons

getBase

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

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

getNumberType

public int getNumberType()
Returns the number or type of this chromosome. Possible values include IChromosome.X_CHROMOSOME, IChromosome.Y_CHROMOSOME and an integer greater than 0.

Returns:
int - number / type of this chromosome

getNumberTypeAsString

public java.lang.String getNumberTypeAsString()
Returns the number / type of this chromosome.

Returns:
int - IChromosome.X_CHROMOSOME, IChromosome.Y_CHROMOSOME or an autosome number

setNumberType

public void setNumberType(int aNumberType)
Sets the number or type of this chromosome. Possible values include IChromosome.X_CHROMOSOME, IChromosome.Y_CHROMOSOME and an integer greater than 0.

Parameters:
aNumberType - int - new number or type of chromosome

setNumberTypeAsString

public void setNumberTypeAsString(java.lang.String aNumberTypeString)
Sets the number or type of this chromosome, using a string as input. Possible values include IChromosome.X_CHROMOSOME_STRING, IChromosome.Y_CHROMOSOME_STRING and an integer greater than 0.

Parameters:
aNumberTypeString - String - new number or type of chromosome as a string
Throws:
ObjectDeletedException - - object is deleted and cannot be modified
ObjectLockedException - - object is locked and cannot be deleted

getImageNumber

public int getImageNumber()
Returns the image number of this chromosome.

Returns:
int - image number of chromosome
See Also:
SpeciesChromosome.LONGEST_CHROMOSOME_IMAGE, SpeciesChromosome.LONGER_CHROMOSOME_IMAGE, SpeciesChromosome.LONG_CHROMOSOME_IMAGE, SpeciesChromosome.MEDIUM_CHROMOSOME_IMAGE, SpeciesChromosome.SHORT_CHROMOSOME_IMAGE, SpeciesChromosome.SHORTER_CHROMOSOME_IMAGE, SpeciesChromosome.SHORTEST_CHROMOSOME_IMAGE, SpeciesChromosome.TINY_CHROMOSOME_IMAGE

setImageNumber

public void setImageNumber(int anImageNumber)
Sets the image number of this chromosome.

Parameters:
anImageNumber - int - new image number of chromosome
Throws:
ObjectDeletedException - - object is deleted and cannot be modified
ObjectLockedException - - object is locked and cannot be deleted

isSexChromosome

public boolean isSexChromosome()
Returns whether the chromosome is a sex chromosome.

Returns:
boolean - true if sex chromosome, else false

getChromosomeType

public int getChromosomeType()
Get the chromosome type (autosome or sex chromosome).

Returns:
int - IChromosome.AUTOSOME or IChromosome.SEX_CHROMOSOME

getOrganismAlleles

public java.util.Enumeration getOrganismAlleles()
Returns an enumeration over the chromosome's organism alleles.

If there are no alleles on this chromosome, an enumeration with no elements is returned.

If there are alleles on this chromosome, the vector of alleles is cloned and an enumeration over that clone is returned. This enables you to safely modify the chromosome and its alleles while using the enumeration.

Returns:
Enumeration - an enumeration over the vector of alleles of this chromosome, never null

getNumberOfOrganismAlleles

public int getNumberOfOrganismAlleles()
Return the number of organism alleles of this chromosome.

Returns:
int - the number of organism alleles of this chromosome

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.

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

setChromosomeBranchs

public void setChromosomeBranchs(OrganismAllele[] P_Strand,
                                 java.awt.Color[] P_Strand_Color,
                                 OrganismAllele[] Q_Strand,
                                 java.awt.Color[] Q_Strand_Color)
This method is used to remember the paint information for this chromosome, Special for drawing the new chromosome for the crossing over offspring. param@ P_Strand OrganismAllele [] -- the alleles on the up strand of this chromosome; param@ P_Strand_Color Color [] -- the Strand's color param@ Q_Strand OrganismAllele [] -- the alleles on the down strand of this chromosome; param@ Q_Strand_Color Color [] -- the Strand's color

getPStrand

public OrganismAllele[] getPStrand()

getPStrandColor

public java.awt.Color[] getPStrandColor()

getQStrand

public OrganismAllele[] getQStrand()

getQStrandColor

public java.awt.Color[] getQStrandColor()

setChromosomeViewHeight

public void setChromosomeViewHeight(int h)

getChromosomeViewHeight

public int getChromosomeViewHeight()