Back to index

python-biopython  1.60
Public Member Functions | Private Attributes
Bio.GA.Mutation.Simple.SinglePositionMutation Class Reference

List of all members.

Public Member Functions

def __init__
def mutate

Private Attributes

 _mutation_rate
 _mutation_rand
 _switch_rand
 _pos_rand

Detailed Description

Perform a conversion mutation, but only at a single point in the genome.

This does not randomize the genome as much as ConversionMutation, since
only one change is allowed per genome at the specified mutation rate.

Definition at line 6 of file Simple.py.


Constructor & Destructor Documentation

def Bio.GA.Mutation.Simple.SinglePositionMutation.__init__ (   self,
  mutation_rate = 0.001 
)
Initialize a mutator.

Arguments:

o mutation_rate - The chance of a mutation happening once in the
genome.

Definition at line 12 of file Simple.py.

00012 
00013     def __init__(self, mutation_rate = 0.001):
00014         """Initialize a mutator.
00015 
00016         Arguments:
00017 
00018         o mutation_rate - The chance of a mutation happening once in the
00019         genome.
00020         """
00021         self._mutation_rate = mutation_rate
00022         # a random number generator to test if we have a mutation
00023         self._mutation_rand = random.Random()
00024         # a random number generator to switch to a new alphabet letter
00025         self._switch_rand = random.Random()
00026         # a random number generator to find the mutation position
00027         self._pos_rand = random.Random()

Here is the caller graph for this function:


Member Function Documentation

Mutate the organisms genome.

Definition at line 28 of file Simple.py.

00028 
00029     def mutate(self, organism):
00030         """Mutate the organisms genome.
00031         """
00032         mutated_org = organism.copy()
00033         gene_choices = mutated_org.genome.alphabet.letters
00034 
00035         mutation_chance = self._mutation_rand.random()
00036         if mutation_chance <= self._mutation_rate:
00037             # pick a gene position to mutate at
00038             mutation_pos = \
00039                          self._pos_rand.choice(range(len(mutated_org.genome)))
00040             
00041             # get a new letter to replace the position at
00042             new_letter = self._switch_rand.choice(gene_choices)
00043 
00044             mutated_org.genome[mutation_pos] = new_letter
00045 
00046         return mutated_org


Member Data Documentation

Definition at line 22 of file Simple.py.

Definition at line 20 of file Simple.py.

Definition at line 26 of file Simple.py.

Definition at line 24 of file Simple.py.


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