-
Notifications
You must be signed in to change notification settings - Fork 0
/
JCCharHistories.html
257 lines (208 loc) · 7.37 KB
/
JCCharHistories.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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Jukes-Cantor Character Histories</title>
<!-- d3 library for data visualization and animation -->
<script type="text/javascript" src="https://d3js.org/d3.v4.min.js"></script>
<!-- jstat library for probability distributions -->
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/jstat@latest/dist/jstat.min.js"></script>
<!-- phyleaux library for phylogenetic objects and functions -->
<script type="text/javascript" src="https://jembrown.github.io/phyleaux.js"></script>
<style type="text/css">
@font-face { font-family: Glober; font-weight: semibold; src: url('Glober-SemiBold.otf'); }
h1 {
font-family: Glober;
font-size: 24px;
}
p {
font-family: Glober;
font-size: 14px;
}
.wide-slider{
width: 800px;
}
#tooltip {
position: absolute;
width: 250px;
height: auto;
padding: 10px;
background-color: white;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
-webkit-box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.4);
-moz-box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.4);
box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.4);
pointer-events: none;
}
#tooltip.hidden {
display: none;
}
#tooltip p {
margin: 0;
font-family: sans-serif;
font-size: 16px;
line-height: 20px;
}
</style>
<script>
function showValueAppendScale(val){
document.getElementById("brl").innerHTML=val;
appendScale(val);
}
function appendScale(val){
var plotSvg = d3.select("#histories")
.append("svg")
.attr("width",800)
.attr("height",20);
plotSvg.append("line")
.attr("x1",0)
.attr("x2",800)
.attr("y1",19)
.attr("y2",19)
.attr("stroke","black")
.attr("stroke-width",2);
plotSvg.append("line")
.attr("x1",1)
.attr("x2",1)
.attr("y1",20)
.attr("y2",15)
.attr("stroke","black")
.attr("stroke-width",2);
plotSvg.append("line")
.attr("x1",800-1)
.attr("x2",800-1)
.attr("y1",20)
.attr("y2",15)
.attr("stroke","black")
.attr("stroke-width",2);
plotSvg.append("text")
.attr("fill","black")
.attr("x",0)
.attr("text-anchor","start")
.attr("font-size","14px")
.attr("y",10)
.text("0.0");
plotSvg.append("text")
.attr("fill","black")
.attr("x",800)
.attr("text-anchor","end")
.attr("font-size","14px")
.attr("y",10)
.text(val);
d3.select("#histories").append("br");
}
</script>
</head>
<body>
<div id="tooltip" class="hidden">
<p><strong>Detailed Character History</strong></p>
<p><i>Changes (Waiting Times)</i></p><br>
<p><span id="value"></span></p>
</div>
<h1>Jukes-Cantor Character Histories</h1>
<p>
Current Branch Length: <span id="brl" style="color:black;"></span><br><br>
0.0<input class="wide-slider" type="range" min="0.0" max="10.0" step="0.01" id="brlSlider" onchange="showValueAppendScale(this.value);">10.0
<br><br>
Fixed Starting State: <input type="checkbox" id="fixStart" onclick="fixStartState()" checked>
<br><br>
Show Character States: <input type="checkbox" id="showStates" onclick="showCharStates()" checked>
<br><br>
<button id="clearCharHists"
style="display: inline-block; text-align: right">Clear Character History Record
</button>
<br><br>
<button id="drawCharHist"
style="display: inline-block; text-align: right">Draw Character History
</button>
<br>
</p>
<script>
var myModel = new Model(bf=[0.25,0.25,0.25,0.25],
rates=[1,1,1,1,1,1],
gammaRates=true,
alpha=10,
invSites=false,
i=0);
var myCharHistory = new characterHistory(model=myModel);
var startState = null;
function fixStartState(){
if (document.getElementById("fixStart").checked === true){
startState = "A";
} else {
startState = null;
}
}
fixStartState();
var show = true;
function showCharStates(){
if (document.getElementById("showStates").checked === true){
show = true;
} else {
show = false;
}
}
d3.select("#clearCharHists").on("click",function(){
d3.select("#histories").selectAll("svg").remove();
d3.select("#histories").selectAll("br").remove();
var brl = parseFloat(d3.select("#brlSlider").property("value"));
appendScale(brl);
});
d3.select("#drawCharHist").on("click",function(){
var brl = parseFloat(d3.select("#brlSlider").property("value"));
myCharHistory.sampleHistory(brl,startState);
var plotSvg = d3.select("#histories").append("svg");
myCharHistory.drawHistory(brl,w=800,h=30,svg=plotSvg,showStates=show);
plotSvg.datum([myCharHistory.states,myCharHistory.waitingTimes]);
plotSvg.on("mouseover",function(d){
d3.select("#tooltip")
.style("left",d3.event.clientX + "px")
.style("top",d3.event.clientY + "px");
if (d[0].length === 1){
d3.select("#tooltip")
.select("#value")
.append("p")
.text("No character changes.")
}
for (var i = 0; i < d[0].length-1; i++){
d3.select("#tooltip")
.select("#value")
.append("p")
.text(d[0][i] + " -> " + d[0][i+1] + " (" + parseFloat(d[1][i]).toFixed(4) + ")");
}
d3.select("#tooltip").classed("hidden", false);
})
plotSvg.on("mouseout",function(){
//Hide the tooltip
d3.select("#tooltip").classed("hidden", true);
d3.select("#tooltip").select("#value").selectAll("p").remove();
})
d3.select("#histories").append("br");
});
</script>
<p>
Set the branch length using the slider. Each time you click the "Draw Character History" button, a history of
character change will be recorded below. Each history has a total length equal to the branch length you've chosen. Colors correspond to different nucleotide states (A, C, G, and T). The
length of each colored segment shows the proportion of the branch length the character spends in a given state. Mousing over a character history will give a detailed record of the changes and corresponding waiting times.
</p>
<section id="histories">
<p>Character History Record:</p>
</section>
<br><br><br><br>
<section id="pageCredits">
<p>
<img width=100 height=100 src="https://raw.githubusercontent.com/jembrown/websiteImages/master/ssb.png">
<br><br>
Development of the Phyleaux Javascript Library and related interactive phylogenetics tools is supported by the Society of Systematic Biologists.
<br><br>
Comments and bug reports should be directed to [email protected].
</p>
</section>
<script>
d3.select("#brlSlider").property("value",1.0);
showValueAppendScale(1.0);
</script>
</body>
</html>