-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
230 lines (196 loc) · 5.45 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
/* Style the tab */
.tab {
overflow: hidden;
border: 1px solid #ccc;
background-color: #f1f1f1;
}
/* Style the buttons inside the tab */
.tab button {
background-color: inherit;
float: left;
border: none;
outline: none;
cursor: pointer;
padding: 14px 16px;
transition: 0.3s;
font-size: 17px;
}
/* Change background color of buttons on hover */
.tab button:hover {
background-color: #ddd;
}
/* Create an active/current tablink class */
.tab button.active {
background-color: #ccc;
}
/* Style the tab content */
.tabcontent {
display: none;
padding: 6px 12px;
border: 1px solid #ccc;
border-top: none;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dygraph/2.1.0/dygraph.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/dygraph/2.1.0/dygraph.min.css" />
</head>
<body>
<p><i>Under construction</i></p>
<div class="tab">
<button class="tablinks" onclick="openTab(event, 'population')" id="defaultOpen">Population</button>
<button class="tablinks" onclick="openTab(event, 'allele')">Alleles</button>
<button class="tablinks" onclick="openTab(event, 'fitness')">Fitness</button>
<button class="tablinks" onclick="openTab(event, 'mutation')">Mutation</button>
</div>
<div id="population" class="tabcontent">
<table>
<tbody>
<tr>
<td>Populations</td>
<td><input id="popNum" type="number" min="1" max="100" step="1" value="10"></td>
</tr>
<tr>
<td>Pop Size</td>
<td><input id="popSize" type="number" min="1" step="1" value="100"></td>
</tr>
<tr>
<td>Generations</td>
<td><input id="popGen" type="number" min="1" step="1" value="200"></td>
</tr>
</tbody>
</table>
</div>
<div id="allele" class="tabcontent">
<table>
<tbody>
<tr>
<td>A1 Freq</td>
<td><input id="A1Freq" type="number" min="0" max="1" step="0.001" value="0.5"></td>
</tr>
</tbody>
</table>
</div>
<div id="fitness" class="tabcontent">
<table>
<tbody>
<tr>
<td>A1A1</td>
<td><input id="fitA1" type="number" min="0" max="1" step="0.01" value="1"></td>
</tr>
<tr>
<td>A1A2</td>
<td><input id="fitHet" type="number" min="0" max="1" step="0.01" value="1"></td>
</tr>
<tr>
<td>A2A2</td>
<td><input id="fitA2" type="number" min="0" max="1" step="0.01" value="1"></td>
</tr>
</tbody>
</table>
</div>
<div id="mutation" class="tabcontent">
<table>
<tbody>
<tr>
<td>A1⟶A2</td>
<td><input id="mutA1" type="number" min="0" max="1" step="0.01" value="0"></td>
</tr>
<tr>
<td>A1⟵A2</td>
<td><input id="mutA2" type="number" min="0" max="1" step="0.01" value="0"></td>
</tr>
</tbody>
</table>
</div>
<div>
<button type="button" onclick="runSim()">Run</button>
</div>
<div id="graphdiv"></div>
<p><i>Description</i></p>
<p><i>Copyright 2021 by Andrew Marx</i></p>
<script type="text/javascript">
function openTab(evt, cityName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(cityName).style.display = "block";
evt.currentTarget.className += " active";
}
// Get the element with id="defaultOpen" and click on it
document.getElementById("defaultOpen").click();
function rbinom(n, p) {
var x = 0;
for(var i = 0; i < n; i++) {
x+=(Math.random() < p);
}
return x;
}
var data = [];
function runSim() {
var popNum = parseInt(document.getElementById("popNum").value);
var popSize = parseInt(document.getElementById("popSize").value);
var popGen = parseInt(document.getElementById("popGen").value);
var p = parseFloat(document.getElementById("A1Freq").value);
var q = 0.0;
var mutA1 = parseFloat(document.getElementById("mutA1").value);
var mutA2 = parseFloat(document.getElementById("mutA2").value);
var fitA1 = parseFloat(document.getElementById("fitA1").value);
var fitHet = parseFloat(document.getElementById("fitHet").value);
var fitA2 = parseFloat(document.getElementById("fitA2").value);
var w = 0.0;
data = [];
var genArray = Array(popNum + 1).fill(p, 1);
for (let i = 0; i < popGen; i++) {
genArray[0] = i;
data.push(genArray.slice());
for (let j = 1; j < popNum + 1; j++) {
// Random drift
p = rbinom(popSize, genArray[j])/popSize;
q = 1 - p;
// Mutation
p = p*(1 - mutA1) + q*mutA2;
q = 1 - p;
// Fitness
w = p*p*fitA1 + 2*p*q*fitHet + q*q*fitA2;
p = (p*p*fitA1 + p*q*fitHet)/w;
// Store result
genArray[j] = p;
}
}
g = new Dygraph(
// containing div
document.getElementById("graphdiv"),
data,
{
valueRange: [0, 1],
title: "Title",
ylabel: "A1 Freq",
xlabel: "Generation",
// labels: ["Generation", "A1 Freq"],
/* axes: {
x: {
ticker: function(min, max, pixels, opts, dygraph, vals) {
}
},
y: {
ticker: function(min, max, pixels, opts, dygraph, vals) {
}
}
}*/
}
);
}
</script>
</body>
</html>