--- /dev/null
+<!DOCTYPE html>
+<html>
+<head>
+<title>Heat Chart</title>
+</head>
+<body>
+<?php
+
+$input = "";
+if (!isset($_POST["geneIDs"])) {
+echo "Heatmap <br\>";
+$input = trim($_POST["genelist"]);
+}
+else {
+echo "Click on a Species, Cluster, or Cell for more details. <br> Click on a gene name to see which cell it belongs to.";
+$input = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", " ", $_POST["geneIDs"]);
+if(!preg_match("/[a-zA-Z0-9\.]/", substr($input,-1))) {
+ $input = substr_replace($input ,"",-1);
+ }
+}
+exec("java -jar Heatmap.jar " . $input, $output);
+
+//main heatmap data parsing
+$tmp;
+for ($i = 0; $i < sizeof($output); $i ++) {
+ $tmp[$i] = explode(",", $output[$i]);
+ }
+
+
+$allSpecies;
+for ($s = 0; $s < sizeof($tmp) - 2; $s ++) // the last array in tmp is the list of cluster IDs
+ {
+ $allSpecies[$s] = $tmp[$s][0];
+ }
+
+
+$allClusterIDs;
+for ($c = 0; $c < sizeof($tmp[sizeof($tmp) - 2]); $c ++)
+ {
+ $allClusterIDs[$c] = $tmp[sizeof($tmp) - 2][$c];
+ }
+
+
+$heatMapData;
+for ($s = 0; $s < (sizeof($tmp) - 2); $s ++)
+ {
+ for ($c = 0; $c < sizeof($allClusterIDs); $c ++)
+ $heatMapData[$s][$c] = $tmp[$s][$c+1];
+ }
+
+$geneIDs = explode(" ", $input);
+$maxCount = $output[sizeof($output)-1];
+$clusterCount = sizeof($allClusterIDs);
+$speciesCount = sizeof($allSpecies);
+
+$temp;
+for ($i = 0; $i < sizeof($heatMapData); $i ++)
+ {
+ $temp[$i] = implode(",", $heatMapData[$i]);
+ }
+$finalHeatMapData = $temp;
+
+// extra goodies from the mysql database
+$username="inparanoid-read-user";
+$password="inparanoid-read-user_pw";
+$database="inparanoid_data";
+$url="floret.cgrb.oregonstate.edu:3306";
+
+$connection=mysql_connect($url,$username,$password);
+$logic="gene like ";
+for($i=0; $i<sizeof($geneIDs); $i++) {
+ $logic = $logic . "\"" . $geneIDs[$i] . "%\"";
+ if($i+1 < sizeof($geneIDs)) {
+ $logic = $logic . " or gene like ";
+ }
+}
+
+function array_search2d($needle, $haystack) {
+ $ind=0;
+ for ($i=0; $i<sizeof($haystack); $i++) {
+ if ($needle == (string)$haystack[$i]) {
+ $ind = $i;
+ }
+ }
+ return $ind;
+}
+
+//getting the information from SQL in order to create clickable gene IDs below the heatMap
+$query = "select gene, species, super_id from super_clust where " . $logic . " order by species";
+mysql_select_db($database);
+$results=mysql_query($query);
+if(!$results) {
+ echo "<br \> Database error, could not list tables.";
+ }
+
+$clickableGenes;
+$k=0;
+for($row=mysql_fetch_row($results); $row != null; $k++) {
+ $clickableGenes[$k] = ($row[0] . "," . $row[1] . "," . (array_search2d($row[2], $allClusterIDs)+1));
+ $row=mysql_fetch_row($results);
+
+
+
+
+$width = 25*$speciesCount + 100;
+$height = 25 * $clusterCount + 200 + 20 * sizeof($clickableGenes);
+}
+
+?>
+
+
+<br> <br> <br> <br> <br> <br>
+
+
+<body>
+Click on a species name, cluster number, or cell for more information.
+<br> Scroll down to see more clusters, right to see more species (if any exist).
+<br>
+<?php echo "There are " . $clusterCount . " clusters in the heatmap. <br> There are " . $speciesCount . " species in the heatmap."; ?>
+
+<form name="infoForm" action="changes" method="post" >
+<input type="hidden" name="param"/>
+</form>
+
+
+<form name="jumpTo" >
+<input type="submit" value="Jump to Cluster:" onClick="return jumpToCluster()"/>
+<input type="text" name="cluster" />
+</form>
+</body>
+
+<div id="canvasDiv" style="overflow: auto; height: 515px; width: 1100px;" onscroll="drawMap();">
+<canvas id="myCanvas" width="1500" height="1000" style="border:1px solid #c3c3c3;">
+Your browser does not support the canvas element.
+</canvas>
+
+<script type="text/javascript">
+
+var width = <?php echo $width; ?>;
+
+
+var rawHeatMapData = "<?php echo implode(";",$finalHeatMapData); ?>";
+var rareHeatMapData = rawHeatMapData.split(";");
+var heatMapData = new Array(rareHeatMapData.length);
+for(var i=0; i<rareHeatMapData.length; i++) {
+ heatMapData[i] = rareHeatMapData[i].split(",");
+ }
+
+var rawSpecies = "<?php echo implode(",",$allSpecies); ?>";
+var allSpecies = rawSpecies.split(",");
+var speciesCount = allSpecies.length;
+
+var rawClusterIDs = "<?php echo implode(",", $allClusterIDs); ?>";
+var allClusterIDs = rawClusterIDs.split(",");
+var maxCount = <?php echo $maxCount; ?>;
+var clusterCount = <?php echo $clusterCount; ?>;
+
+var rawClickableGenes = "<?php echo implode(";", $clickableGenes); ?>";
+var rareClickableGenes = rawClickableGenes.split(";");
+var clickableGenes = new Array(rareClickableGenes.length);
+for(var i=0; i<rareClickableGenes.length; i++) {
+ clickableGenes[i] = rareClickableGenes[i].split(",");
+}
+var canvas = document.getElementById("myCanvas");
+var heatMap = canvas.getContext("2d");
+
+var drawnRows = 0; // NOTE starts from the edge of the screen, not 0,0 cell
+var drawnCols = 0; // NOTE starts from the edge of the screen, not 0,0 cell
+
+
+
+var scrolledLeft = 0;
+var scrolledTop = 0;
+
+var lastColor;
+var lastX;
+var lastY;
+
+var cellSize = 25; // NOTE don't make this less than 10. The font won't fit.
+var borderWidth = 2;
+
+var leftScrollOffset = 25;
+var topScrollOffset = 50;
+
+var leftOffset = 25+leftScrollOffset;
+var topOffset = 200 + topScrollOffset;
+
+var maxRows = Math.floor((500-(topOffset - topScrollOffset))/cellSize);
+var maxCols = Math.floor((1000-(leftOffset-leftScrollOffset))/cellSize);
+
+function drawSpecies(startSpecies) {
+ //black for text
+ heatMap.fillStyle = "#000000";
+
+ //rotating the canvas for labeling the species
+ heatMap.rotate(-90*Math.PI/180);
+ heatMap.translate(-topOffset,0);
+
+ //labeling the species
+ var translated = 0;
+ for (var s=startSpecies; (s<speciesCount) && (s<=startSpecies+maxCols); s++) {
+ name = allSpecies[s];
+ speciesName = name.replace("_", " ");
+ heatMap.fillText(speciesName,4, leftOffset + 15);
+ heatMap.translate(0,cellSize);
+ translated = translated + cellSize;
+ }
+ //resetting the canvas to start position
+ heatMap.translate(0,-translated);
+ heatMap.translate(topOffset,0);
+ heatMap.rotate(90*Math.PI/180);
+}
+
+function drawClusters(startCluster) {
+ heatMap.fillStyle = "#000000";
+ for(var c=startCluster; (c<clusterCount) && (c<=startCluster + maxRows); c++) {
+ heatMap.fillText((c+1),(leftOffset-leftScrollOffset)+5,(c-startCluster)*cellSize + topOffset + cellSize/2);
+ }
+}
+
+function drawMap(init) {
+ scrolledLeft = scrolledLeft + document.getElementById("canvasDiv").scrollLeft - leftScrollOffset;
+ scrolledTop = scrolledTop + document.getElementById("canvasDiv").scrollTop - topScrollOffset; // NOTE the 25 accounts for the scrollbar offset allowing for scrolling up/left
+ if(scrolledLeft > speciesCount*cellSize - maxCols*cellSize) {
+ scrolledLeft = speciesCount*cellSize - maxCols*cellSize;
+ }
+ if(scrolledTop > clusterCount*cellSize - maxRows*cellSize) {
+ scrolledTop = clusterCount*cellSize - maxRows*cellSize;
+ }
+ if(scrolledLeft < 0) {
+ scrolledLeft = 0;
+ }
+ if(scrolledTop < 0) {
+ scrolledTop = 0;
+ }
+
+ document.getElementById("canvasDiv").scrollTop = topScrollOffset;
+ document.getElementById("canvasDiv").scrollLeft = leftScrollOffset;
+
+ if((init || Math.floor(scrolledLeft/cellSize) != drawnCols || Math.floor(scrolledTop/cellSize) != drawnRows)) {
+ drawnCols = Math.floor(scrolledLeft/cellSize);
+ drawnRows = Math.floor(scrolledTop/cellSize);
+
+ heatMap.fillStyle = "#FFFFFF";
+ heatMap.fillRect(0,0,1500,topOffset);
+ heatMap.fillRect(0,0,leftOffset,1000);
+ heatMap.fillRect(1029,0,1100,500);
+// heatMap.fillRect(maxCols*cellSize+leftOffset,0,1500-(maxCols*cellSize+leftOffset),1000);
+// heatMap.fillRect(0,maxRows*cellSize+topOffset,1500,1000-(maxRows*cellSize+topOffset));
+ startXCell = Math.floor(scrolledLeft/cellSize);
+ startYCell = Math.floor(scrolledTop/cellSize);
+ for(var s=startXCell; (s<heatMapData.length) && ((s-startXCell)<maxCols); s++) {
+ for(var c=startYCell; (c<clusterCount) && ((c-startYCell)<maxRows); c++) {
+ var count = parseInt(heatMapData[s][c]);
+ var redcolor = "00";
+ var bluecolor = "00";
+ var greencolor = "00";
+ if(count == 0) {
+ redcolor = "5C";
+ greencolor = "5C";
+ bluecolor = "5C";
+ }
+ else if(count == 1) {
+ redcolor = "CF";
+ greencolor = "B5";
+ bluecolor = "2B";
+ }
+ else if(count == 2) {
+ if(maxCount == 2) {
+ redcolor = "FF";
+ bluecolor = "00";
+ }
+ else {
+ redcolor = "00";
+ bluecolor = "FF";
+ }
+ }
+ else {
+ count = count - 2;
+ var redfrequency = Math.floor((count / (maxCount-2)) * 255);
+ redcolor = redfrequency.toString(16);
+ var bluefrequency = 255 - redfrequency;
+ bluecolor = bluefrequency.toString(16);
+
+ }
+ if(redcolor.length < 2) {
+ redcolor = "0" + redcolor;
+ }
+ if(bluecolor.length < 2) {
+ bluecolor = "0" + bluecolor;
+ }
+ var xCoord = leftOffset+(s-startXCell)*cellSize;
+ var yCoord = topOffset+(c-startYCell)*cellSize;
+ heatMap.fillStyle= "#" + redcolor + greencolor + bluecolor;
+ heatMap.fillRect(xCoord, yCoord, cellSize, cellSize);
+ heatMap.fillStyle= "#FFFFFF";
+ heatMap.strokeRect(xCoord-borderWidth/2, yCoord-borderWidth/2,cellSize,cellSize);
+ }
+ }
+ drawClusters(startYCell);
+ drawSpecies(startXCell);
+ drawKey();
+ }
+}
+
+function drawKey() {
+ //drawing the key
+ //0
+ heatMap.fillStyle="#5C5C5C";
+ heatMap.fillRect(1030,(topOffset-topScrollOffset),cellSize,cellSize);
+ heatMap.fillStyle="#000000";
+ heatMap.fillText("= 0",1060,13 + (topOffset-topScrollOffset));
+ heatMap.strokeRect(1030-borderWidth/2,(topOffset-topScrollOffset)-borderWidth/2,cellSize,cellSize);
+
+ //1
+ heatMap.fillStyle="#CFB52B";
+ heatMap.fillRect(1030,cellSize+5+(topOffset-topScrollOffset),cellSize,cellSize);
+ heatMap.fillStyle="#000000";
+ heatMap.fillText("= 1",1060,5+(3/2)*cellSize + (topOffset-topScrollOffset));
+ heatMap.strokeRect(1030-borderWidth/2,(topOffset-topScrollOffset) + 5+cellSize - borderWidth/2,cellSize,cellSize);
+
+ //2
+ if(maxCount == 2) {
+ heatMap.fillStyle="#FF0000";
+ }
+ else {
+ heatMap.fillStyle="#0000FF";
+ }
+ heatMap.fillRect(1030,2*(cellSize+5)+(topOffset-topScrollOffset),cellSize,cellSize);
+ heatMap.fillStyle="#000000";
+ heatMap.fillText("= 2",1060,10+(5/2)*cellSize+(topOffset-topScrollOffset));
+ heatMap.strokeRect(1030-borderWidth/2,(topOffset-topScrollOffset)+2*(cellSize+5)-borderWidth/2,cellSize,cellSize);
+
+ //3+
+ var i=7;
+ if(maxCount<6) {
+ i=maxCount+1;
+ }
+
+ for(var k=3; k < i; k++) {
+ var refPoint = Math.floor((k-2) * 255/(i-3));
+ var redcolor=refPoint.toString(16);
+ if(redcolor.length < 2) {
+ redcolor = "0" + redcolor;
+ }
+ var bluefrequency =255-refPoint;
+ var bluecolor=bluefrequency.toString(16);
+ if(bluecolor < 2) {
+ bluecolor = "0" + bluecolor;
+ }
+ heatMap.fillStyle="#" + redcolor + "00" + bluecolor;
+ heatMap.fillRect(1030, 5+cellSize+(k-1)*(cellSize+5) + (topOffset-topScrollOffset),cellSize,cellSize);
+ heatMap.fillStyle="#000000";
+ var key = Math.floor((k-2)*((maxCount-2)/2) + 2);
+ // var key = Math.floor((k+1)*(maxCount-2)/i);
+ var txt = "= " + key;
+ heatMap.fillText(txt,1060,5+(3/2*cellSize)+(k-1)*(cellSize+5) + (topOffset-topScrollOffset));
+ heatMap.strokeRect(1030-borderWidth/2, 5+cellSize+(k-1)*(cellSize+5) + (topOffset-topScrollOffset) - borderWidth/2,cellSize,cellSize);
+ }
+
+}
+
+alert(maxCount);
+
+
+// drawing the clickable genes
+// for(var i=0; i<clickableGenes.length; i++) {
+// rawspecies = clickableGenes[i][1];
+// species = rawspecies.replace("_", " ");
+// var txt = clickableGenes[i][0] + " from " + species + " in cluster " + clickableGenes[i][2];
+// heatMap.fillText(txt, 25, i*20 + 215 + 25 * clusterCount);
+// }
+
+
+function showInfo(event) {
+ var x = event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft - canvas.offsetLeft;
+ var y = event.clientY + document.body.scrollTop + document.documentElement.scrollTop - canvas.offsetTop;
+
+ if((x<leftOffset-leftScrollOffset) && (y>topOffset-topScrollOffset) && ((y+scrolledTop)<(topOffset + cellSize*clusterCount))) {
+ var index = Math.floor(((y+topScrollOffset)-topOffset)/cellSize) + Math.floor(scrolledTop/25);
+ var cluster = allClusterIDs[index];
+ getClusterInfo(cluster);
+ alert(index);
+ }
+ if((y<topOffset-topScrollOffset) && (x>leftOffset-leftScrollOffset)) {
+ var index = Math.floor(((x+leftScrollOffset)-leftOffset)/cellSize) + Math.floor(scrolledLeft/25);
+ var species = allSpecies[index];
+ getSpeciesInfo(species);
+ }
+ if((y>topOffset-topScrollOffset) && ((y+scrolledTop)<(topOffset + cellSize*clusterCount)) && (x>leftOffset-leftScrollOffset) && ((x+scrolledLeft)<leftOffset + speciesCount*cellSize)) {
+ var clusterIndex = Math.floor(((y+topScrollOffset)-topOffset)/cellSize) + Math.floor(scrolledTop/25);
+ var cluster = allClusterIDs[clusterIndex];
+ var index = Math.floor(((x+leftScrollOffset)-leftOffset)/cellSize) + Math.floor(scrolledLeft/25);
+ var species = allSpecies[index];
+ getBoxInfo(cluster, species, clusterIndex+1);
+ }
+ if(((y+scrolledTop)>(topOffset + cellSize*clusterCount))) {
+ var index = Math.floor((y+topScrollOffset-topOffset+cellSize*clusterCount)/cellSize)+Math.floor(scrolledTop/25);
+ var xVal = 0;
+ var yVal = 0;
+ var species = clickableGenes[index][1];
+ var cluster = clickableGenes[index][2] - 1;
+ yVal = scrolledTop + topOffset + cluster*cellSize;
+ for(var i=0; i < allSpecies.length; i++) {
+ if(allSpecies[i] == species) {
+ xVal = scrolledLeft + leftOffset + i*cellSize;
+ }
+ }
+ heatMap.strokeStyle = "#22FF99";
+ heatMap.strokeRect(xVal+borderWidth/2,yVal+borderWidth/2, cellSize-2*borderWidth, cellSize-2*borderWidth);
+ heatMap.strokeRect(xVal+borderWidth,yVal+borderWidth, cellSize-3*borderWidth, cellSize-3*borderWidth);
+ var xCoord = leftOffset+lastX*cellSize;
+ var yCoord = topOffset+lastY*cellSize;
+ heatMap.fillStyle = lastColor;
+ heatMap.fillRect(xCoord, yCoord, cellSize-borderWidth, cellSize-borderWidth);
+ if(lastX == ((xVal+scrolledLeft)-leftOffset)/cellSize) {
+ //TODO find out if this if statement can just be {}, or if i need to actually draw the rectangle
+ heatMap.strokeStyle = "#22FF99";
+ heatMap.strokeRect(xVal+borderWidth/2,yVal+borderWidth/2, cellSize-2*borderWidth, cellSize-2*borderWidth);
+ heatMap.strokeRect(xVal+borderWidth,yVal+borderWidth, cellSize-3*borderWidth, cellSize-3*borderWidth);
+ } else {
+ lastX = ((xVal+scrolledLeft)-leftOffset)/cellSize;
+ lastY = cluster;
+ }
+ var count = parseInt(heatMapData[lastX][lastY]);
+ var redcolor = "00";
+ var bluecolor = "00";
+ var greencolor = "00";
+ if(count == 0) {
+ redcolor = "5C";
+ greencolor = "5C";
+ bluecolor = "5C";
+ }
+ else if(count == 1) {
+ redcolor = "CF";
+ greencolor = "B5";
+ bluecolor = "2B";
+ }
+ else {
+ count = count - 2;
+ var redfrequency = Math.floor((count / (maxCount-2)) * 255);
+ redcolor = redfrequency.toString(16);
+ var bluefrequency = 255 - redfrequency;
+ bluecolor = bluefrequency.toString(16);
+ if(redcolor == "0") {
+ redcolor = "00";
+ }
+ if(bluecolor == "0") {
+ bluecolor = "00";
+ }
+ }
+ lastColor = "#" + redcolor + greencolor + bluecolor;
+ }
+}
+
+
+function getClusterInfo(cluster) {
+ document.infoForm.action = "ClusterInfo.php";
+ document.infoForm.param.value = cluster;
+ document.infoForm.submit();
+ }
+
+
+function getSpeciesInfo(species) {
+ document.infoForm.action = "SpeciesInfo.php";
+ var pass = [species]
+ pass = pass.concat(allClusterIDs);
+ document.infoForm.param.value = (pass);
+ document.infoForm.submit();
+ }
+
+function getBoxInfo(cluster, species, userIndex) {
+ document.infoForm.action = "ClusterSpeciesInfo.php";
+ document.infoForm.param.value = cluster + "," + species + "," + userIndex;
+ document.infoForm.submit();
+ }
+
+function jumpToCluster() {
+ var cluster = document.jumpTo.cluster.value;
+ scrolledTop = (cluster-1)*25;
+ drawMap(false);
+ return false;
+}
+
+drawMap(true);
+
+canvas.addEventListener('mouseup', showInfo, false);
+
+</script>
+</body>
+</html>
+
+
+<!--
+10. Linkability from clickable genes?
+13. Update user instructions on use
+14. Jump-to-cluster Box
+
+CHECK 1. Scrolling up/left
+CHECK 2. Stop scrolling past the end
+CHECK 3. Fix so that you can see the key
+CHECK 4. Draw 7 ref points on key, not 5
+CHECK 5. Fix clickability
+CHECK 6. Resizable boxes
+CHECK 7. Make hardcoded numbers into variables
+CHECK 8. Fix heatmap initialization
+CHECK 9. Fix text size/positioning for resizable boxes
+CHECK 11. Fix weird row at the bottom of the heatmap that isn't rendering
+CHECK 12. Fix upwards scroll speed
+
+-->
\ No newline at end of file
--- /dev/null
+<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
+<?php
+//read all post parameters
+ if ($_POST) {
+ $spec1 = $_POST['spec1'];
+ $spec2 = $_POST['spec2'];
+ if (isset($_POST['pair'])) {$pair = $_POST['pair'];}
+ if (isset($_POST['super'])) {$super = $_POST['super'];}
+ //when a file is uploaded
+ if (isset($_POST['genelist'])) {
+ $genelist=$_POST['genelist'];
+ //create an array from the gene ids from the uploaded file
+ $geneArray=explode(",",$genelist);
+ echo "<h2 style='text-align:center'><br>File uploaded successfully! Now proceed to choose other options</h2><br><br>";
+ }
+ //when the user enters gene ids into the textarea
+ else if (isset($_POST['gene'])) {
+ $gene = $_POST['gene'];
+ $geneArray=explode("\n",$gene);
+ $count = count($geneArray);
+ if($count > 0 && trim($geneArray[$count-1]) == ""){
+ unset($geneArray[$count -1]);
+ }
+ }
+ }
+ //db Config values
+ $dbHost = "floret.cgrb.oregonstate.local";
+ $dbUser = "planteome_php";
+ $dbPwd = "planteome_php-pw";
+
+ //global variables to hold the list of species values. This is passed to download.php for downloading protein sequence in fasta format
+ $specieslist="";
+ $geneids="";
+
+ //global variables to hold the list of results. This is passed to download.php for downloading the results as a text file.
+ $pairSearchResult = "";
+ $superClusterSearchResult = "";
+
+ $showFastaDownloadLink = true;
+ $showDataDownloadLink = true;
+ $sep="~";
+
+ //function that fetches all results from the db
+ function mysql_fetch_all($query, $conn) {
+ $result = mysql_query($query, $conn);
+ if (!$result) {
+ echo "DB Error, could not find cluster id<br>";
+ echo "MySQL Error: " . mysql_error() . "<br>";
+ }
+ $rows = array();
+ while($row = mysql_fetch_assoc($result)) {
+ $rows[] = $row;
+ }
+ return $rows;
+ }
+
+ //function that builds query from the geneArray
+ function buildQueryFromGeneArray($query,$geneArray){
+ for($i=0;$i<=count($geneArray)-1;){
+ if(trim($geneArray[$i]) != ""){
+ $query = $query . " gene LIKE '%".trim($geneArray[$i])."%'";
+ }
+ $i++;
+ if($i!=count($geneArray) && trim($geneArray[$i]) != ""){
+ $query = $query. " OR ";
+ }
+ }
+ return $query;
+ }
+?>
+<!-- html for file upload section -->
+<p>Upload a .txt file containing the list of gene ids. Make sure the file contains only one gene id per line</p>
+<form style="width:385px;margin-bottom:17px;" action="/php/upload.php" enctype="multipart/form-data" method="POST" onsubmit="if(document.getElementsByName('genelistFile')[0].value == ''){alert('Choose a file first');return false;}">
+ <input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
+ <input name="genelistFile" type="file" />
+ <input type="submit" value="Upload file" />
+</form>
+<b>or</b>
+<p>Enter gene id(s) in the textarea below. Make sure you enter only one gene id per line.</p>
+<form method='post'>
+ <table border=1 align='CENTER'>
+ <!-- the following piece of code is in a single line to avoid additional new line characters introduced into the textarea.
+ The php code loops through the genelist which is an array containing as gene ids from the file upload -->
+ <textarea cols="30" rows="10" name="gene"><?php if(isset($genelist) || isset($gene)){foreach($geneArray as $geneVal){print stripslashes($geneVal)."\n";}}?></textarea>
+ <tr>
+ <td>Species 1:</td>
+ <td>
+ <?php
+ //list box for species 1
+ $connection = mysql_connect($dbHost,$dbUser,$dbPwd);
+ $query = "show tables from protein_sequences";
+ $rsrcResult = mysql_query($query);
+ if (!$rsrcResult) {
+ echo "DB Error, could not list tables\n";
+ echo 'MySQL Error: ' . mysql_error();
+ }
+ echo "<select name='spec1'>";
+ while($arrayRow = mysql_fetch_row($rsrcResult)) {
+ if (isset($spec1)&&$spec1==$arrayRow[0]) {
+ echo "<option selected>{$arrayRow[0]}</option>";
+ }else{
+ echo "<option>{$arrayRow[0]}</option>";
+ }
+ //echo "$rsrcResult";
+ //echo "Table: {$arrayRow[0]}\n";
+ }
+ echo "</select>";
+ ?>
+ </td>
+ </tr>
+ <tr>
+ <td>Species 2:</td>
+ <td>
+ <?php
+ //list box for species 2
+ $connection = mysql_connect($dbHost,$dbUser,$dbPwd);
+ $query = "show tables from protein_sequences";
+ $rsrcResult = mysql_query($query);
+ if (!$rsrcResult) {
+ echo "DB Error, could not list tables\n";
+ echo 'MySQL Error: ' . mysql_error();
+ }
+ echo "<select name='spec2'>";
+ while($arrayRow = mysql_fetch_row($rsrcResult)) {
+ if (isset($spec2)&&$spec2==$arrayRow[0]) {
+ echo "<option selected>{$arrayRow[0]}</option>";
+ }else{
+ echo "<option>{$arrayRow[0]}</option>";
+ }
+ //echo "$rsrcResult";
+ //echo "Table: {$arrayRow[0]}\n";
+ }
+ echo "</select>";
+ ?>
+ </td>
+ </tr>
+
+ <tr>
+ <td></td>
+ <td align='CENTER'>
+ <input type='submit' name="pair" value='Search species-species' onclick="if(document.getElementsByName('spec1')[0].value == document.getElementsByName('spec2')[0].value){alert('Choose different species');return false;}">
+ </td>
+ </tr>
+ <tr>
+ <td></td>
+ <td align='CENTER'>
+ <input type='submit' name="super" value='Search across all species'>
+ </td>
+</tr>
+ </table>
+</form>
+
+<br>
+<br>
+
+<?php
+ if(isset($pair)) {
+ if($spec1 == $spec2) {
+ echo "choose different gene ids";
+ }
+ else{
+ $species = array("$spec1", "$spec2");
+ sort($species);
+ $connection = mysql_connect($dbHost,$dbUser,$dbPwd);
+ mysql_select_db("inparanoid_data_eucalyptus");
+ $table = "$species[0]" . "_" . "$species[1]";
+ if(isset($geneArray)){
+ $query1 = "select id from $table where ";
+ $query1 = buildQueryFromGeneArray($query1,$geneArray);
+ }
+ $rowArray = mysql_fetch_all($query1,$connection);
+ for($i=0;$i<=count($rowArray)-1;$i++){
+ $row = $rowArray[$i];
+ $clust_id = $row["id"];
+ $query2 = "select * from $table where id = '$clust_id'";
+ $query2Result = mysql_query($query2);
+ if (!$query2Result) {
+ echo "DB Error, could not find cluster<br>";
+ echo "MySQL Error: " . mysql_error(). "<br>";
+ }
+ $num = mysql_num_rows($query2Result);
+ if($num > 0) {
+ if($showFastaDownloadLink){
+ echo "<a id='ptf' style='color:#5895BE;cursor:pointer;'>Click here to download all results as a <b>FASTA</b> file</a><br>";
+ //this link has to be shown only one. so set the variable $showFastaDownloadLink to false after first time;
+ $showFastaDownloadLink = false;
+ }
+ if($showDataDownloadLink){
+ echo "<a id='ptt' style='color:#5895BE;cursor:pointer;'>Click here to download all results as a <b>text</b> file</a><br>";
+ //this link has to be shown only one. so set the variable $showDataDownloadLink to false after first time;
+ $showDataDownloadLink = false;
+ }
+ }
+ if($i==0){
+ echo "<table border=1 align='CENTER'>";
+ echo "<tr><td colspan='5' align='CENTER'><b>Results for species-species pair search</b></td></tr>";
+ echo "<tr>";
+ echo "<td>bit score</td><td>species</td><td>orthology score</td><td>gene</td>";
+ echo "</tr>";
+ }
+ $j=0;
+ while ($j <$num) {
+ $bit_score=mysql_result($query2Result,$j,"bit_score");
+ $species=mysql_result($query2Result,$j,"species");
+ $score=mysql_result($query2Result,$j,"score");
+ $gene_return=mysql_result($query2Result,$j,"gene");
+ $gene_return_url="<a href=11?species=$species&gene=$gene_return>$gene_return</a>";
+
+ $specieslist= $specieslist == "" ? $species : $specieslist.','.$species;
+ $geneids = $geneids == "" ? $gene_return : $geneids.','.$gene_return;
+
+ if($score ==1) {$score = '1.00';}
+ echo "<tr>";
+ echo "<td>$bit_score</td><td>".str_replace('_',' ',$species)."</td><td>$score</td><td>$gene_return_url</td>";
+ echo "</tr>";
+ $j++;
+ $res = $clust_id.$sep.$bit_score.$sep.$species.$sep.$score.$sep.$gene_return;
+ if($pairSearchResult != "")
+ $pairSearchResult=$pairSearchResult.",".$res;
+ else
+ $pairSearchResult=$res;
+ }
+ }
+ echo "</table>";
+ mysql_close();
+ }
+}
+
+if(isset($super)) {
+ $connection = mysql_connect($dbHost,$dbUser,$dbPwd);
+ mysql_select_db("inparanoid_data_eucalyptus");
+ if(isset($geneArray)){
+ $query1 = "select super_id from super_clust where ";
+ $query1 = buildQueryFromGeneArray($query1,$geneArray);
+ }
+ $rowArray = mysql_fetch_all($query1,$connection);
+ for($i=0;$i<=count($rowArray)-1;$i++){
+ $row = $rowArray[$i];
+ $super_id = $row["super_id"];
+ $query2 = "select * from super_clust where super_id = '$super_id'";
+ $query2Result = mysql_query($query2);
+ if (!$query2Result) {
+ echo "DB Error, could not find cluster<br>";
+ echo "MySQL Error: " . mysql_error(). "<br>";
+ }
+ $num = mysql_num_rows($query2Result);
+ if($num > 0) {
+ if($showFastaDownloadLink){
+ echo "<a id='ptf' style='color:#5895BE;cursor:pointer;'>Click here to download all results as a <b>FASTA</b> file</a><br>";
+ //this link has to be shown only one. so set the variable $showFastaDownloadLink to false after first time;
+ $showFastaDownloadLink = false;
+ }
+ if($showDataDownloadLink){
+ echo "<a id='ptt' style='color:#5895BE;cursor:pointer;'>Click here to download all results as a <b>text</b> file</a><br>";
+ //this link has to be shown only one. so set the variable $showDataDownloadLink to false after first time;
+ $showDataDownloadLink = false;
+ }
+ }
+ if($i==0){
+ echo "<table border=1 align='CENTER'>";
+ echo "<tr><td colspan='3' align='CENTER'><b>Results from supercluster search</b></td></tr>";
+ echo "<tr>";
+ echo "<td>supercluster id</td><td>species</td><td>gene</td>";
+ echo "</tr>";
+ }
+ $j = 0;
+ while ($j < $num) {
+ $super_id_result=mysql_result($query2Result,$j,"super_id");
+ $species=mysql_result($query2Result,$j,"species");
+ $gene_result=mysql_result($query2Result,$j,"gene");
+ $gene_result_url="<a href=11?species=$species&gene=$gene_result>$gene_result</a>";
+
+ $specieslist= $specieslist == "" ? $species : $specieslist.','.$species;
+ $geneids = $geneids == "" ? $gene_result : $geneids.','.$gene_result;
+
+ echo "<tr>";
+ echo "<td>$super_id_result</td><td>".str_replace('_',' ',$species)."</td><td>$gene_result_url</td>";
+ echo "</tr>";
+ $j++;
+ $res = $super_id_result.$sep.$species.$sep.$gene_result;
+ if($superClusterSearchResult != "")
+ $superClusterSearchResult=$superClusterSearchResult.",".$res;
+ else
+ $superClusterSearchResult=$res;
+ }
+ }
+ echo "</table>";
+ mysql_close();
+}
+ //to be used for downloading protein sequence is fasta format
+ if(isset($geneArray)){
+ $genelist = implode(',', $geneArray);
+ }
+?>
+<iframe id="fFrm" style="height:0px;width:0px;" src="/php/fileForm.html"></iframe>
+<script type="text/javascript">
+$(document).ready(function(){
+ $("#ptf").click(function() {
+ iframeForm = $("#fFrm").contents().find("#form");
+ iframeForm.find('input[name=type]').val("fasta");
+ iframeForm.find('input[name=genelist]').val("<?php echo $geneids ?>");
+ iframeForm.find('input[name=specieslist]').val("<?php echo $specieslist ?>");
+ iframeForm.submit();
+ });
+$("#ptt").click(function() {
+ iframeForm = $("#fFrm").contents().find("#form");
+ iframeForm.find('input[name=type]').val("txt");
+ iframeForm.find('input[name=pairSearchResult]').val("<?php echo $pairSearchResult ?>");
+ iframeForm.find('input[name=superClusterSearchResult]').val("<?php echo $superClusterSearchResult ?>");
+ iframeForm.submit();
+ });
+});
+</script>
+