-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1274b2b
commit e89ca72
Showing
4 changed files
with
95 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import csv | ||
from population import Population | ||
|
||
|
||
def change_allelewf(population): | ||
t = 0 | ||
fixprocess = [[t, population.get_mutantfreq()]] | ||
while population.mutation_is_not_fixed(): | ||
t += 1 | ||
population.next_genwf() | ||
fixprocess.append([t, population.get_mutantfreq()]) | ||
return fixprocess | ||
|
||
|
||
def change_allelemo(population): | ||
t = 0 | ||
fixprocess = [[t, population.get_mutantfreq()]] | ||
while population.mutation_is_not_fixed(): | ||
t += 1 | ||
population.next_genmo() | ||
fixprocess.append([t, population.get_mutantfreq()]) | ||
return fixprocess | ||
|
||
|
||
def output_allelechange(filename, population, function): | ||
with open(filename, "w", encoding="utf-8") as outfile: | ||
writer = csv.writer(outfile) | ||
writer.writerow(["generation", "derived_allele_frequency"]) | ||
fixprocess = function(population) | ||
for x in range(len(fixprocess)): | ||
writer.writerow(fixprocess[x]) | ||
|
||
|
||
p1 = Population(10, 0.1, 0.2) | ||
output_allelechange("allelefreqwf.csv", p1, change_allelewf) | ||
|
||
p2 = Population(10, 0.1, 0.5) | ||
output_allelechange("allelefreqmo.csv", p2, change_allelemo) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
library("tidyverse") | ||
setwd("~/github/practice-py/hamazaki1990/") | ||
freq_wf <- read_csv("allelefreqwf.csv") %>% | ||
dplyr::mutate(model = "wf") | ||
freq_wf | ||
freq_mo <- read_csv("allelefreqmo.csv") %>% | ||
dplyr::mutate(model = "moran") | ||
freq_mo | ||
freq <- dplyr::bind_rows(freq_wf, freq_mo) | ||
print(freq) | ||
freqplot <- ggplot(freq, aes(x=generation, y=derived_allele_frequency, group=model, color=model)) | ||
freqplot <-freqplot + geom_line() | ||
print(freqplot) |