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: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202:
<?php
namespace DispatchModule\Tools;
class SimilarityTool extends \DispatchModule\Tools\BaseTool implements \DispatchModule\Tools\ToolInterface {
protected $xmlParser;
protected $query;
protected $directory;
public $description = 'Basic Local Alignment Search Tool compares primary biological sequence information';
public $blastTempFile;
protected $used = false;
public function used() {
return $this->used;
}
protected $wantedParameters = array(
'min_coverage' => array('select', 'Min coverage', array("items" =>
array(
'40' => '40%',
'65' => '65%',
'80' => '80%',
'85' => '85%',
'90' => '90%',
'93' => '93%',
'95' => '95%',
'97' => '97%',
'98' => '98%',
'99' => '99%',
'100' => '100%',
))),
'min_identity' => array('select', 'Min identity', array("items" =>
array(
'40' => '40%',
'65' => '65%',
'80' => '80%',
'85' => '85%',
'90' => '90%',
'93' => '93%',
'95' => '95%',
'97' => '97%',
'98' => '98%',
'99' => '99%',
'100' => '100%',
))),
'sequence' => array('textarea', 'Sequence', array(
'placeholder' => 'AGUUCGGCACCACGGUGCAA',
'multiplicators' => array('or' => 10))),
'fasta_file' => array('file', 'Fasta file'),
'fasta_file_hidden' => array('hidden')
);
public function __construct(\Nette\DI\Container $container) {
parent::__construct($container);
$this->directory = TEMP_PATH . DIRECTORY_SEPARATOR . "blastTemp" . DIRECTORY_SEPARATOR;
}
public function addCriteria($name, $value) {
switch ($name) {
case "sequence":
if (isset($this->completeData['blast_sequence_array'])) {
$sequences = $this->completeData['blast_sequence_array'];
}
$value .= ((isset($sequences[0])) ? "\n" . implode("\n", $sequences) : "");
if (!empty($value)) {
$this->used = true;
}
break;
case "fasta_file":
break;
case "fasta_file_hidden":
if (!empty($value)) {
$this->used = true;
}
break;
}
if (isset($this->completeData['offset']) && $this->completeData['offset'] > 0) {
return true;
}
if (is_null($this->query)) {
if (!isset($this->fileName) || empty($this->fileName)) {
$this->fileName = (session_id()) ? session_id() : (time() . rand());
}
$this->blastTempFile = $this->directory . $this->fileName . ".txt";
$this->query = new \BaseModule\Models\FileModel($this->directory . $this->fileName);
$this->query->createFile();
$this->xmlParser = new \DispatchModule\Models\BlastXMLParser($this->directory . $this->fileName . ".xml");
}
switch ($name) {
case "min_coverage":
$this->xmlParser->setMinCoverage($value / 100);
break;
case "min_identity":
$this->xmlParser->setMinIdentity($value / 100);
break;
case "sequence":
if (!empty($value)) {
$this->query->appendContent($value);
}
break;
case "fasta_file":
break;
case "fasta_file_hidden":
if (!empty($value)) {
if ($this->query->getContent()) {
$this->query->appendContent("\n");
}
$this->query->appendContent($value);
}
break;
}
}
public function execute() {
if (isset($this->completeData['offset']) && $this->completeData['offset'] > 0) {
return null;
}
$blast = new \DispatchModule\Models\BlastModel($this->query->getFile());
$blast->executeBlastSearch($this->xmlParser->getFileName());
$seq = $this->xmlParser->execute();
$this->query->deleteFile();
$this->xmlParser->deleteFile();
\BaseModule\Models\FileModel::deleteOldFiles($this->directory);
return $seq;
}
public function getLabel() {
return 'Sequence';
}
}