Hardy Weignbach Calulcator

by Ron Eaglin

HTML

Hardy-Weinberg Calculator<br/><br>
Calculates Hardy Weinbach 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();  
});