Overview

Namespaces

  • AnalyseModule
    • Models
  • BaseModule
    • Exceptions
    • Models
    • Repository
    • Services
  • DispatchModule
    • Helpers
    • Models
    • Tools
  • PredictModule
  • SearchModule

Classes

  • AnalyseModule\AnalysePresenter
  • AnalyseModule\ConservancyPresenter
  • AnalyseModule\Models\BaseTool
  • AnalyseModule\Models\ConservancyComparator
  • BaseModule\BasePresenter
  • BaseModule\DiscoveredViewReflection
  • BaseModule\ErrorPresenter
  • BaseModule\Form
  • BaseModule\HomepagePresenter
  • BaseModule\Models\BaseModel
  • BaseModule\Models\FileModel
  • BaseModule\PesekPresenter
  • BaseModule\Repository\BaseRepository
  • BaseModule\Repository\TestRepository
  • BaseModule\RouterFactory
  • BaseModule\RssPresenter
  • BaseModule\Services\Authenticator
  • BaseModule\Services\BaseService
  • BaseModule\Services\DbService
  • DispatchModule\BaseMatch
  • DispatchModule\BaseParser
  • DispatchModule\BlastMatch
  • DispatchModule\BlatMatch
  • DispatchModule\Helpers\RnaplotHelper
  • DispatchModule\Helpers\TravelerHelper
  • DispatchModule\Models\BaseModel
  • DispatchModule\Models\BlastModel
  • DispatchModule\Models\BlastXMLParser
  • DispatchModule\Models\BlatModel
  • DispatchModule\Models\Cppredict2Model
  • DispatchModule\Models\CppredictModel
  • DispatchModule\Models\FastaModel
  • DispatchModule\Models\FileModel
  • DispatchModule\PredictParser
  • DispatchModule\ResultSet
  • DispatchModule\SearchParser
  • DispatchModule\Sequence
  • DispatchModule\Tools\AnnotationDbTool
  • DispatchModule\Tools\BaseTool
  • DispatchModule\Tools\Cppredict2Tool
  • DispatchModule\Tools\DbTool
  • DispatchModule\Tools\SimilarityTool
  • DispatchModule\Tools\TaxonomyDbTool
  • PredictModule\PredictPresenter
  • SearchModule\SearchPresenter

Interfaces

  • DispatchModule\Tools\ToolInterface

Exceptions

  • BaseModule\Exceptions\BaseException
  • BaseModule\Exceptions\NotFoundException
  • BaseModule\Exceptions\ToolException
  • Overview
  • Namespace
  • Class
  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;

/**
 * Description of SearchPresenter
 *
 * @author Tomáš Hladík
 */
class SearchPresenter extends \BaseModule\BasePresenter {

    /**
     * @var \DispatchModule\SearchParser object that parses query and returns result
     * @Inject
     */
    protected $parser;

    /**
     * @var \BaseModule\Services\DbService object that parses query and returns result
     * @Inject
     */
    protected $dbService;

    /**
     * Render default search form page
     */
    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;
        }
    }

    /**
     * Creates search form
     *
     * @return \BaseModule\Form
     */
    protected function createComponentSearchForm() {
        // get all wanted attributes
        $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;
    }

    /**
     * Search form processing
     *
     * @param \Nette\Application\UI\Form $f
     */
    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();
                /* @var $seq \DispatchModule\Sequence */
                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);
            }
        }
    }

    /**
     * Forces a file to download (from the export of the search).
     * Data are from the post request (variables exportType and export)
     */
    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");
    }
    
    /**
     * Forces a file to download
     * @param \DispatchModule\ResultSet $resultSet Result set containing all sequences to be saved
     * @param String $ext Extension of the file, "fasta" as default
     */
    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();
    }
    
    /**
     * Forces a fasta file to download
     * @param \DispatchModule\ResultSet $resultSet Result set containing all sequences to be saved
     */
    public function saveResultSetFasta($resultSet) {
        /* @var $seq \DispatchModule\Sequence */
        $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"];
            }
        }
    }
    
    /**
     * Forces a CSV file to download
     * @param \DispatchModule\ResultSet $resultSet Result set containing all sequences to be saved
     * @param String $file Location to save the output of the file, "php://output" as default
     */
    public function saveResultSetCsv($resultSet, $file = null) {
        if (empty($file)) {
            $file = "php://output";
        }
        $fp = fopen($file, "w");
        /* @var $seq \DispatchModule\Sequence */
        foreach ($resultSet->getData() as $seq) {
            fputcsv($fp, $seq->convertIntoOneDimensionalArray());
        }
        fclose($fp);
    }
    
    /**
     * Forces a JSON file to download
     * @param \DispatchModule\ResultSet $resultSet Result set containing all sequences to be saved
     */
    public function saveResultSetJSON($resultSet) {
        /* @var $seq \DispatchModule\Sequence */
        $first = true;
        echo json_encode($resultSet->getData());
    }

    /**
     * Autocomplete - organism name
     */
    public function actionGetOrganismName() {
        $orgName = $this->getParameter("q");
        $this->sendResponse(new \Nette\Application\Responses\TextResponse($this->getParameter("callback") . "(" .
                json_encode(
                        $this->parser->getNameValues($orgName)
                )
                . ")")
        );
    }

    /**
     * Returns result size in json response
     *
     * @return json encoded array containing 'resultSize' key with integer value
     */
    public function actionGetResultSize() {
        return $this->sendResponse(new \Nette\Application\Responses\JsonResponse(array('resultSize' => $this->parser->getResultCount($this->getHttpRequest()->getPost()))));
    }

    /**
     * Returns file response with image for specified structure
     *
     * @param string $param name of the image to be displayed (format is ACCESSION_START_STOP)
     */
    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'));
    }

    /**
     * Returns a file response with a requested template
     *
     * @param string $param id of the template
     */
    public function actionGetTemplate($param) {
        $this->sendResponse(new \Nette\Application\Responses\FileResponse(CPPREDICT2_TEMPLATES . str_replace(' ', '_', str_replace(' - ', '-', $param)) . '.br'));
    }

    /**
     * Gets sequence from database
     *
     * @param string $param accesion number
     * @param int $start start position
     * @param int $stop stop position
     * @throws \BaseModule\Exceptions\NotFoundException
     */
    public function actionGetSequence($param, $start, $stop) {
        // load information from database
        $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
        ));
    }

    /**
     * Gets structure from database
     *
     * @param string $param accession number
     * @param int $start start position
     * @param int $stop stop position
     * @param int $id predicted structure id
     * @throws \BaseModule\Exceptions\NotFoundException
     */
    public function actionGetStructure($param, $start, $stop, $id) {
        // load information from database
        $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));
    }

    /**
     * Gets full SVG iamge for accesion & prediction id
     *
     * @param string $param accession number OR file name for predicted file display (in case rest of the parameters are null)
     * @param int $start start of the sequence region
     * @param int $stop end of the sequence region
     * @param int $id prediction id
     */
    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;
        }
    }

    /**
     * Serves for AJAX calls - returns JSON-encoded list of taxonomies in sublevel
     *
     * @param int $param taxonomy id
     */
    public function actionGetTaxonomyChoiceWithSpecies($param) {
        $this->sendResponse(new \Nette\Application\Responses\JsonResponse(array(0 => $this->dbService->getSubTaxonomyFull($param), 1 => $this->dbService->getSubSpeciesFull($param))));
    }

    /**
     * Display taxonomy browser - the top list categories are displayed
     *
     * @param string $preselected preselected ids (split by ',')
     * @param string $fulltext word to search for
     * @param boolean $fulltextOnlyMatches if true, only direct (non-expanded) paths to fulltext matches are shown
     * @param string $fulltextIds serialized array of ids of matches (helper to ease heavy use of DB in between same fulltext calls)
     * @param int $treeElSize helper determinig the tree height based on viewport size (is here just in case of JS problems since the actual height is set by JS anyway)
     */
    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) { // fulltext search performed
            $this->template->fulltextWord = $fulltext;
            if ($fulltextOnlyMatches) { // display tree with paths to matches non-expanded
                list($this->template->fulltextedChildren, $this->template->fulltextIds) = $this->dbService->getFulltextMatchesTree($fulltext);
            } else {
                if ($fulltextIds !== '') { // help exists (ids of matches are known)
                    $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);
    }

    /**
     * Serves for AJAX calls - list sequences by (multiple) accession numbers
     *
     * @param string $param json-encoded array of accession numbers
     * @return JSON array containing all sequences with specified accession numbers
     */
    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));
    }

    /**
     * Serves for AJAX calls - list fasta file info (name, sequence, prediction) of sequences by (multiple) accession numbers
     *
     * @param string $param json-encoded array of accession numbers
     * @return JSON array containing all sequences with specified accession numbers
     */
    public function actionGetFastaInfoByAccessions($param) {
        $accessions = json_decode($param);
        $result = $this->dbService->getBasicInfoForAccessions($accessions);
        return $this->sendResponse(new \Nette\Application\Responses\JsonResponse($result));
    }

    /**
     * Creates search form
     *
     * @return \BaseModule\Form
     */
    protected function createComponentTaxonomyBrowserForm() {
        // get all wanted attributes
        $form = new \BaseModule\Form;

        $form->addText('fulltextSearch', false)->setAttribute('placeholder', 'fulltext search');
        $form->addCheckbox('wholeTree', 'display full tree');
        $form->addSubmit('fulltextSearchSubmit', 'Search');
        return $form;
    }

}
API documentation generated by ApiGen