1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94:
<?php
namespace DispatchModule\Models;
/**
* BlatModel cooperates with Blat
*
*/
class BlatModel extends \BaseModule\Models\BaseModel {
/**
* Input query file (relative path from "www" folder)
* @var String
*/
private $input;
/**
* Filename for Blat output file
* @var String
*/
private $output;
/**
* Results returned from python encoded by json
* @var Array
*/
private $dumpedResults;
/**
* Results returned from python as a string (still encoded by json)
* @var String
*/
private $stringResults;
/**
* Results returned from python decoded by json
* @var String
*/
private $decodedResults;
/**
* Constructor sets input
*
* @param string $input input file path
* @param string $fileId identifier of the output file
*/
public function __construct($input, $fileId = null) {
$this->input = $input;
// generate output filename
$this->output = TEMP_PATH . "/blatTemp/";
if (isset($fileId) && !empty($fileId)) {
$this->output = $this->output . $fileId;
} else {
$this->output = $this->output . (session_id() ? session_id() : (time() . rand()));
}
$this->output = $this->output . ".output.pslx";
}
/**
* Executing query saved in the blatTemp directory
*
* @param integer $minMatch Minimal (percentage) match with query
* @param integer $minCoverage Minimal (percentage) coverage of query
* @return String
*/
public function executeBlatSearch($minMatch, $minCoverage) {
// run Blat client
exec("\"" . BLAT_PATH . "gfClient\" localhost 7776 \"\" " . $this->input . " -out=pslx " . "\"" . $this->output . "\"" . " -minIdentity=" . $minMatch);
/** exec("\"" . BLAT_PATH . "gfClient\" localhost 7776 \"\" " . $this->input . " -out=psl " . "\"" . $this->output . ".psl\"" . " -minIdentity=" . $minMatch);
exec("\"" . BLAT_PATH . "gfClient\" localhost 7776 \"\" " . $this->input . " -out=pslx " . "\"" . $this->output . ".pslx\"" . " -minIdentity=" . $minMatch);
exec("\"" . BLAT_PATH . "gfClient\" localhost 7776 \"\" " . $this->input . " -out=axt " . "\"" . $this->output . ".axt\"" . " -minIdentity=" . $minMatch);
exec("\"" . BLAT_PATH . "gfClient\" localhost 7776 \"\" " . $this->input . " -out=maf " . "\"" . $this->output . ".maf\"" . " -minIdentity=" . $minMatch);
exec("\"" . BLAT_PATH . "gfClient\" localhost 7776 \"\" " . $this->input . " -out=sim4 " . "\"" . $this->output . ".sim4\"" . " -minIdentity=" . $minMatch);
exec("\"" . BLAT_PATH . "gfClient\" localhost 7776 \"\" " . $this->input . " -out=wublast " . "\"" . $this->output . ".wublast\"" . " -minIdentity=" . $minMatch);
exec("\"" . BLAT_PATH . "gfClient\" localhost 7776 \"\" " . $this->input . " -out=blast " . "\"" . $this->output . ".blast\"" . " -minIdentity=" . $minMatch);
exec("\"" . BLAT_PATH . "gfClient\" localhost 7776 \"\" " . $this->input . " -out=blast8 " . "\"" . $this->output . ".blast8\"" . " -minIdentity=" . $minMatch);
exec("\"" . BLAT_PATH . "gfClient\" localhost 7776 \"\" " . $this->input . " -out=blast9 " . "\"" . $this->output . ".blast9\"" . " -minIdentity=" . $minMatch); /**/
// parsing results returned by Blat client using Biopython
// (the path to parsing.py is from the directory where the BlatTool
// is actually run)
exec("python ../app/DispatchModule/models/parsing.py " . "\"" . $this->output . "\" " . $minCoverage, $this->dumpedResults);
// convert array returned from exec in dumpedResults variable into string
$this->stringResults = implode("\n", $this->dumpedResults);
// unpack parsed results from python
$this->decodedResults = json_decode($this->stringResults, true);
return $this->decodedResults;
}
}