Hardy Weinberg Calculator
HTML
<h1>Hardy-Weinberg Calculator</h1><br/>
In the field of Genetics the Hardy Weinberg principle (also known as the Hardy Weinberg equilibrium, model, theorem, or law) states that allele and genotype frequencies in a population will remain constant from generation to generation in the absence of other evolutionary influences. More information about this is avaiable at <a href="http://en.wikipedia.org/wiki/Hardy%E2%80%93Weinberg_principle" target="_new">Wikipedia</a>.
<br><br/>
This will calculate Hardy Weinbach population values for expected allele frequency<br/><br/>
Input AA population: <input type="text" id="a" size="5" /><br/>
Input Aa population: <input type="text" id="b" size="5" /><br/>
Input aa population: <input type="text" id="c" size="5" /><br/>
<p id="total"> </p>
<br/><br/>
<input type="button" value="Calculate" id="calculate" />
<br/><br/>
<p id="output"> </p>
JavaScript
function calculateY(a, b, c, x) {
return a * x * x + b * x + c;
}
function calculate() {
var a = Number($('#a').val());
var b = Number($('#b').val());
var c = Number($('#c').val());
var total = a+b+c;
total.innerHtml = "Total: " + total;
var ap = a/total;
var bp = b/total;
var cp = c/total;
var p = ap + 0.5*bp;
var q = cp + 0.5*bp;
var s = "";
s = "Actual AA: " + a + " AA (fraction): " + ap.toFixed(3) + "<br/>";
s+= "Actual Aa: " + b + " Aa (fraction): " + bp.toFixed(3) + "<br/>";
s+= "Actual aa: " + c + " aa (fraction): " + cp.toFixed(3) + "<br/>";
s+="<br/>";
s += "Allele A fraction: " + p.toFixed(3) + "<br/>";
s += "Allele a fraction: " + q.toFixed(3) + "<br/><br/>";
s += "HW AA fraction: " + (p*p).toFixed(3) + "<br/>";
s += "HW Aa fraction: " + (2*p*q).toFixed(3) + "<br/>";
s += "HW aa fraction: " + (q*q).toFixed(3) + "<br/><br/>";
s += "F(ST) = " + ((2*p*q - bp)/(2*p*q)).toFixed(3);
output.innerHTML = s;
}
$('#calculate').click( function() {
calculate();
});