Back to index

python-biopython  1.60
Public Member Functions | Public Attributes | Private Attributes
Bio.GA.Organism.Organism Class Reference

List of all members.

Public Member Functions

def __init__
def __str__
def __eq__
def __ne__
def __lt__
def __le__
def __gt__
def __ge__
def copy
def recalculate_fitness

Public Attributes

 genome
 fitness

Private Attributes

 _fitness_calc

Detailed Description

Represent a single individual in a population.

Attributes:

o genome -- The genome of the organism. This is a Bio.MutableSeq
object that has the sequence of the genome, and the alphabet
describing all elements that can be a part of the genome.

o fitness -- The calculate fitness of the organism. This fitness is
based on the last time it was calculated using the fitness_calculator.
So... the fitness could potentially be out of date with the real genome
if you are not careful to recalculate it after changes with
recalculate_fitness()

Definition at line 82 of file Organism.py.


Constructor & Destructor Documentation

def Bio.GA.Organism.Organism.__init__ (   self,
  genome,
  fitness_calculator,
  start_fitness = None 
)
Initialize an organism

Arguments:

o genome -- A MutableSeq object representing the sequence of the
genome.

o fitness_calculator -- A funtion that will calculate the fitness
of the organism when given the organisms genome.

o start_fitness - the starting fitness corresponding with the
given genome. If not supplied, the fitness will be calculated
using fitness_calculator.

Definition at line 97 of file Organism.py.

00097 
00098     def __init__(self, genome, fitness_calculator, start_fitness = None):
00099         """Initialize an organism
00100 
00101         Arguments:
00102 
00103         o genome -- A MutableSeq object representing the sequence of the
00104         genome.
00105 
00106         o fitness_calculator -- A funtion that will calculate the fitness
00107         of the organism when given the organisms genome.
00108 
00109         o start_fitness - the starting fitness corresponding with the
00110         given genome. If not supplied, the fitness will be calculated
00111         using fitness_calculator.
00112         """
00113         assert isinstance(genome, MutableSeq), "Genome must be a MutableSeq"
00114         
00115         self.genome = genome
00116         self._fitness_calc = fitness_calculator
00117 
00118         # calculate the fitness of the genome
00119         if start_fitness is None:
00120             self.fitness = self._fitness_calc(self.genome)
00121         else:
00122             self.fitness = start_fitness

Here is the caller graph for this function:


Member Function Documentation

def Bio.GA.Organism.Organism.__eq__ (   self,
  other 
)
Compare organisms by their genomes (as strings of letters).

Definition at line 128 of file Organism.py.

00128 
00129     def __eq__(self, other):
00130         """Compare organisms by their genomes (as strings of letters).
00131         """
00132         # See Bio/Seq.py and the comments there about shifting to
00133         # using simple string equality. Previously Seq objects used
00134         # object equality, while MutableSeq objects used alphabet
00135         # aware string equality.
00136         return str(self.genome) == str(other.genome)

Here is the caller graph for this function:

def Bio.GA.Organism.Organism.__ge__ (   self,
  other 
)
Compare organisms by their genomes (as strings of letters).

Definition at line 157 of file Organism.py.

00157 
00158     def __ge__(self, other):
00159         """Compare organisms by their genomes (as strings of letters).
00160         """
00161         return str(self.genome) >= str(other.genome)

def Bio.GA.Organism.Organism.__gt__ (   self,
  other 
)
Compare organisms by their genomes (as strings of letters).

Definition at line 152 of file Organism.py.

00152 
00153     def __gt__(self, other):
00154         """Compare organisms by their genomes (as strings of letters).
00155         """
00156         return str(self.genome) > str(other.genome)

def Bio.GA.Organism.Organism.__le__ (   self,
  other 
)
Compare organisms by their genomes (as strings of letters).

Definition at line 147 of file Organism.py.

00147 
00148     def __le__(self, other):
00149         """Compare organisms by their genomes (as strings of letters).
00150         """
00151         return str(self.genome) <= str(other.genome)

def Bio.GA.Organism.Organism.__lt__ (   self,
  other 
)
Compare organisms by their genomes (as strings of letters).

Definition at line 142 of file Organism.py.

00142 
00143     def __lt__(self, other):
00144         """Compare organisms by their genomes (as strings of letters).
00145         """
00146         return str(self.genome) < str(other.genome)

def Bio.GA.Organism.Organism.__ne__ (   self,
  other 
)
Compare organisms by their genomes (as strings of letters).

Definition at line 137 of file Organism.py.

00137 
00138     def __ne__(self, other):
00139         """Compare organisms by their genomes (as strings of letters).
00140         """
00141         return str(self.genome) != str(other.genome)

Provide a string output for debugging.

Definition at line 123 of file Organism.py.

00123 
00124     def __str__(self):
00125         """Provide a string output for debugging.
00126         """
00127         return "Genome: %s; Fitness %s" % (self.genome.tostring(), self.fitness)

Here is the caller graph for this function:

Return a copy of the organism.

This makes it easy to duplicate an organism before changing it.

Definition at line 162 of file Organism.py.

00162 
00163     def copy(self):
00164         """Return a copy of the organism.
00165 
00166         This makes it easy to duplicate an organism before changing it.
00167         """
00168         copy_genome = self.genome[:]
00169         return Organism(copy_genome, self._fitness_calc, self.fitness)

Here is the caller graph for this function:

Calculate and reset the fitness of the current genome

This should be called after the genome is updated to ensure that
fitness always stays in sync with the current genome.

Definition at line 170 of file Organism.py.

00170 
00171     def recalculate_fitness(self):
00172         """Calculate and reset the fitness of the current genome
00173 
00174         This should be called after the genome is updated to ensure that
00175         fitness always stays in sync with the current genome.
00176         """
00177         self.fitness = self._fitness_calc(self.genome)

Member Data Documentation

Definition at line 115 of file Organism.py.

Definition at line 119 of file Organism.py.

Definition at line 114 of file Organism.py.


The documentation for this class was generated from the following file: