Anonymous avatar Anonymous committed bb49f9f

Final bug fixes and documentation added

Comments (0)

Files changed (4)

 date_default_timezone_set('America/New_York');
 error_reporting(0);
 $username = $_POST['userID'];
+// no need giving a notification that the ID doesn't exist if they haven't entered one yet. I did a calculation and found that there's actually a
+// 7*10E-34% chance that the user ID will be blank. Funny if that were to happen.
 if($username == '') {
 	exit;
 }
 	exit;
 }
 $outDir="temp/" . $username ."/";
+// since the file names are used in the program characters that could possibly run malicious code need to be removed
 	$illegal = array(':', '|','/', '\\', '(', ')', '~', "'", '"', "?", "#", "$", "%", "&", ",", "!", "@", "^", "*", ";", "[", "]", "{", "}", "<",">","+", "-", " ", "=");
 if($_FILES["file1"]["tmp_name"]=='') {
 	$file1 = '';
 	$file7 = $outDir . $name;
 	move_uploaded_file($_FILES["file7"]["tmp_name"], $file7);
 }
-$c = 0;
 $images =  glob($outDir . 'hist/*'); 
+// sort the images so that new plots show up at the bottom
 usort($images, function($a, $b) {
 	return filemtime($b) < filemtime($a);
 });
 $tileFiles = array();
 $n1 = 0;
 $files = glob($outDir . '*');
+// sort the files so that new files show up at the bottom
 usort($files, function($a, $b) {
 	return filemtime($b) < filemtime($a);
 });
+// keep track of the number of files and images so that the canvas can be generated only as big as it's needed
 foreach ($files 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;
 }
 $rowNum = $canvasNum +1;
 $canvasNum *= 80;
+// initializing the table. all of this will be the same regardless of how many files there are (except canvas size)
 echo "<table id='fileManager' width=\"400\" align=\"center\" cellpadding='3' cellspacing='2' style='border: 1px solid #CCCCCC;background-color:#DEEBDC; '>
 		<tr><td><input type='checkbox' id='toggle' checked onchange='Javascript:toggleCheckboxes()'></input></td><td>Toggle Selection</td></tr>
 		<tr><td>&nbsp;</td><td>Filename</td><td>Date uploaded</td><td>Filesize</td><td rowspan=$rowNum><canvas width='300' height='$canvasNum' id='relationsCanvas'></canvas></td></tr>";
+// for every file create a new row and fill it with the information about it
 foreach ($files 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' & substr($allfile1, strlen($username) + 6) != 'logs') {
 		$time = filemtime($allfile1);
 		$class = substr($allfile1, 6 + strlen($username));
+		// gah, more lazy programming where I get rid of the file extension because it messes with the class
 		$classExplode = explode(".", $class);
 		$class = $classExplode[0];
 		echo "<tr style='display: table-row'><td height='70' class='". $class ."'><input id='$allfile1' type='checkbox' class='". $class ."' value=" .  $allfile1. "
 			$c++;
 	}
 }
+// create an option in the history bar for each file in the history folder
 $histScript = '';
 foreach (glob($outDir . 'hist/*') as $allfile1) {
 	$filename = substr($allfile1, strlen($username) + 11);
 	$histScript .= "<option value='$allfile1'>$filename</option>";
 }
 echo "</table>";
+// this parses each file and looks at the first line. if the first line matches a recognized plot type then it adds it to the drop down menu 
+// for that type
 if(empty($heatmapFiles)) {
 	$heatmapScript .= "<option value='' selected='selected'>No files available</option>";
 } else {
 		}
 	}
 }
+// this draws the lines between the plots and the files and displays the rest of the filemanager
 $script ="<script>var colorArray = new Array('rgba(20,83,154, .6)', 'rgba(154,110,9, .6)', 'rgba(29,110,17, .6)', 'rgba(100,20,162, .6)', 'rgba(0,0,0, .6)', 'rgba(100,0,0, .6)', 'rgba(168,168,8, .6)');
 		var c = -1;
 		$('#step2').css('display','table-row');
 		$('#start').css('display', 'inline');
 		$('#deleteFiles').css('display', 'inline');
 		$('#circosForm').css('display', 'block');
+		$('#preID').css('display', 'none');
 	    $(this).ajaxSubmit(optionsinit); 
 		var control = $("#file1");
 		control.val("");
 </table>
 </form></div>
 <div id='generator'>
+<table id='preID'><tr><td align='center'>Looks like you haven't started a session! Starting a session allows you to keep files on the server and use them to create circos plots over and over again. Switch to the File Manager tab and get started!</td></tr></table>
 <form id="circosForm" name="circosForm" method="post" action="rcircos_action.php" enctype="multipart/form-data" style="display: none">
 <table width="800" align="center" cellpadding='3' cellspacing='2' style='border: 1px solid #CCCCCC;background-color:#DEEBDC; '>
   <tr>
 			<INPUT type="Submit" Name=Submit VALUE="Plot Data" id="mySubmit">
           <input type="reset" value="Reset" onclick="Javascript: speciesReset()"/>  <a onclick="Javascript:document.getElementById('circos_div').innerHTML = '<img src=\'images/spinner2-greenie.gif\'   style=\'position:relative; left:0px;\' height=\'30\' width=\'30\' />'; window.setTimeout(function() { document.getElementById('circos_div').innerHTML = '<img src=\'images/example.png\' height=\'800\' width=\'800\' />'}, 15000);">Run Demo</a>  | 
           
-          <a onclick="Javascript: 	var optionsinit = {target: '#seed_div', url: 'fileupload.php',};  $('#idForm').ajaxSubmit(optionsinit);  $('#idForm').css('display', 'inline'); $('#circosForm').css('display', 'none');">Upload Files</a> 
+          <a onclick="Javascript:$('#tabs').tabs('option', 'active', 0);">Upload Files</a> 
           
               </td>
 </tr>

rcircos_action.php

 $Track4File = $_POST['track4'];
 $Track5File = $_POST['track5'];
 $geneFile = $_POST['geneLabel'];
-// Get file types and throw error if they are not supported
+// Get the filetypes so that r can read them correctly. files that aren't txt or csv should've been caught in fileupload so every file
+// should satisfy one of these conditions
 if(substr($linkFile, -3) =="txt") {
 	$linkType = "table";
 } elseif(substr($linkFile, -3) == "csv") {
 	echo "ERROR: data files must be .csv or .txt";
 	exit();
 }
+// by counting how many files are being used we can adjust the size of the circos plot so that it is not needlessly big for only a few tracks
 $files = array($Track1File, $Track2File, $Track3File, $Track4File, $Track5File, $geneFile, $linkFile);
 $filespresent = 0;
 foreach($files as $file) {
 		$filespresent++;
 	}
 }
-
-// TEST TEST TEST TEST TEST
 //echo "<pre>" . print_r($_FILES, true) . "</pre>";
 //echo "<pre>" . print_r($_POST, true) . "</pre>";
 $username = $_POST['username'];
 $missingChrs = array();
 $i = 0;
 $c = 0;
+// easy way to convert the included list which is more inuitive for user input into the exclude list that rcricos needs
 $humanChrList = array( chr1, chr2, chr3, chr4, chr5, chr6, chr7, chr8, chr9, chr10, chr11, chr12, chr13, chr14, chr15, chr16, chr17, chr18, chr19, chr20, chr21, chr22, 'chrX', 'chrY'	);
 foreach ($humanChrList as $value) {
 	if($value != $chrList[$i]) {
 	$c++;
 }
 $fileType = $_POST['fileType'];
-$numExluded = count($missingChrs);
 $width = $_POST['width'];
 $trackHeight = $_POST['trackHeight'];
 $trackHeight = round($trackHeight * 0.1, 5);
 $textSize = $width*.2/3.0;
+// the plot looks super wierd when the size gets really small
 if($width < 3) {
 	echo "WARNING: Sizes less than 3 inches are not recommended";
 }
 $trackType5 = $_POST['trackType5'];
 $fileName = $_POST['plotName'];
 $date = getdate();
+// depending on what number the day of the month is give it 'st' , 'nd' , 'rd' or 'th'
 if($fileName == '') {
 	$fileName = date("M") . "_" . $date["mday"];
 	if($date["mday"] == 01 | $date["mday"] == 21 | $date["mday"] == 31 ) {
 		$fileName =$fileName . "th_" . $date["hours"] ."_".$date["minutes"]. "_" . $date["seconds"];
 	}
 }
+// make sure you aren't overwriting a prexisting file and if you are change the name so it doesn't
 while(is_file("temp/$username/hist/$fileName.png") | is_file("temp/$username/hist/$fileName.pdf") | is_file("temp/$username/hist/$fileName.jpeg")) {
 	$fileName .= "1";
 }
 THERSCRIPT;
 $circosPlot ="temp/" . $username . "/hist/" . $fileName."." .$fileType;
 //echo "<pre>" . print_r($relationsArray, true) . "</pre>";
+// any sessions that haven't been used for 2 or more weeks are deleted here
 foreach (glob("temp/" . '*') as $allfile1) {
 	if ( (time() - filemtime($allfile1)) > 60*60*24*7) unlink($allfile1);
 }
 $isDone = false;
 $c = 0;
+// since the filemanager's rows are generated by having a file in the upload folder these files allow it to display 
+// all the plots if there are more plots than files uploaded
 while($isDone == false) {
 	if(is_file('temp/' . $username . '/zzzzzzz' . $c . ".txt")) {
 		$c++;
 $cmd = "/usr/bin/R --vanilla < " .  $cmd_file . ' 2>&1';
 $changeDir = shell_exec("cd ".$outDir);
 $output = shell_exec($cmd); 
+// creates a log for the r output to make bug tracking easier
 $log = fopen('temp/' . $username .'/logs/'. $fileName . "_log.txt", 'a');
 fwrite($log, $output);
 fclose($log);
+// if an error occured let the user know
 $errorCheck = explode("Error!", $output);
 if(count($errorCheck) > 1) {
 	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>";
 }
+// since pdf's are not images they have to be handled differently from png's or jpeg's
 if($fileType == "pdf") {
 	echo "<script>
 if($('#history1').children().length > 0) {
 $('#modal2').dialog( 'close');
 	</script><img align='center' src='". $circosPlot ."' height='800' width='800' >";
 }
+// this creates the file which relates the plot to the files that were used to create it. Extensions are removed because they interfere with html classes
 $relations = fopen('temp/' . $username ."/relations.txt", 'a');
 $file1 = substr($Track1File, 6 + strlen($username), -4);
 $file2 = substr($Track2File, 6 + strlen($username), -4);
 $file7 = substr($linkFile, 6 + strlen($username), -4);
 $relationstext = "var relArray = new Array('".$fileName."'";
 $c = 1;
+// don't include an empty file name I think the $c is for something I ended up removing but I'm afraid to delete things since I won't have time to test
+// changes right now
 if($file1 != '') {
 	$relationstext .= " ,'$file1'";
 	$c++;
 } $relationstext .= ");~";
 fwrite($relations, $relationstext);
 fclose($relations);
-$email = $_POST['email'];
+$emailInput = $_POST['email'];
+// returns the url of the page so that this works whether it's on localhost, alps, or watson
 function curPageURL() {
 	$pageURL = 'http';
 	if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 	$pageURL = substr($pageURL, 0, -18);
 	return $pageURL;
 }
-if(empty($email) == false) {
-	$emailText = 'Your circos plot is ready to download! Right click the link below and select "save file as" to download it. 
-' . curPageURL() . $circosPlot;
-	mail($email, 'Your Circos Plot is Complete', $emailText);
+// if there are multiple emails provided we simply create an array of them
+$emailArray = explode(",", $emailInput);
+foreach($emailArray as $email) {
+	// eliminate whitespace
+	$email = preg_replace('/\s+/', '', $email);
+	if(empty($email) == false) {
+		$emailText = 'Your circos plot is ready to download! Right click the link below and select "save file as" to download it. ' . curPageURL() . $circosPlot;
+		mail($email, 'Your Circos Plot is Complete', $emailText);
+	}
 }
 ?>
 <?php
 $key = $_POST['key'];
 $found = false;
+// since cookies are stored as a hash of the session ID it is impossible to recreate the session ID from the cookie. The only way to do it
+// is to check if hashes of any the existing session ID's matches the hash in the cookie.
 foreach (glob('temp/' . '*') as $allfile1) {
 	if(md5(substr($allfile1, 5)) == $key) {
 		$found = true;
 		dis = document.getElementById('username');
 		dis.value = token;
 		$('#circosForm').css('display', 'block');
+		$('#preID').css('display', 'none');
 		$(\"#ID\").html(token);
 		$(\"#cookie\").html(\"<button type='button' onclick='Javascript: forgetCookie();'>Forget Cookie</button>\"); </script>";
 	}
 }
 if($found == false) {
-	echo "<script>window.alert('The id provided by your cookie does not match any existing sessions');
+	echo "<script>window.alert('The id provided by your cookie does not match any existing sessions. It may have been deleted if it was unused for more than two weeks.');
 	delete_cookie('rcircostoken');</script>";
 }
 ?>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.