$fastaFile = $myTimestamp . _ .$_FILES["fastaUpload"]["name"]; $treeFile = $myTimestamp . _ .$_FILES["treeUpload"]["name"]; $myFile = "klee_upload/$treeFile"; $fh = fopen($myFile, 'r'); $theData = fread($fh, filesize($myFile)); fclose($fh); //Setup log file $myLogFile = "klee_logs/log_$myTimestamp.txt"; $fhLog = fopen($myLogFile, 'w') or die("can't open file"); fwrite($fhLog, "###########LOG FILE###############\n"); $pattern = '/[A-Z]{3,5}[0-9]{3,4}-[0-9]{2}/'; //IN ORDER TO LOCATE THE INDIVIDUAL FASTA ENTRIES, THE PROGRAM SEARCHES FOR AN //ID PATTERN. THE DEFAULT PATTERN IS 3 TO 5 CAPITAL LETTERS FOLLOWED BY 3 OR //4 NUMBERS FOLLOWED BY A DASH FOLLOWED BY 2 NUMBERS. FOR EXAMPLE, "ABCD456-99" //THIS PATTERN CAN BE CHANGED BY MODIFYING THE $pattern VARIABLE. preg_match_all($pattern, $theData, $matches, 0); $matches2 = $matches[0]; $countMatches = count($matches2); fwrite($fhLog, "###############END PATTERN MATCH############################\n"); $myFile2 = "klee_upload/$fastaFile"; $fh2 = fopen($myFile2, 'r'); $theData2 = fread($fh2, filesize($myFile2)); fwrite($fhLog, "###############END READING THE FILE##########################\n"); $pieces = explode(">", $theData2); //pieces is an array of each chunk of the fasta file. $fastaCounter = 1; foreach ($pieces as $value) { $mystring = substr($value, 0, strpos($value, "|")); //mystring is each code. $full_fasta[] = $mystring; $fastaCodes[$mystring] = $value; //fastaCodes is an array of fasta info with indexes of codes from the fasta file. $fastaCounter++; } array_shift($full_fasta); if($pieces[0] == "") { array_shift($pieces); array_shift($full_fasta); } $countPieces = count($pieces); $countfastaCodes = count($fastaCodes); fwrite($fhLog, "There are $countPieces blocks of text in the fasta file\n"); fclose($fh2); fwrite($fhLog, "###############END EXPLODING THE FILE########################\n"); //SEARCH IF THERE ARE ANY CODES IN THE TREE LIST NOT IN THE FASTA FILE $codeCounter = 0; foreach($matches2 as $currCode) { if($fastaCodes[$currCode] != "") { $analysisArray[] = $fastaCodes[$currCode]; } else { fwrite($fhLog, "ERROR $currCode is NOT in the fasta file\n"); } $codeCounter = $codeCounter+1; } //SEARCH IF THERE ARE ANY CODES IN THE FASTA FILE NOT IN THE TREE LIST foreach($full_fasta as $currFasta) { if (in_array($currFasta, $matches2)) { } else{ fwrite($fhLog, "ERROR $currFasta is NOT in the tree list\n"); } } $countanalysisArray = count($analysisArray); fwrite($fhLog, "The output file contains $countanalysisArray blocks of text\n"); fwrite($fhLog, "###############END GENERATING THE NEW ORDER########################\n"); $myOutFile = "klee_results/result_$myTimestamp.fas"; $fhOut = fopen($myOutFile, 'w') or die("can't open file"); foreach($analysisArray as $analysisVal) { $analysisVal = ">" . $analysisVal; fwrite($fhOut, $analysisVal); } fclose($fhOut); fwrite($fhLog, "###############END WRITING THE NEW FILE########################\n"); $myZipFile = "$myTimestamp.zip"; exec("zip -r klee_zips/$myZipFile $myLogFile $myOutFile"); fclose($fhLog); $ranScript = '1'; } function get_file_extension($file_name) { return substr(strrchr($file_name,'.'),1); }