Login | Register

Info | Home

BioPHP - Discriminatory Power

Original code submitted by joseba
Code bellow is covered by GNU GPL v2 license.

Description

Last change: 2010/10/18 21:09 | Recent Changes | Original description
Computes discriminatory poweras described by Hunter.

Code

Last change: 2010/10/18 21:09 | Recent Changes | Download | Original code and
<html>
<head>
<title>Discriminatory power Calculator</title>
</head>
<body bgcolor=FFFFFF>
<center>
<h1>Discriminatory Power Calculator</h1>
        <table width=600><tr><td>
        The <a href="<? print $_SERVER["PHP_SELF"]; ?>?show=formula">Discriminatory Power (D)</a>
        is the average probability that the typing system will assign a different type to <b>two
        unrelated strains randomly sampled</b> in the microbial population of a given taxon.
        <p>This tool has been created to help calculate this parameter, and source code is
        available at <a href=http://www.biophp.org/stats/discriminatory_power/>biophp.org</a>
        <hr></td></tr></table>
        <p>
<?php

// author    Joseba Bikandi
// license   GNU GPL v2
// biophp.org

error_reporting(0);

// if formula is requested, show it
if ($_GET["show"]=="formula"){print_formula();die;}

if (!$_POST){
        // when nothing is posted, an example is shown
        // example is included within the form
        print_form("40,30,20,10",100,4,"0.7071");
        // example is explained
        print_example();
}else{
        // when data is posted, discriminatory power is computed
        // get the data
        $values=$_POST["values"];
        $values=preg_replace("/ /","",$values);   // just in case there are spaces

        // parse data to an array
        $data_array=preg_split("/,/",$values,-1,PREG_SPLIT_NO_EMPTY);

        // compute discriminatory power
        $result=discriminatory_power($data_array);

        // print results
        print_form($values,$result["N"],$result["types"],$result["D"]);

}

//######## compute discriminatory power
// input must be an array
function discriminatory_power($data_array) {
        $temp=0;
        $N=0;  // number of strains
        foreach($data_array as $key => $val){
                $temp+=$val*($val-1);
                $N+=$val;
        }
        $result["D"]=round(1-($temp/($N*($N-1))),4);
        $result["N"]=$N;
        $result["types"]=sizeof($data_array);

        return $result;
}

//######## is integral
function str_is_int($str) {
        $var=intval($str);
        return ("$str"=="$var");
}
//########print form
function print_form($values,$N,$S,$result){
?>
        <table width=600>
        <tr><td align=center bgcolor=DDDDFF>
                <form action="<? print $_SERVER["PHP_SELF"]; ?>" method=post>
                  Add number of samples assigned to each type separated by comma: <p>
                  <input type=text name=values value="<? print $values; ?>" size=60><p>
                  <input type=submit value="Calculate Discrimination Power">
                </form>
                <p>
                <table>
                  <tr><td><b>Number of unrelated strains</b>:</td><td align=right><? print $N; ?></td></tr>
                  <tr><td><b>Number of types</b>:</td><td align=right><? print $S; ?></td></tr>
                  <tr><td><b>Discriminatory power</b>:</td><td align=right><? print $result; ?></td></tr>
                </table>
        </td></tr>
        </table>
<?

}

//########print example
function print_example(){
?>
        <table width=600>
        <tr><td>
                <b>Example</b>: a novel typing system was used to type 100 randomly sampled <i>E. coli</i> strains.
                Four types were obtained, and to each type the following number of strains was assigned:
                <p style="margin-left: 40px;">Type A: 40 strains
                <br>Type B: 30 strains
                <br>Type C: 20 strains
                <br>Type D: 10 strains</p>
                <p>With this data, discriminatory power was calculated and its value was 0.7071
        </td></tr>
        </table>
<?
}

// #################### print example
function print_formula(){
?>
        <table width=600>
        <tr><td>
                <b>Reference</b>
                <p>Hunter P. Reproducibility and indices of discriminatory power of microbial typing methods. J Clin Microbiol  1990; 28: 1903-5.
                <a href=http://www.pubmedcentral.gov/articlerender.fcgi?tool=pmcentrez&artid=268075>PubMed</a>.
                <p>A Discriminatory Power (D) value of 1.0 would indicate that a
                typing method was able to distinguish each member of a
                strain population from all other members of that population.
                Conversely, an index of 0.0 would indicate that all members
                of a strain population were of an identical type. An index of
                0.50 would mean that if one strain was chosen at random
                from a strain population, then there would be a 50% probability
                that the next strain chosen at random would be
                indistinguishable from the first.
                <p>
                <div align=right><a href="<? print $_SERVER["PHP_SELF"]; ?>">Start using this tool</a></div>
        </td></tr>
        </table>
<?
}
?>

</center>
</body>
</html>