1. peter_hansen
  2. RCircos

Commits

Peter Hansen  committed 0e38c70

cleaning up some bugs, limiting user ability to break it

  • Participants
  • Parent commits a0d440f
  • Branches master

Comments (0)

Files changed (5)

File fileupload.php

View file
  • Ignore whitespace
 //error_reporting(0);
 $username = $_POST['userID'];
 if(is_dir("temp/" . $username) == false | $username == '') {
-	echo "<script> window.alert(\"ID does not match any sessions\");";
+	echo "<script> window.alert(\"ID does not match any sessions\");
+		$('#start').css('display', 'none');";
 	exit;
 }
 $outDir="temp/" . $username ."/";
 $histogramFiles = array();
 $lineScatFiles = array();
 $tileFiles = array();
+$n1 = 0;
+foreach (glob($outDir . '*') as $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') {
+		$n1 += 1;
+	}
+}
+$n2 = 0;
+foreach (glob($outDir . '/hist/*') as $allfile1) {
+	$n2 += 1;
+}
+if($n1 > $n2) {
+	$canvasNum = $n1;
+} else {
+	$canvasNum = $n2;
+}
+$rowNum = $canvasNum +1;
+$canvasNum *= 80;
 echo "<table id='fileManager' 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><td rowspan=20><canvas width='100' height='300' id='relationsCanvas'></canvas></td></tr>";
+		<tr><td>&nbsp;</td><td>Filename</td><td>Date uploaded</td><td>Filesize (KB)</td><td rowspan=$rowNum><canvas width='300' height='$canvasNum' id='relationsCanvas'></canvas></td></tr>";
 foreach (glob($outDir . '*') as $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. "
+		echo "<tr style='display: table-row'><td height='70' class='". $class ."'><input id='delList[]' type='checkbox' value=" .  $allfile1. "
 				name='delList[]'></input></td>";
 		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></td><td>" . "<a id='$images[$c]' class='$imgClass' href='$images[$c]' target='_blank'><img align='center' src='". $images[$c] ."' height='40' width='40'></a>";
+			if(substr($images[$c], -3) == 'pdf') {
+				echo "<td></td><td><a id='$images[c]' class='$imgClass' href='$images[$c]' target='_blank'>Download</a>";
+			} else {
+				echo "<td></td><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;
 		$linkScript .= "<option value='$file' selected='selected'>$filename</option>";
 	}
 }
-$script ="<script>var colorArray = new Array('#c2374c', '#CC9933', '#0000cc', '#336633', '#000000', '#FF9900', '#999900','#c2374c', '#CC9933', '#0000cc', '#336633', '#000000', '#FF9900', '#999900','#c2374c', '#CC9933', '#0000cc', '#336633', '#000000', '#FF9900', '#999900');
+$script ="<script>var colorArray = new Array('blue', 'orange', 'green', '#336633', '#000000', '#FF9900', '#999900','#c2374c', '#CC9933', '#0000cc', '#336633', '#000000', '#FF9900', '#999900','#c2374c', '#CC9933', '#0000cc', '#336633', '#000000', '#FF9900', '#999900');
 		var c = -1;";
 if (is_file('temp/' . $username . '/relations.txt') == true) {
 	$relations = file_get_contents('temp/' . $username . '/relations.txt');
 				c++;
 				var figPos = $('.' + jq(relArray[0])).offset();
 				var len = relArray.length;
+				var title = relArray[0] + ': ';
 				for (var i= 1; i < len; i++) {
+					if(i !== 1){
+						title = title + ', ';
+					}
+					title = title + relArray[i];
 					var filei = $('#' + jq(relArray[i]));
 					var pos1 = filei.offset();
 					DrawLine(pos1.left + filei.width(), pos1.top + filei.height()/2, figPos.left, figPos.top, colorArray[c]);
 				}
+				$('.' + jq(relArray[0])).prop('title', title);
 				";
 	}
 }

File rcircos.php

View file
  • Ignore whitespace
 		alert("Warning! Track Height cannot be greater than 3!");
 	}
 }
+/* This function ensures that no illegal characters will be included in the
+ * plot name to prevent errors
+ */
+function fixName() {
+	var illegal = new Array('/', '\\', '(', ')', '.', '~', "'", '"', "?", "#", "$", "%", "&", ",", "!", "@", "^", "*", ";", "[", "]", "{", "}", "<",">","+" );
+	var name = $('#plotName').val();
+  	var error = false;
+	for(var i = 0; i<26; i++) {
+		var charExists = (name.indexOf(illegal[i]) >= 0);
+		if(charExists) {
+			error = true;
+			var character = illegal[i];
+			var rnum = name.split(character);
+			var len = rnum.length;
+			name = '';
+			for(var c = 0; c<len; c++) {
+				name += rnum[c];
+			}
+		}
+	}
+	if(error) {
+		$('#plotName').val(name);
+		window.alert('Illegal characters have been removed from the plot name');
+	}
+}
 /* This function creates the pop up windows that the help information shows up in
  * and shifts the focus to the new window.
  */
  * displays the id in the textbox and gives the option to save the id as a cookie
  */
 function startNewSession() { 
+	delete_cookie('rcircostoken');
 	$('#fileManager').css('display', 'none');
 	var chars = "1234567890abcdefghijklmnopqrstuvwxyz";
 	var token = "";
 function histUpdate() {
 	var username = $('#userID').val();
 	var circosPlot = $('#historySelect').val() ;
-	$('#circos_div').html("<img align='center' src='" + circosPlot +"' height='800' width='800' >");
+	if(circosPlot.slice(-3) == 'pdf') {
+		$('#circos_div').html("<a href='" + circosPlot + "'>Download Plot</a>");
+	} else {
+		$('#circos_div').html("<img align='center' src='" + circosPlot +"' height='800' width='800' >");
+	}
 }
 /*
  * Draws a line given start and stop coordinates
 	x2 = x2-posAdjust.left;
 	y2 = y2-posAdjust.top;
 	context.beginPath();
+	context.lineWidth = 5;
 	context.moveTo(x1, y1);
-	context.lineTo(x2, y2);
+	context.quadraticCurveTo(250 , y2 , x2, y2);
     context.strokeStyle = color;
 	context.stroke(); 
 	}
 		<td><input name="userID" type="text" id="userID" onchange="Javascript: $('#username').val($('#userID').val());"><div id="ID"></div></td>
 		<td id="cookie"><button type='button' onclick='Javascript: saveCookie();'>Save as Cookie</button></td>
 	</tr>
-		<!-- 
-	Gene label data upload
-	 -->
-
-<!-- 
-Track 1 data upload
- -->
  			<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>
-	<!-- 
-	Track 2 data upload
-	 -->	
 	 		<tr id="track2row" style="display: none">
 				<td>&nbsp;</td>
 				<td colspan=6 align="center"><input type="file" name="file2" id="file2" onchange="Javascript: dis=document.getElementById('track3row'); dis.style.display='table-row';">
 				<td>&nbsp;</td>
 			</tr>	
-	<!-- 
-	Track 3 data upload
-	 -->
 	 	 	<tr id="track3row" style="display:none">
 				<td>&nbsp;</td>
 				<td colspan=6 align="center"><input type="file" name="file3" id="file3" onchange="Javascript: dis=document.getElementById('track4row'); dis.style.display='table-row';">
 					</div>
 				</td>
 
-				<td>&nbsp;</td>
+				<td><div align="left">
+						<strong>Plot name:</strong>(without file extension)<input name="plotName" type="text" id="plotName" onchange="Javascript: fixName();"><br>
+					</div></td>
+				
 				<td>&nbsp;</td>
 			</tr>
 			<tr> <td colspan="6" align="center">

File rcircos_action.php

View file
  • Ignore whitespace
 $trackType3 = $_POST['trackType3'];
 $trackType4 = $_POST['trackType4'];
 $trackType5 = $_POST['trackType5'];
+$fileName = $_POST['plotName'];
 $date = getdate();
-$fileName = '';
-$fileName .= $date["mon"] . ":" . $date["mday"] . ":" . $date["hours"] .":".$date["minutes"].":" . $date["seconds"]; 
+if($fileName == '') {
+	$fileName = $date["mon"] . ":" . $date["mday"] . ":" . $date["hours"] .":".$date["minutes"].":" . $date["seconds"]; 
+}
+while(is_file("temp/$username/hist/$fileName.png") | is_file("temp/$username/hist/$fileName.pdf") | is_file("temp/$username/hist/$fileName.jpeg")) {
+	$fileName .= "1";
+}
 $R_script =<<<THERSCRIPT
 library(RCircos)
 Species <- '$speciesName';
 	echo "<script>window.alert('Some of your data was unable to be plotted. Check what data is missing in your plot and make sure that the files with that data are formatted correctly and do not go outside chromosome bounds');</script>";
 }
 if($fileType == "pdf") {
-	echo "<a href='". $circosPlot ."'>Download Plot</a>";
+	echo "<script>
+if($('#history').children().length > 0) {
+var html = $('#historySelect').html();
+	html = html + \"<option value='$circosPlot'>$fileName.$fileType</option>\";
+	$('#historySelect').html(html);
+} else {
+	html = \"History:(month:day:hour:minute:second)<select name='historySelect' id='historySelect' onchange='Javascript: histUpdate();'><option value='none'>No option selected</option><option value='$circosPlot'>$fileName.$fileType;</option>\"
+	$('#history').html(html);
+}
+
+$('#historySelect').val('$circosPlot');
+	</script><a href='". $circosPlot ."'>Download Plot</a>";
 } else {
 	echo "	<script>
 if($('#history').children().length > 0) {
 var html = $('#historySelect').html();
-	html = html + \"<option value='$circosPlot'>$fileName.$fileType;</option>\";
+	html = html + \"<option value='$circosPlot'>$fileName.$fileType</option>\";
 	$('#historySelect').html(html);
 } else {
 	html = \"History:(month:day:hour:minute:second)<select name='historySelect' id='historySelect' onchange='Javascript: histUpdate();'><option value='none'>No option selected</option><option value='$circosPlot'>$fileName.$fileType;</option>\"

File rcircos_help.html

View file
  • Ignore whitespace
   <br>
   For gene labels and heatmap plots, the gene/probe names must be provided <br>
   in the fourth column. For other plots, this column could be optional. <br>
-  </p>
+<p><a href="rcircos_workflow.html">Step by step instructions</a></p>
 <p>Test Data: <a href="rcircos_test_data.zip">Download</a></p>
 <a name="geneLabels" id="geneLabels"></a>
 <p><strong>Gene Label Data</strong> <br>

File rcircos_workflow.html

View file
  • Ignore whitespace
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>Instructions</title>
+<link href="rcircos.css" rel="stylesheet" type="text/css" />
+</head>
+<body>
+<br>
+<table align="center"><tr align="left"><td>
+<h2>Step by step instructions</h2>
+<p><br>
+<p><strong>Step 1: Create Your Data</strong><br>Refer to the <a href="rcircos_help.html" target="_blank">formatting</a> page to see references to base your files off of and ensure that files match exactly the format presented <br> in the examples or the program might be unable to recognize how to use it. </p>
+<p><strong>Step 2: Upload Your Data</strong><br>Once you are confident that the data is formatted correctly load the <a href="rcircos.php" target="_blank">main page</a> and click the start new session button. If will <br> generate a filemanager that will handle all the files you upload and create and display the ID you will use to acces this account. <br>
+You now have the choice of either saving the ID as an encrypted cookie in your browser or keeping it stored somewhere else. <br> When you return to the site the ID will automatically be loaded for you, if there is no cookie it will require you to enter the one <br> you recieved when creating the session. Now select the files you want to upload and simply click the upload data button.</p>
+<p><strong>Step 3: Select the Data You Want to Use</strong><br>If your data was formatted correctly it will automattically sort the files out and only give them as options for track types that <br> match their formatting. Under each track type there are links to formatting advice and to download sample data. Once <br> you have selected the data you want and made the specifications necessary simply press start and it will begin making the plot.</p>
+</td></tr></table>
+</body>
+</html>