Page MenuHomec4science

getVariants.php
No OneTemporary

File Metadata

Created
Sat, Jul 20, 10:30

getVariants.php

<?php
// query_type define is we are searching by:
// - old is the old version that uses the first version of the schema
// - Gene + Zygosity
// - ...
$query = "";
switch($_GET["query_type"]){
case "gene_and_zygosity":
// case insensitive regex query
// select variant_id
// from shrine_ont.genomic_annotations_new
// where annotations ~* '^CTBP2P1;(Homozygous|Unknown);'
$zigosity = $_GET["zygosity"]; // array of zygosity options, put them in the query separated by | (or)
$query =
"SELECT variant_id " .
"FROM shrine_ont.genomic_annotations_new " .
"WHERE annotations ~* '^" . $_GET["gene_name"] .
";(" . join('|', $zigosity) .");'";
break;
case "variantName_and_zygosity":
// select variant_id
// from shrine_ont.genomic_annotations_new
/* where variant_name='Y:59022489:?>A'*/
$zigosity = $_GET["zygosity"];
$query = "SELECT variant_id " .
"FROM shrine_ont.genomic_annotations_new " .
"WHERE variant_name='" . $_GET["variant_name"] ."' AND " .
"annotations ~* '" . "(" . join('|', $zigosity) .")'";
break;
case "annotation_and_zygosity":
//select variant_id
//from shrine_ont.genomic_annotations_new
//where annotations ~* '(Homozygous|Unknown);.*VARIANT_CLASS=DELETION'
$zigosity = $_GET["zygosity"];
$query = "SELECT variant_id " .
"FROM shrine_ont.genomic_annotations_new " .
"WHERE annotations ~* '" . "(" . join('|', $zigosity) .");.*" . $_GET["annotation_name"] . "=" . $_GET["annotation_value"] . "'";
break;
case "old":
//select variant_id
//from shrine_ont.genomic_annotations
//where variant_annotations ->> 'Start_Position' = '5239176'
$query =
"SELECT variant_id
FROM shrine_ont.genomic_annotations
WHERE variant_annotations ->> '". $_GET["annotation_name"] . "' = '" . $_GET["annotation_value"] ."'";
break;
default:
echo "Error: query type not recognized";
return;
}
include 'sqlConnection.php';
$result = pg_query($conn, $query);
if (!$result) {
echo "An error occurred while querying the database.\n";
exit;
}
// In json format return both the panel number and the list of variants
echo "{ \"panel_number\" :" . $_GET["panel_number"] . ", \"variants\" : ";
$variantList = "";
while ($row = pg_fetch_row($result)) {
$variantList .= "\"$row[0]\",";
}
// drop the last comma
echo "[" . substr($variantList, 0, -1) . "]}";

Event Timeline