Commits

Peter Hansen  committed bf87ae5

added better filemanaging and it now shows relations

  • Participants
  • Parent commits f85a88f

Comments (0)

Files changed (4)

File delFiles.php

 //	echo "<pre>" . print_r($delFiles, true) . "</pre>";
 	echo "<script>";
 	foreach($delFiles as $file) {
-		echo "dis = document.getElementById('". $file . "');
-			dis.style.display = 'none';";
+		$classArray = explode("/", $file);
+		$myClass = substr($classArray[2], 0, -4);
+		echo "$(\".$myClass\").html('');";
 		unlink($file);
 	}
 	echo " </script>";

File fileupload.php

 	move_uploaded_file($_FILES["file7"]["tmp_name"], $file7);
 }
 $c = 0;
+$images = array();
+foreach (glob($outDir . 'hist/*') as $allfile1) {
+	$images[$c] = $allfile1;
+	$c++;
+}
+$c = 0;
 $fileConnectArray = array();
 $geneFiles = array();
 $linkFiles = array();
 $histogramFiles = array();
 $lineScatFiles = array();
 $tileFiles = array();
-echo "<table width=\"200\" align=\"center\" cellpadding='3' cellspacing='2' style='border: 1px solid #CCCCCC;background-color:#DEEBDC; '>
-		<tr><td>&nbsp;</td><td>Filename</td><td>Filesize (bytes)</td></tr>";
+$seed = '';
+$d = 0;
+echo "<table width=\"400\" align=\"center\" cellpadding='3' cellspacing='2' style='border: 1px solid #CCCCCC;background-color:#DEEBDC; '>
+		<tr><td>&nbsp;</td><td>Filename</td><td>Date uploaded</td><td>Filesize (KB)</td></tr>";
 foreach (glob($outDir . '*') as $allfile1) {
-	if(substr($allfile1, strlen($username) + 6) != 'hist' ) {
-		echo "<tr id='". $allfile1 ."' style='display: table-row'><td><input id='delList[]' type='checkbox' value=" .  $allfile1. "
+	if(substr($allfile1, strlen($username) + 6) != 'hist' & substr($allfile1, strlen($username) + 6) != 'relations.txt' & substr($allfile1, strlen($username)+6, -6) != 'zzzzzzz' & substr($allfile1, strlen($username)+6, -6) != 'zzzzzz') {
+		$time = filemtime($allfile1);
+		$class = substr($allfile1, 6 + strlen($username), -4);
+		echo "<tr style='display: table-row'><td class='". $class ."'><input id='delList[]' type='checkbox' value=" .  $allfile1. "
 				name='delList[]'></input></td>";
-		echo "<td>" . substr($allfile1, strlen($username) + 6) . "</td>";
-		echo "<td>" . filesize($allfile1) . "</td></tr>";
+		echo "<td class='". $class ."'>" . substr($allfile1, strlen($username) + 6) . "</td>";
+		echo "<td class='". $class ."'>" .date(j, $time). "/". date(n, $time). "/". date(y,$time). "</td>";
+		echo "<td id='".$class."' class='". $class ."'>" . round(filesize($allfile1)/1024, 1) . "</td>";
+//		if (empty($images[$c]) == false) {
+//			$imgClass = substr($images[$c], 11 + strlen($username), -4);
+//			echo "<td>" . "<a id='$images[$c]' class='$imgClass' href='$images[$c]' target='_blank'><img align='center' src='". $images[$c] ."' height='40' width='40'></a>";
+//		}
+		echo "</tr>";
 		$q=FALSE;
 		if('txt' == substr($allfile1, -3)) {
 			$q=TRUE;
 			$linkFiles[$c] = $allfile1;
 		}
 		$c++;
+	} else if (substr($allfile1, strlen($username)+6, -6) == 'zzzzzzz' | substr($allfile1, strlen($username)+6, -6) == 'zzzzzz') {
+		if (empty($images[$d]) == false) {
+			$imgClass = substr($images[$d], 11 + strlen($username), -4);
+			echo "<tr><td></td><td></td><td></td><td></td><td>" . "<a id='$images[$d]' class='$imgClass' href='$images[$d]' target='_blank'><img align='center' src='". $images[$d] ."' height='40' width='40'></a></tr>";
+			$d++;
+		}
 	}
 }
 $histScript = '';
 	$filename = substr($allfile1, strlen($username) + 11);
 	$histScript .= "<option value='$allfile1'>$filename</option>";
 }
-echo "<tr><td colspan = 3 align = \"center\"><button id=\"deleteFiles\" type=\"button\" onclick=\"Javascript: $('#idForm').ajaxSubmit({url:'delFiles.php', type:'post', target: '#delete_div'});\">Delete checked files</button>";
+echo "<tr><td colspan = 8 align = \"center\"><button id=\"deleteFiles\" type=\"button\" onclick=\"Javascript: $('#idForm').ajaxSubmit({url:'delFiles.php', type:'post', target: '#delete_div'});\">Delete checked files</button>";
 echo "</table>";
 if(empty($heatmapFiles)) {
 	$heatmapScript .= "<option value='' selected='selected'>No files available</option>";
-}
-foreach ($heatmapFiles as $file) {
-	$filename = substr($file, strlen($username) + 6);
-	$heatmapScript .= "<option value='$file'>$filename</option>";
+} else {
+	$heatmapScript .= "<option value=''>No file</option>";
+	foreach ($heatmapFiles as $file) {
+		$filename = substr($file, strlen($username) + 6);
+		$heatmapScript .= "<option value='$file' selected='selected'>$filename</option>";
+	}
 }
 if(empty($histogramFiles)) {
 	$histogramScript .= "<option value='' selected='selected'>No files available</option>";
-}
-foreach ($histogramFiles as $file) {
-	$filename = substr($file, strlen($username) + 6);
-	$histogramScript .= "<option value='$file'>$filename</option>";
+} else {
+	$histogramScript .= "<option value=''>No file</option>";
+	foreach ($histogramFiles as $file) {
+		$filename = substr($file, strlen($username) + 6);
+		$histogramScript .= "<option value='$file' selected='selected'>$filename</option>";
+	}
 }
 if(empty($lineScatFiles)) {
 	$lineScatScript .= "<option value='' selected='selected'>No files available</option>";
-}
-foreach ($lineScatFiles as $file) {
-	$filename = substr($file, strlen($username) + 6);
-	$lineScatScript .= "<option value='$file'>$filename</option>";
+} else {
+	$lineScatScript .="<option value=''>No file</option>";
+	foreach ($lineScatFiles as $file) {
+		$filename = substr($file, strlen($username) + 6);
+		$lineScatScript .= "<option value='$file' selected='selected'>$filename</option>";
+	}
 }
 if(empty($tileFiles)) {
 	$tileScript .= "<option value='' selected='selected'>No files available</option>";
-}
-foreach ($tileFiles as $file) {
-	$filename = substr($file, strlen($username) + 6);
-	$tileScript .= "<option value='$file'>$filename</option>";
+} else {
+	$tileScript .= "<option value=''>No file</option>";
+	foreach ($tileFiles as $file) {
+		$filename = substr($file, strlen($username) + 6);
+		$tileScript .= "<option value='$file' selected='selected'>$filename</option>";
+	}
 }
 if(empty($geneFiles)) {
 	$geneScript .= "<option value='' selected='selected'>No files available</option>";
-}
-foreach ($geneFiles as $file) {
-	$filename = substr($file, strlen($username) + 6);
-	$geneScript .= "<option value='$file'>$filename</option>";
+} else {
+	$geneScript .= "<option value=''>No file</option>";
+	foreach ($geneFiles as $file) {
+		$filename = substr($file, strlen($username) + 6);
+		$geneScript .= "<option value='$file' selected='selected'>$filename</option>";
+	}
 }
 if(empty($linkFiles)) {
 	$linkScript .= "<option value='' selected='selected'>No files available</option>";
+} else {
+	$linkScript .= "<option value=''>No file</option>";
+	foreach ($linkFiles as $file) {
+		$filename = substr($file, strlen($username) + 6);
+		$linkScript .= "<option value='$file' selected='selected'>$filename</option>";
+	}
 }
-foreach ($linkFiles as $file) {
-	$filename = substr($file, strlen($username) + 6);
-	$linkScript .= "<option value='$file'>$filename</option>";
+$script ="<script>	delLines();";
+if (is_file('temp/' . $username . '/relations.txt') == true) {
+	$relations = file_get_contents('temp/' . $username . '/relations.txt');
+	$relationsArray=explode("~", $relations);
+	foreach ($relationsArray as $relation) {
+		$script .= $relation;
+		$script .= "
+				var figPos = $('.' + jq(relArray[0])).offset();
+
+				var len = relArray.length;
+				for (var i= 1; i < len; i++) {
+					var pos1 = $('#' + jq(relArray[i])).offset();
+					DrawLine(pos1.left + 12, pos1.top + 12, figPos.left, figPos.top);
+				}
+				window.alert('hi');
+				";
+	}
 }
-$script =
-"<script>
-	var scripts = new Array(\"$heatmapScript\", \"$histogramScript\", \"$lineScatScript\", \"$tileScript\");
+$script .="	var scripts = new Array(\"$heatmapScript\", \"$histogramScript\", \"$lineScatScript\", \"$tileScript\");
 	function start() {
+		delLines();
 		var username = document.getElementById('userID').value;
 		var dis = document.getElementById('circosForm');
 		dis.style.display = 'block';
 		$(\"[name='ph5']\").html(\"<select name='track5' id='track5'>" .$tileScript . "\");
 		$(\"[name='phGene']\").html(\"<select name='geneLabel' id='geneLabel'>" .$geneScript . "\");
 		$(\"[name='phLink']\").html(\"<select name='linkLines' id='linkLines'>" .$linkScript . "\"); ";
-
 	if ($histScript != '') {
-		$script .= "$(\"#history\").html(\"History:(month:day:hour:minute:second)<select name='historySelect' id='historySelect' onchange='Javascript: histUpdate();'><option value='none'>No option selected</option>" .$histScript . "<!-- hue -->\"); ";
+		$script .= "
+		$(\"#history\").html(\"History:(month:day:hour:minute:second)<select name='historySelect' id='historySelect' onchange='Javascript: histUpdate();'><option value='none'>No option selected</option>" .$histScript . "<!-- hue -->\"); ";
 	}
 $script .= "		});
 	}
 function saveCookie() {
 	 var promise = saveCookieAjax();
 	promise.success(function (data) {
-		$('#seed_div').html(data);
+		$('#circos_div').html(data);
 	});
 //	var dis = document.getElementById('userID');
 //	dis.type = "hidden";
 	var circosPlot = $('#historySelect').val() ;
 	$('#circos_div').html("<img align='center' src='" + circosPlot +"' height='800' width='800' >");
 }
+/*
+ * Draws a line given start and stop coordinates
+ */
+ function DrawLine(x1, y1, x2, y2) {
+	    c = $(document.body);
+	    var dx = Math.abs(x2-x1);
+	    var dy = Math.abs(y2-y1);
+	    var d = Math.max(dx, dy);
+	    var i=0;
+	    for(i=0; i < d; i++) {
+	        var img = $(document.createElement('img')).attr('src', 'blank.gif');
+	        var div = $(document.createElement('div')).width(1).height(1).css({'background-color': '#008080', position: 'absolute', left: Math.min(x1,x2)+(i*dx/d), top: Math.min(y1,y2)+(i*dy/d) });
+	        div.append(img);
+	        c.append(div);
+	    }
+	}
+/*
+ * Deletes all the lines
+ */
+function delLines() {
+	while($('body > div:last-child').html() != '<a style="display:none">huehuehue</a>') {
+		$('body > div:last-child').remove();
+	}
+}
+/*
+ * Espaces characters that need to be escaped in a jquery ID selector
+ */
+function jq( myid ) {
+	return myid.replace( /(:|\.|\[|\])/g, "\\$1" );
+}
 </script>
 </head>
 <body>
 </div>
 <div id="user_div" name="user_div" align=center></div>
 <form id ="idForm" name="idForm" method="post" style="display: block">
-<table width="200" align="center" cellpadding='3' cellspacing='2' style='border: 1px solid #CCCCCC;background-color:#DEEBDC; '>
+<table width="600" align="center" cellpadding='3' cellspacing='2' style='border: 1px solid #CCCCCC;background-color:#DEEBDC; '>
   	<tr>
     	<td width="1">&nbsp;</td>
     	<td width="159">&nbsp;</td>
 <!-- 
 Track 1 data upload
  -->
- 			<tr><td>&nbsp;</td><td>&nbsp;</td> <td><div id="seed_div"></div> </td> </tr>
+ 			<tr><td>&nbsp;</td> <td colspan=8><div id="seed_div"></div> </td> </tr>
 			<tr>
 				<td>&nbsp;</td>
 				<td colspan=6 align="center"><input type="file" name="file1" id="file1" onchange="Javascript: dis=document.getElementById('track2row'); dis.style.display='table-row';">
 				<td>&nbsp;</td>
 			</tr>
 			<tr>
-		<td colspan=6 align=center><INPUT type="Submit" Name=Submit VALUE="Upload data" id="mySubmit">
+		<td colspan=6 align=center><INPUT type="Submit" Name=Submit VALUE="Upload data" id="mySubmit"> <input id="showRelations" type="checkbox" value="showRelations"
+										name="showRelations">Show file relations. (this could take a while)</input></td>
+		<tr> <td colspan=6 align=center>
 		<button type='button' id='start' style="display: none">Start</button>
   </td>
 	</tr>
 
 </form>
 <div id='circos_div' align='center'></div>
+<div id='stop_div'><a style="display:none">huehuehue</a></div>
 </body>
 </html>

File rcircos_action.php

 RCircos.Chromosome.Ideogram.Plot();
 linkNumber <- 0;
 c <- 0;
+probe <- F;
 if('$spacing' != '') {
 	if('$geneFile' =='') {
 		c <- c-3
+		probe <- T;
 	}
 	for( i in 1:5) {
 		TrackType <- TrackTypes[i];
 		} 
 	}
 }
-if('$geneFile' == '' & linkNumber == 0 & '$linkFile' != '') {
+if('$geneFile' == '' & linkNumber == 0 & '$linkFile' != '' & probe == F) {
 	if("$linkType" == "table") {
 		link.data <- read.table("$linkFile", sep="\t", quote="", head=T);
 	} else {
 
 dev.off();
 THERSCRIPT;
+$circosPlot ="temp/" . $username . "/hist/" . $fileName."." .$fileType;
+$relations = fopen('temp/' . $username ."/relations.txt", 'a');
+$file1 = substr($Track1File, 6 + strlen($username), -4);
+$file2 = substr($Track2File, 6 + strlen($username), -4);
+$file3 = substr($Track3File, 6 + strlen($username), -4);
+$file4 = substr($Track4File, 6 + strlen($username), -4);
+$file5 = substr($Track5File, 6 + strlen($username), -4);
+$file6 = substr($geneFile, 6 + strlen($username), -4);
+$file7 = substr($linkFile, 6 + strlen($username), -4);
+$relationstext = "var relArray = new Array(); relArray[0]='".$fileName."';";
+$c = 1;
+if($file1 != '') {
+	$relationstext .= "
+relArray[$c]='$file1';";
+	$c++;
+}
+if($file2 !='') {
+	$relationstext .= "
+relArray[$c]='$file2';";
+	$c++;
+}
+if($file3 != '') {
+	$relationstext .= "
+relArray[$c]='$file3';";
+	$c++;
+}
+if($file4 != '') {
+	$relationstext .= "
+relArray[$c]='$file4';";
+	$c++;
+}
+if($file5 != '') {
+	$relationstext .= "
+relArray[$c]='$file5';";
+	$c++;
+}
+if($file6 != '') {
+	$relationstext .= "
+relArray[$c]='$file6';";
+	$c++;
+}
+if($file7 != '') {
+	$relationstext .= "
+relArray[$c]='$file7';";
+} $relationstext .= "~";
+fwrite($relations, $relationstext);
+fclose($relations);
+$contents = file_get_contents('temp/' . $username . '/relations.txt');
+$relationsArray = explode("~", $contents);
+//echo "<pre>" . print_r($relationsArray, true) . "</pre>";
 foreach (glob("temp/" . '*') as $allfile1) {
 	if ( (time() - filemtime($allfile1)) > 60*60*24*7) unlink($allfile1);
 }
+$isDone = false;
+$c = 0;
+while($isDone = false); {
+	if(is_file('temp/' . $username . '/zzzzzzz' . $c . ".txt")) {
+		$c++;
+	} else {
+		fopen('temp/' . $username . '/zzzzzzz' . $c . ".txt", 'w');
+	}
+}
 $cmd_file = "temp/" . $fileName. '_R.cmd';
 $RFileHandle = fopen($cmd_file, "w") or die("Could not open tempfile");
 fwrite($RFileHandle, $R_script);
+fclose($RFileHandle);
 $cmd = "/usr/bin/R --vanilla < " .  $cmd_file ;
 $changeDir = shell_exec("cd ".$outDir);
 $output = shell_exec($cmd);
-$circosPlot ="temp/" . $username . "/hist/" . $fileName."." .$fileType;
 if($fileType == "pdf") {
 	echo "<a href='". $circosPlot ."'>Download Plot</a>";
 } else {
 $('#historySelect').val('$circosPlot');
 	</script><img align='center' src='". $circosPlot ."' height='800' width='800' >";
 }
+
 ?>