for line in filename: if (not line.startswith(">")): sequence = sequence + line sequence.replace("\n", "") return sequence sequence = parse_fasta(fasta) environment = Environment(0.000000001, 10) organism = Organism(sequence) environment.population_list.append(organism) start = time.clock() for organism in environment.population_list: print "-" * 20 print "Current organism: ", organism organism.transcribe() organism.translate() environment.population_list.append(organism.reproduce()) print "Population:", len(environment.population_list) print environment.population_list print "-" * 20 if len(environment.population_list) >= environment.carrying_capacity: break stop = time.clock() print environment.population_list print "Total time taken =", (stop-start), "seconds"
def reproduce(self): self.children = [Organism.reproduce(p1, p2) for (p1, p2) in zip(self.parents1, self.parents2)] self.population += self.children self.population = sorted(self.population, key=lambda org: org.fitness, reverse=True)[:self.pop_size]