forked from heavywatal/practice-py
-
Notifications
You must be signed in to change notification settings - Fork 0
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 735afc7
Showing
2 changed files
with
45 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import pandas as pd | ||
from population import Population | ||
|
||
|
||
def calculate_ave(seq): | ||
return sum(seq)/len(seq) | ||
|
||
|
||
def calculate_var(seq): | ||
ave = calculate_ave(seq) | ||
sqd = [(seq[x] - ave)**2 for x in range(len(seq))] | ||
return sum(sqd)/len(seq) | ||
|
||
|
||
def change_allelewf(Population): # simulate fixation in Wrigft-Fisher model | ||
time = 0 | ||
while Population.is_not_fixed(): | ||
Population.next_genwf() | ||
Population.print_ids() | ||
time += 1 | ||
else: | ||
winner_id = Population._inds[0] | ||
return time, winner_id | ||
|
||
|
||
def simulate_fixmo(Population): # simulate fixation in Moran model | ||
time = 0 | ||
while Population.is_not_fixed(): | ||
Population.next_genmo() | ||
time += 1 | ||
else: | ||
winner_id = Population._inds[0] | ||
return time, winner_id | ||
|
||
|
||
p1 = Population(10) | ||
data = list(change_allelewf(p1)) | ||
data.to_csv() |