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: 
<?php

namespace DispatchModule;

/**
 * PredictParser is responsible for parsing predict form (from user) and running services for needed tools
 * - it also contains support functions for connecting search form with tools
 */
class PredictParser extends \DispatchModule\BaseParser {

    /**
     * Main method parses form and initializes tool classes
     *
     * @param \Nette\Application\UI\Form $form
     * @return \DispatchModule\ResultSet result of the search
     */
    public function parseForm(\BaseModule\Form $form) {
        $formValues = $form->values;

        // list all available tools with its prefixes
        $tools = $this->getTools();

        // only run tools, that were checked
        foreach ($tools as $toolName => $tool) {
            if (!$formValues[$toolName]) {
                unset($tools[$toolName]);
            }
        }

        // process all submitted values
        foreach ($formValues as $inputName => $value) {
            // remove input name prefix
            $name = \Nette\Utils\Strings::substring($inputName, strpos($inputName, '_') + 1);
            $prefix = \Nette\Utils\Strings::substring($inputName, 0, strpos($inputName, '_'));
            if (!empty($prefix) && isset($tools[$prefix])) {
                $tools[$prefix]->addCriteria($name, $value);
            }
        }


        $outputs = ""; // for the case that none tool is selected
        // run tools and merge results
        foreach ($tools as $tool) {
            $outputs = $tool->execute(); // only 1 tools is allowed
        }
        $results = array();

        if (is_array($outputs)) {
            $outputsArray = $outputs;
        } else {
            $outputsArray = preg_split('/((?<=\n)(?=>))/', $outputs, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
        }
        if (is_array($outputsArray)) {
            foreach ($outputsArray as $output) {
                if (is_array($output)) {
                    $results[] = $output;
                } else {
                    $outputArray = explode("\n", $output); // split output by line
                    // output should be an array
                    if (is_array($outputArray)) {
                        $result = array('other' => array());
                        // first line is always header
                        $result['header'] = $outputArray[0];
                        for ($i = 1; $i < count($outputArray); $i++) {
                            // skip empty lines
                            if ($outputArray[$i] == '') {
                                continue;
                            }
                            // recognize sequence
                            if (!preg_match('/[^ACGUTMRWSYKVHDBN\*\-]/i', trim($outputArray[$i]))) {
                                $result['sequence'] .= $outputArray[$i];
                                $result['cleaned'] .= $outputArray[$i];
                            } elseif (!preg_match('/[^\(\.\){}\[\]]/', trim($outputArray[$i]))) { // recognize dot parent structure
                                $result['dotParent'] = $outputArray[$i];
                            } else { // other unknown information
                                $result['other'][] = $outputArray[$i];
                            }
                        }
                    }
                    $results[] = $result;
                }
            }
        }

        $idPrefix = microtime(true);
        foreach ($results as $index => &$result) {
            // generate RNAplot visualization for predicted structure
            if (isset($result['cleaned']) && isset($result['dotParent'])) {
                $rnaplotTemp = APP_DIR . 'www' . DIRECTORY_SEPARATOR . TEMP_PATH . DIRECTORY_SEPARATOR . 'predict_rnaplot' . DIRECTORY_SEPARATOR;
                $idString = $idPrefix . '-' . $index;
                \DispatchModule\Helpers\RnaplotHelper::generateRnaplot($rnaplotTemp, $idString, $result['cleaned'], $result['dotParent'], -1);
                \BaseModule\Models\FileModel::deleteOldFiles($rnaplotTemp);
                unset($result['cleaned']);
                $result['image'] = $idString . '_ss.svg';
            }
        }

        return $results;
    }

}
API documentation generated by ApiGen