Skip to content

Commit

Permalink
Updated crossover function inside genetic.py to make new chromosomes …
Browse files Browse the repository at this point in the history
…inherit their parent's background mutation rate
  • Loading branch information
Clarence Castillo committed Oct 9, 2013
1 parent 9732725 commit abfd23a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions dose/genetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,9 @@ def crossover(chromosome1, chromosome2, position):
@param position: base position of the swap over
@type position: integer
@return: (resulting chromosome1, resulting chromosome2)
New chromosomes inherit their parent's crossed sequences, bases and
background mutation rate.
@since: version 0.4
"""
Expand All @@ -609,19 +612,19 @@ def crossover(chromosome1, chromosome2, position):
position = int(position)
if len(seq1) > position and len(seq2) > position:
new1 = Chromosome(seq1[:position] + seq2[position:],
chromosome1.base)
chromosome1.base, chromosome1.background_mutation)
new2 = Chromosome(seq2[:position] + seq1[position:],
chromosome2.base)
chromosome2.background_mutation)
return (new1, new2)
elif len(seq1) > position:
new1 = Chromosome(seq1[:position], chromosome1.base)
new1 = Chromosome(seq1[:position], chromosome1.base, chromosome1.background_mutation)
new2 = Chromosome(chromosome2.sequence + seq1[position:],
chromosome2.base)
chromosome2.base, chromosome2.background_mutation)
return (new1, new2)
elif len(seq2) > position:
new1 = Chromosome(chromosome1.sequence + seq2[position:],
chromosome1.base)
new2= Chromosome(seq2[:position], chromosome2.base)
chromosome1.base, chromosome1.background_mutation)
new2= Chromosome(seq2[:position], chromosome2.base, chromosome2.background_mutation)
return (new1, new2)
else:
return (chromosome1, chromosome2)
Expand Down

0 comments on commit abfd23a

Please sign in to comment.