Skip to content

Commit

Permalink
solved heavywatal#20
Browse files Browse the repository at this point in the history
  • Loading branch information
hamazaki1990 committed May 18, 2017
1 parent cf20eb4 commit 94f157a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
6 changes: 6 additions & 0 deletions hamazaki1990/population.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ def get_fitnesses(self):
fitness = [x.get_fitness() for x in self._inds]
return fitness

def get_mutantfreq(self):
fitness = [x.get_fitness() for x in self._inds]
mutantfreq = 1 - fitness.count(1.0)/len(fitness)
return mutantfreq

def next_genwf(self):
fitness = [x.get_fitness() for x in self._inds]
size = len(self._inds)
Expand Down Expand Up @@ -74,6 +79,7 @@ def main():
print(p1_2.get_fitnesses())
print(p1_2.is_not_fixed())
print(p1_2.mutation_is_not_fixed())
print(p1_2.get_mutantfreq())

for x in range(20):
p1_2.next_genwf()
Expand Down
34 changes: 19 additions & 15 deletions hamazaki1990/visualize.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
import csv
import pandas as pd
from population import Population


def change_allelewf(population):
fit_list = population.get_fitnesses()
fixprocess = [1 - fit_list.count(1.0)/len(fit_list)]
t = 0
fixprocess = [[t, population.get_mutantfreq()]]
while population.mutation_is_not_fixed():
t += 1
population.next_genwf()
fit_list = population.get_fitnesses()
mutantrate = 1 - fit_list.count(1.0)/len(fit_list)
fixprocess.append(mutantrate)
fixprocess.append([t, population.get_mutantfreq()])
return fixprocess


def change_allelemo(population):
fit_list = population.get_fitnesses()
fixprocess = [1 - fit_list.count(1.0)/len(fit_list)]
t = 0
fixprocess = [[t, population.get_mutantfreq()]]
while population.mutation_is_not_fixed():
t += 1
population.next_genmo()
fit_list = population.get_fitnesses()
mutantrate = 1 - fit_list.count(1.0)/len(fit_list)
fixprocess.append(mutantrate)
fixprocess.append([t, population.get_mutantfreq()])
return fixprocess


csvfile1 = open("allelechangewf.csv", "w", encoding="utf-8")
writer = csv.writer(csvfile1)
p1 = Population(10, 0.1, 0.5)
writer.writerow(change_allelewf(p1))
fixprocesswf = change_allelewf(p1)
writer.writerow(["generation", "derived_allele_frequency"])
for x in range(len(fixprocesswf)):
writer.writerow(fixprocesswf[x])


p2 = Population(10, 0.1, 0.5)
print(change_allelemo(p2))
csvfile2 = open("allelechangemo.csv", "w", encoding="utf-8")
writer = csv.writer(csvfile2)
p1 = Population(10, 0.1, 0.5)
fixprocessmo = change_allelemo(p1)
writer.writerow(["generation", "derived_allele_frequency"])
for x in range(len(fixprocessmo)):
writer.writerow(fixprocessmo[x])
17 changes: 11 additions & 6 deletions hamazaki1990/visualize.r
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
install.packages("tidyverse")
library("tidyverse")
allelefreq=read_csv("~/github/practice-py/hamazaki1990/allelechangewf.csv", col_names = FALSE)
names(allelefreq)=c("generation","derived_allele_frequency")
freqprot=ggplot(allelefreq, x=generation, y=derived_allele_frequency)
freqprot=freqprot+geom_line()
print(freqprot)
freq <- read_csv("~/github/practice-py/hamazaki1990/allelechangewf.csv")
freq
freqplot <- ggplot(freq, aes(x = generation, y = derived_allele_frequency))
freqplot <- freqplot + geom_line()
print(freqplot)

freq1 <- read_csv("~/github/practice-py/hamazaki1990/allelechangemo.csv")
freq1
freqplot1 <- ggplot(freq1, aes(x = generation, y = derived_allele_frequency))
freqplot1 <- freqplot1 + geom_path(size=2, linetype="dashed")
print(freqplot1)

0 comments on commit 94f157a

Please sign in to comment.