<html>
<body>
<?php
+//select term_id from gene_product inner join association on association.gene_product_id=gene_product.id where gene_product.full_name='AT1G32960';
+
$genes;
$geneProductIDs = "";
$terms = "";
$connection=mysql_connect($url,$username,$password);
mysql_select_db($database);
-$logic = "where full_name like '";
-for($i = 0; $i < sizeof($genes); $i ++) { // note that the last parameter of $genes is an empty array
+
+//This all gets the list of terms for the x-axis
+$logic = "where gene_product.full_name='";
+for($i = 0; $i < sizeof($genes); $i++) {
$toAdd = $genes[$i] . "'";
if($i + 1 < sizeof($genes)) {
- $toAdd = $toAdd . " or full_name like '";
+ $toAdd = $toAdd . " or gene_product.full_name='";
}
$logic = $logic . $toAdd;
-
}
-$query="select id from gene_product " . $logic . " order by id";
-$results=mysql_query($query);
-
-$i = 0;
-for($row = mysql_fetch_row($results); $row != null; $row = mysql_fetch_row($results)) {
- $geneProductIDs[$i] = $row[0];
- $i++;
- }
-$logic = "where gene_product_id=";
-for($i = 0; $i < sizeof($geneProductIDs); $i++) {
- $toAdd = $geneProductIDs[$i];
- if($i + 1 < sizeof($geneProductIDs)) {
- $toAdd = $toAdd . " or gene_product_id=";
- }
- $logic = $logic . $toAdd;
-}
-
-$query="select term_id from association " . $logic . " order by term_id";
+$query="select distinct name from (select term_id from gene_product left join association on association.gene_product_id=gene_product.id " . $logic . ") as mytable left join term on term_id=term.id order by name";
$results=mysql_query($query);
$i = 0;
for($row = mysql_fetch_row($results); $row != null; $row = mysql_fetch_row($results)) {
- $termIDs[$i] = $row[0];
+ $terms[$i] = $row[0];
$i++;
}
-$logic = "where id='";
-for($i = 0; $i < sizeof($termIDs); $i++) {
- $toAdd = $termIDs[$i] . "'";
- if($i + 1 < sizeof($termIDs)) {
- $toAdd = $toAdd . " or id='";
+//new testing stuff with optimized queries
+
+$logic = "where gene_product.full_name='";
+for($i = 0; $i < sizeof($genes); $i++) {
+ $toAdd = $genes[$i] . "'";
+ if($i + 1 < sizeof($genes)) {
+ $toAdd = $toAdd . " or gene_product.full_name='";
}
$logic = $logic . $toAdd;
}
-$query="select name from term " . $logic . " order by name";
+$query = "select full_name,term_id,name from (select full_name,term_id from gene_product left join association on association.gene_product_id=gene_product.id " . $logic . " order by full_name,term_id) as temp left join term on term.id=term_id order by full_name,name";
$results=mysql_query($query);
-$i = 0;
-for($row = mysql_fetch_row($results); $row != null; $row = mysql_fetch_row($results)) {
- $terms[$i] = $row[0];
- $i++;
- }
-
-
+$t = 0;
+$g = -1;
$cellData;
-//TODO this part needs the most optimization. It's really bad.
-//theoretically this should return a two-dimensional array of booleans, representing whether or not each gene is referenced to each term
-for($i = 0; $i < sizeof($genes); $i++) {
- $query="select id from gene_product where full_name='" . $genes[$i] . "'";
- $results=mysql_query($query);
- $row = mysql_fetch_row($results);
- $productID = $row[0];
-
- $query="select term_id from association where gene_product_id='" . $productID . "'";
- $results=mysql_query($query);
-
- $k = 0;
- $geneTerms;
- for($row = mysql_fetch_row($results); $row != null; $row = mysql_fetch_row($results)) {
- $geneTerms[$k] = $row[0];
- $k++;
- }
- for($j=0;$j<sizeof($termIDs);$j++) {
- $cellData[$i][$j] = 0;
- }
- for($j = 0; $j < sizeof($geneTerms);$j++) {
- for($m = 0; $m<sizeof($termIDs);$m++) {
- if($geneTerms[$j]==$termIDs[$m]) {
- $cellData[$i][$m] = 1;
- }
+
+for($row = mysql_fetch_row($results); $row != null; $row = mysql_fetch_row($results)) {
+ if(($g == -1) || ($genes[$g] != $row[0])) {
+ $g ++;
+ $genes[$g];
+ for($t = 0; $t < sizeof($terms); $t++) {
+ $cellData[$g][$t] = 0;
}
}
+ for($t = 0; $t < sizeof($terms); $t++) {
+ if($row[2] == $terms[$t]) {
+ $cellData[$g][$t] = 1;
+ } //TODO optimize this by using PO ID's instead of the entire term string
+ }
+
}
$finalCellData;
-
?>
<div id="canvasDiv" style="overflow: hidden; float: left; height: 500px; width: 1100px;">
cellData[i] = rareCellData[i].split(",");
}
-var rawGenes = "<?php echo $_POST['param'] ?>";
+var rawGenes = "<?php echo implode(",",$genes) ?>";
var genes = rawGenes.split(",");
var geneCount = genes.length;
startXCell = Math.floor(scrolledLeft/cellSize);
startYCell = Math.floor(scrolledTop/cellSize);
- for(var s=startXCell; (s<termCount) && ((s-startXCell)<maxCols); s++) {
+ for(var t=startXCell; (t<termCount) && ((t-startXCell)<maxCols); t++) {
var changed=true;
- for(var c=startYCell; (c<geneCount) && ((c-startYCell)<maxRows); c++) {
- if(changed && cellData[c][s] != 0) {
+ for(var g=startYCell; (g<geneCount) && ((g-startYCell)<maxRows); g++) {
+ if(changed && cellData[g][t] != 0) {
redcolor = "00";
- var greenfrequency = Math.floor((s / termCount) * 255);
+ var greenfrequency = Math.floor((t / termCount) * 255);
greencolor = greenfrequency.toString(16);
var bluefrequency = 255 - greenfrequency;
bluecolor = bluefrequency.toString(16);
changed=false;
ontMap.fillStyle= "#" + redcolor + greencolor + bluecolor;
}
- if(cellData[c][s] == 0) {
+ if(cellData[g][t] == 0) {
redcolor = "FF";
greencolor = "FF";
bluecolor = "FF";
changed=true;
ontMap.fillStyle= "#" + redcolor + greencolor + bluecolor;
}
- var xCoord = leftOffset+(s-startXCell+.5)*cellSize;
- var yCoord = topOffset+(c-startYCell)*cellSize;
+ var xCoord = leftOffset+(t-startXCell+.5)*cellSize;
+ var yCoord = topOffset+(g-startYCell)*cellSize;
ontMap.fillRect(xCoord, yCoord, cellSize, cellSize);
}
}