コード例 #1
0
ファイル: evidence.php プロジェクト: jwssb90/get-evidence
function evidence_get_report($snap, $variant_id)
{
    $flag_edited_id = 0;
    if ($snap == "latest" || $snap == "release") {
        $table = "snap_{$snap}";
        $and_max_edit_id = "";
    } else {
        if (ereg("^[0-9]+\$", $snap)) {
            $flag_edited_id = $snap;
            $table = "edits";
            $variant_id = 0 + $variant_id;
            $and_max_edit_id = "AND {$table}.edit_id IN (\n SELECT MAX(edits.edit_id)\n FROM edits\n WHERE variant_id={$variant_id}\n AND edit_id<={$snap}\n AND is_draft=0\n GROUP BY article_pmid, genome_id, disease_id)\n AND ({$table}.edit_id={$snap} OR {$table}.is_delete=0\n )";
        }
    }
    // Get all items relating to the given variant
    $v =& theDb()->getAll("SELECT variants.*, {$table}.*, genomes.*, datasets.*, variant_occurs.*,\n\t\t\tvariants.variant_id AS variant_id,\n\t\t\t{$table}.genome_id AS genome_id,\n\t\t\t{$table}.disease_id AS disease_id,\n\t\t\tgenetests.testable AS genetests_testable,\n\t\t\tgenetests.reviewed AS genetests_reviewed,\n\t\t\tdiseases.disease_name AS disease_name,\n\t\t\tvariant_occurs.chr AS chr,\n\t\t\tvariant_occurs.chr_pos AS chr_pos,\n\t\t\tvariant_occurs.allele AS allele,\n\t\t\tvariant_occurs.rsid AS rsid,\n\t\t\tvf.num AS variant_f_num,\n\t\t\tvf.denom AS variant_f_denom,\n\t\t\tvf.f AS variant_f,\n\t\t\tCOUNT(datasets.dataset_id) AS dataset_count,\n\t\t\tMAX(zygosity) AS zygosity,\n\t\t\tMAX(dataset_url) AS dataset_url,\n\t\t\tMIN(dataset_url) AS dataset_url_2,\n\t\t\t{$table}.edit_id=? AS flag_edited_id\n\t\t\tFROM variants\n\t\t\tLEFT JOIN {$table}\n\t\t\t\tON variants.variant_id = {$table}.variant_id\n\t\t\tLEFT JOIN genetests\n\t\t\t\tON {$table}.disease_id=0\n\t\t\t\tAND {$table}.article_pmid=0\n\t\t\t\tAND {$table}.genome_id=0\n\t\t\t\tAND variants.variant_gene = genetests.gene\n\t\t\tLEFT JOIN diseases\n\t\t\t\tON {$table}.disease_id = diseases.disease_id\n\t\t\tLEFT JOIN genomes\n\t\t\t\tON {$table}.genome_id > 0\n\t\t\t\tAND {$table}.genome_id = genomes.genome_id\n\t\t\tLEFT JOIN datasets\n\t\t\t\tON datasets.genome_id = {$table}.genome_id\n\t\t\tLEFT JOIN variant_occurs\n\t\t\t\tON {$table}.variant_id = variant_occurs.variant_id\n\t\t\t\tAND variant_occurs.dataset_id = datasets.dataset_id\n\t\t\tLEFT JOIN variant_frequency vf\n\t\t\t\tON vf.variant_id=variants.variant_id\n\t\t\tWHERE variants.variant_id=?\n\t\t\t\t{$and_max_edit_id}\n\t\t\tGROUP BY\n\t\t\t\t{$table}.genome_id,\n\t\t\t\t{$table}.article_pmid,\n\t\t\t\t{$table}.disease_id\n\t\t\tORDER BY\n\t\t\t\t{$table}.genome_id,\n\t\t\t\t{$table}.article_pmid,\n\t\t\t\tdiseases.disease_name,\n\t\t\t\t{$table}.disease_id,\n\t\t\t\t{$table}.edit_id DESC", array($flag_edited_id, $variant_id));
    if (theDb()->isError($v)) {
        die($v->getMessage());
    }
    if (!theDb()->isError($v) && $v && $v[0]) {
        foreach (array("article_pmid", "genome_id", "disease_id") as $x) {
            if (!$v[0][$x]) {
                $v[0][$x] = 0;
            }
        }
    }
    // Make sure for every pmid>0 row all of the article=A, disease=D
    // rows are there too (and ditto for article=0, genome=0)
    $have_a_d = array();
    // will contain one array per article
    // id (incl. "0" for the main variant
    // summary section)
    foreach ($v as $row) {
        if (!$row["genome_id"]) {
            $have_a_d[$row["article_pmid"]][$row["disease_id"]] = 1;
        }
    }
    // Get a list of all the diseases that should be listed in each disease table
    $v_d = theDb()->getAll("SELECT diseases.* FROM diseases\n WHERE disease_id IN\n (SELECT disease_id\n  FROM variant_disease\n  WHERE variant_id=?\n UNION\n  SELECT disease_id\n  FROM gene_disease\n WHERE gene = ?)", array($variant_id, $v[0]["variant_gene"]));
    // Look for article=A, disease=D rows that should be there but
    // aren't... and add them
    foreach ($v_d as $row) {
        // for each disease...
        foreach ($have_a_d as $a => $have_d) {
            // for each article...
            $d = $row["disease_id"];
            if (isset($have_d[$d])) {
                // already have a result row for this {article, disease}
                continue;
            }
            // add a row after all of the existing rows pertaining to the
            // target article
            for ($i = 0; $i < sizeof($v); $i++) {
                // skip until we reach the target article's row
                if ($v[$i]["article_pmid"] != $a) {
                    continue;
                }
                // skip until we reach the last row for the target article
                if ($i < sizeof($v) - 1 && $a != 0 && $v[$i + 1]["article_pmid"] == $a) {
                    continue;
                }
                // found the last row for this article.  copy the existing row
                // (minus the editable stuff) and insert after.
                array_splice($v, $i + 1, 0, array($v[$i]));
                $v[$i + 1]["disease_id"] = $row["disease_id"];
                $v[$i + 1]["disease_name"] = $row["disease_name"];
                $v[$i + 1]["summary_short"] = "";
                $v[$i + 1]["summary_long"] = "";
                $v[$i + 1]["talk_text"] = "";
                $v[$i + 1]["edit_id"] = "";
                $v[$i + 1]["previous_edit_id"] = "";
                break;
            }
        }
    }
    if ($v && is_array($v[0])) {
        if (1) {
            // fix up obsolete impacts (until they get fixed in the db, at which
            // point this section can be removed)
            if ($v[0]["variant_impact"] == "unknown" || $v[0]["variant_impact"] == "none") {
                $v[0]["variant_impact"] = "not reviewed";
            }
        }
        $v[0]["certainty"] = evidence_compute_certainty($v[0]["variant_quality"], $v[0]["variant_impact"]);
        $v[0]["qualified_impact"] = evidence_qualify_impact($v[0]["variant_quality"], $v[0]["variant_impact"]);
        list($v[0]["variant_evidence"], $v[0]["clinical_importance"]) = str_split($v[0]["certainty"]);
    }
    if ($v && is_array($v[0])) {
        $row =& $v[0];
        $row["nblosum100"] = 0 - blosum100($row["variant_aa_from"], $row["variant_aa_to"]);
        $tags = array();
        foreach (theDb()->getAll("SELECT distinct tag FROM variant_external WHERE variant_id=?", array($variant_id)) as $tagrow) {
            $tags[] = $tagrow["tag"];
        }
        $row["in_omim"] = in_array("OMIM", $tags) ? 'Y' : '-';
        $row["in_gwas"] = in_array("GWAS", $tags) ? 'Y' : '-';
        $row["in_pharmgkb"] = in_array("PharmGKB", $tags) ? 'Y' : '-';
        $autoscore = 0;
        $why = array();
        // Computational (max of 2 points):
        if ($row["nblosum100"] > 9) {
            $autoscore += 2;
            $why[] = "nblosum100>9";
        } else {
            if ($row["nblosum100"] > 3) {
                $autoscore++;
                $why[] = "nblosum100>3";
            }
        }
        // TODO: ++$autoscore if within 1 base of a splice site
        // TODO: ++$autoscore if indel in coding region
        // TODO: ++$autoscore if indel in coding region and causes frameshift
        if ($autoscore > 2) {
            $autoscore = 2;
        }
        // Variant-specific lists (max of 2 points):
        $autoscore_db = 0;
        if ($row["in_omim"] == 'Y') {
            $autoscore_db += 2;
            $why[] = "omim";
        }
        if ($row["in_gwas"] == 'Y') {
            $autoscore_db++;
            $why[] = "gwas";
            if ($row["gwas_max_or"] >= 1.5) {
                $autoscore_db++;
                $why[] = "gwas_or";
            }
        }
        if ($row["in_pharmgkb"] == 'Y') {
            ++$autoscore_db;
            $why[] = "PharmGKB";
        }
        if ($autoscore_db > 2) {
            $autoscore_db = 2;
        }
        $autoscore += $autoscore_db;
        // Gene-specific lists (max of 2 points):
        if ($row["genetests_testable"]) {
            $autoscore++;
            $why[] = "genetest";
        }
        if ($row["genetests_reviewed"]) {
            $autoscore++;
            $why[] = "genereview";
        }
        $row["autoscore"] = $autoscore;
        $row["autoscore_flags"] = implode(", ", $why);
        // Summarize relevant/not-relevant votes as one of { null, 0, 1 }
        $row["webscore"] = "N";
        $urlscores =& evidence_get_web_votes($variant_id);
        foreach (evidence_extract_urls(theDb()->getOne("SELECT content FROM variant_external WHERE variant_id=? AND tag=?", array($variant_id, "Yahoo!"))) as $url) {
            if ($urlscores[$url] == 1) {
                $row["webscore"] = "Y";
                break;
            }
            if (!strlen($urlscores[$url])) {
                $row["webscore"] = "-";
            }
        }
    }
    return $v;
}
コード例 #2
0
ファイル: index.php プロジェクト: jwssb90/get-evidence
            }
            $html .= "<BR /><SPAN class=\"searchurl\">" . htmlspecialchars($url_abbrev) . "</SPAN>";
        } else {
            $html .= $content;
        }
        $html . "</LI>";
        $lasttag = $r["tag"];
    }
    if ($lasttag !== FALSE) {
        $html .= "</UL>\n";
    }
    $html .= "</DIV>\n";
}
$html .= "<H2>Other <I>in silico</I> analyses<BR />&nbsp;</H2>\n<DIV id=\"in_silico\">\n<UL>\n";
if ($aa) {
    $html .= "<LI>NBLOSUM100 score = <STRONG>" . ereg_replace("-", "&ndash;", 0 - blosum100($row0["variant_aa_from"], $row0["variant_aa_to"])) . "</STRONG></LI>\n";
}
$autoscore_html = $row0["autoscore"];
if ($autoscore_html > 0) {
    $autoscore_html = "<SPAN onmouseover=\"Tip('" . htmlspecialchars($row0["autoscore_flags"]) . "',BALLOON,true,FIX,[this,-18,0],FOLLOWMOUSE,false,ABOVE,true,WIDTH,-400);\" onmouseout=\"UnTip();\">" . $autoscore_html . "</SPAN>";
}
$html .= "<LI>GET-Evidence autoscore = <STRONG>" . $autoscore_html . "</STRONG>";
$html .= "</LI>\n";
$html .= "</UL>\n";
$html .= "</DIV>";
$html .= "<H2>Edit history<BR />&nbsp;</H2>\n<DIV id=\"edit_history\">";
$html .= evidence_render_history($variant_id);
$html .= "</DIV>";
$gOut["content"] .= $html;
// $gOut["content"] .= "<!--\n" . ereg_replace ("-->", "\\-\\-\\>", json_encode ($report)) . "-->\n";
$gOut["content"] .= "<!--\n" . ereg_replace("-->", "\\-\\-\\>", json_encode(evidence_get_assoc_flat_summary("latest", $variant_id))) . "-->\n";