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: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342:
<?php
namespace SearchModule;
class SearchPresenter extends \BaseModule\BasePresenter {
protected $parser;
protected $dbService;
public function renderDefault() {
$this->template->parameterList = $this->parser->getParameterList();
$this->template->toolList = $this->parser->getTools();
if ($this->getHttpRequest()->getQuery('noajax') !== null) {
$this->template->noajax = true;
}
}
protected function createComponentSearchForm() {
$form = $this->parser->addFormParameters(new \BaseModule\Form);
$form->addHidden('search_id');
$form->addHidden('continuous', false);
$form->addHidden('limit', 20)->setValue('20');
$form->addHidden('offset', 0)->setValue('0');
$form->addHidden('start');
$form->addHidden('stop');
$form->addHidden('export_type');
$form->addHidden('db_perform_full', false)->setValue('false');
$form->addTextArea('db_export_accession')->setAttribute('class', 'hidden');
$form->addSubmit('search', 'Search');
$form->onSuccess[] = $this->searchFormSubmitted;
return $form;
}
public function searchFormSubmitted(\Nette\Application\UI\Form $f) {
$resultSet = $this->parser->parseForm($f);
if ($resultSet && count($resultSet) > 0) {
if ($this->isAjax()) {
$this->sendResponse(new \Nette\Application\Responses\JsonResponse($resultSet->getDataAndCount()));
} else {
$accessions = explode("\n", $f->values->db_export_accession);
$newResultSet = empty($f->values->db_export_accession) ? $resultSet : new \DispatchModule\ResultSet();
foreach ($resultSet->getData() as $seq) {
if (in_array($seq->accession.":".$seq->startPosition.":".$seq->stopPosition, $accessions)) {
$newResultSet->addSequence($seq);
}
}
$this->saveResultSet($newResultSet, $f->values->export_type);
}
}
}
public function renderExport() {
$ext = $this->getHttpRequest()->getPost("exportType");
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="export.' . $ext . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
$this->setLayout(false);
$this->template->export = $this->getHttpRequest()->getPost("export");
}
public function saveResultSet($resultSet, $ext = "fasta") {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="export.' . $ext . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
$fc = "saveResultSet" . ucfirst($ext);
$this->$fc($resultSet);
$this->terminate();
}
public function saveResultSetFasta($resultSet) {
$first = true;
foreach ($resultSet->getData() as $seq) {
if ($first) {
$first = false;
} else {
echo "\r\n\r\n";
}
echo ">" . $seq->accession . "." . preg_replace("/\s/", "_", $seq->name) . "\r\n" .
$seq->sequence;
foreach ($seq->predictions as $p) {
echo "\r\n" . $p["structure"];
}
}
}
public function saveResultSetCsv($resultSet, $file = null) {
if (empty($file)) {
$file = "php://output";
}
$fp = fopen($file, "w");
foreach ($resultSet->getData() as $seq) {
fputcsv($fp, $seq->convertIntoOneDimensionalArray());
}
fclose($fp);
}
public function saveResultSetJSON($resultSet) {
$first = true;
echo json_encode($resultSet->getData());
}
public function actionGetOrganismName() {
$orgName = $this->getParameter("q");
$this->sendResponse(new \Nette\Application\Responses\TextResponse($this->getParameter("callback") . "(" .
json_encode(
$this->parser->getNameValues($orgName)
)
. ")")
);
}
public function actionGetResultSize() {
return $this->sendResponse(new \Nette\Application\Responses\JsonResponse(array('resultSize' => $this->parser->getResultCount($this->getHttpRequest()->getPost()))));
}
public function actionGetImage($param) {
$dir = substr($param, 0, 3);
$this->sendResponse(new \Nette\Application\Responses\FileResponse(APP_DIR . 'www' . DIRECTORY_SEPARATOR . TEMP_PATH . DIRECTORY_SEPARATOR . 'dbImages' . DIRECTORY_SEPARATOR . 'png' . DIRECTORY_SEPARATOR . $param . '.png'));
}
public function actionGetTemplate($param) {
$this->sendResponse(new \Nette\Application\Responses\FileResponse(CPPREDICT2_TEMPLATES . str_replace(' ', '_', str_replace(' - ', '-', $param)) . '.br'));
}
public function actionGetSequence($param, $start, $stop) {
$data = \DispatchModule\Sequence::loadSequenceInfo($this->parser, $param, $start, $stop);
$this->sendResponse(new \Nette\Application\Responses\TextResponse(
"<style> body {word-wrap: break-word;}</style>" .
$data->sequence
));
}
public function actionGetStructure($param, $start, $stop, $id) {
$data = \DispatchModule\Sequence::loadSequenceInfo($this->parser, $param, $start, $stop);
$prediction = \DispatchModule\Sequence::getPredictionFromGroup($data->predictions, $id, $start, $stop);
$this->sendResponse(new \Nette\Application\Responses\TextResponse($prediction));
}
public function actionGetFullImage($param, $start = null, $stop = null, $id = null) {
if ($start !== null && $stop !== null && $id !== null) {
$this->template->imagePath = TEMP_PATH . DIRECTORY_SEPARATOR . 'dbImages' . DIRECTORY_SEPARATOR . 'svg' . DIRECTORY_SEPARATOR . $param . '_' . $start . '_' . $stop . '.svg';
} elseif (file_exists(TEMP_PATH . DIRECTORY_SEPARATOR . 'predict_rnaplot' . DIRECTORY_SEPARATOR . $param)) {
$this->template->imagePath = TEMP_PATH . DIRECTORY_SEPARATOR . 'predict_rnaplot' . DIRECTORY_SEPARATOR . $param;
}
}
public function actionGetTaxonomyChoiceWithSpecies($param) {
$this->sendResponse(new \Nette\Application\Responses\JsonResponse(array(0 => $this->dbService->getSubTaxonomyFull($param), 1 => $this->dbService->getSubSpeciesFull($param))));
}
public function actionTaxonomybrowser($preselected = null, $fulltext = null, $fulltextOnlyMatches = true, $fulltextIds = '', $treeElSize = 600) {
$this->template->preselected = array_filter(explode(',', $preselected));
if ($fulltext !== NULL && strlen($fulltext) > 2) {
$this->template->fulltextWord = $fulltext;
if ($fulltextOnlyMatches) {
list($this->template->fulltextedChildren, $this->template->fulltextIds) = $this->dbService->getFulltextMatchesTree($fulltext);
} else {
if ($fulltextIds !== '') {
$this->template->fulltextIds = unserialize($fulltextIds);
$this->template->fulltextedChildren = $this->dbService->getFulltextWholeTreeWithHelp($this->template->fulltextIds);
} else {
list($this->template->fulltextedChildren, $this->template->fulltextIds) = $this->dbService->getFulltextWholeTree($fulltext);
}
}
} else {
$this->template->fulltextIds = array();
$this->template->fulltextWord = '';
}
$this->template->treeElSize = $treeElSize;
$this->template->children = $this->dbService->getChildrenTree($this->template->preselected);
$this->template->tree = $this->dbService->getSubTaxonomyFull(null);
}
public function actionGetSequencesByAccessions($param) {
$accessions = json_decode($param);
$result = array();
foreach ($accessions as $acc) {
$result[] = \DispatchModule\Sequence::loadSequenceInfo($this->parser, $acc);
}
return $this->sendResponse(new \Nette\Application\Responses\JsonResponse($result));
}
public function actionGetFastaInfoByAccessions($param) {
$accessions = json_decode($param);
$result = $this->dbService->getBasicInfoForAccessions($accessions);
return $this->sendResponse(new \Nette\Application\Responses\JsonResponse($result));
}
protected function createComponentTaxonomyBrowserForm() {
$form = new \BaseModule\Form;
$form->addText('fulltextSearch', false)->setAttribute('placeholder', 'fulltext search');
$form->addCheckbox('wholeTree', 'display full tree');
$form->addSubmit('fulltextSearchSubmit', 'Search');
return $form;
}
}