-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
104 lines (88 loc) · 2.96 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
<!DOCTYPE html>
<html>
<head>
<title>ADRSM geometric</title>
<script src="https://unpkg.com/[email protected]/dist/math.min.js"></script>
<script src="https://cdn.plot.ly/plotly-1.35.2.min.js"></script>
<style>
input[type=text] {
width: 300px;
}
input {
padding: 6px;
}
body, html, input {
font-family: sans-serif;
font-size: 11pt;
}
form {
margin: 20px 0;
}
</style>
</head>
<body>
<p>
<h1>Plotting aDNA simulated damage with geometric distribution for ADRSM</h1>
</p>
<form id="form">
<label for="eq">Parameter for geometric distribution:</label>
<input type="number" id="param" step="0.01" min="0.01" max="1" value="0.5" />
<label for="eq">Sequence size:</label>
<input type="number" id="seqsize" min="20" max="100" value="30" />
<label for="eq">Max probability:</label>
<input type="number" id="maxproba" step="0.01" min="0.01" max="1" value="0.3" />
<input type="submit" value="Draw" />
</form>
<div id="plot"></div>
<script>
function draw() {
try {
// compile the expression once
const param = document.getElementById('param').value
const seqsize = document.getElementById('seqsize').value
const maxproba = document.getElementById('maxproba').value
// evaluate the expression repeatedly for different values of x
const xValues = math.range(1, seqsize, 1).toArray()
const yValues = xValues.map(function (x) {
res = ((1 - param) ** (x - 1)) * param
return (res)
})
themin = math.min(yValues)
themax = math.max(yValues)
minproba = 0
const nValues = yValues.map(function (x) {
res = (x - themin) / (themax - themin) * (maxproba - minproba) + minproba
return (res)
})
// render the plot using plotly
const trace1 = {
x: xValues,
y: nValues,
type: 'scatter'
}
var layout = {
title: 'aDNA simulated damage with geometric distribution for ADRSM',
xaxis: {
title: 'nucleotide position'
},
yaxis: {
title: 'probability',
range: [0, 1]
}
};
const data = [trace1]
Plotly.newPlot('plot', data, layout)
}
catch (err) {
console.error(err)
alert(err)
}
}
document.getElementById('form').onsubmit = function (event) {
event.preventDefault()
draw()
}
draw()
</script>
</body>
</html>