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

namespace DispatchModule\Models;

/**
 * Cppredict2Model cooperates with Cppredict2
 *
 */
class Cppredict2Model extends \BaseModule\Models\BaseModel {

    /**
     * Used as: cp_predict.py -r $cp_root
     * @var string
     */
    protected $cpRoot;

    /**
     * This is where the temporary files for cp_predict2 are created.
     * @var string
     */
    protected $tempDir;

    /**
     * Used as: cp_predict.py -t $templates
     * @var string
     */
    protected $templates;

    /**
     * Used as: cp_predict.py -m $tmap
     * @var string
     */
    protected $tmap;

    /**
     * Passed directly. Will change when further input fields are enabled.
     * @var string
     */
    protected $defaultPredictionSettings;

    /**
     * Used for debugging.
     * @var FileModel
     */
    private $logFile;

    /**
     * Debug mode
     * @var bool
     */
    private $debug;

    /**
     * Log message output for debugging purposes, incl. formatting.
     * @param string $message Log message to be saved
     */
    public function logRecord($message) {
        if ($this->debug) {
            $this->logFile->appendContent(time() . ' : Cppredict2Model : ' . $message . "\n");
        }
    }

    /**
     * Fills in the default values for running cp_predict.py
     *
     * @param bool $debug if set to true, debug mode is on
     */
    public function __construct($debug = -1) {

        if ($debug === -1) { // default => Nette debug value
            $this->debug = \Nette\Diagnostics\Debugger::isEnabled();
        } else {
            $this->debug = $debug;
        }

        $this->cpRoot = CPPREDICT_TOOLDIR . 'cp_root/';
        # If the setup.py installation procedure is found to work, we will
        # not need $this->cpRoot any more.

        $this->tempDir = TEMP_PATH . '/cppredict/';
        $this->templates = 'template-selection.aln';
        $this->tmap = 'tmap.csv';
        $this->defaultPredictionSettings = ' -p -w 10 -g 0.15 --disregard_ends';
        $this->logFile = new \BaseModule\Models\FileModel('files/cppredict/cppredict_tool.log');
        $dummyCommand = $this->buildCommand('someInput');
        $this->logRecord('  Built model with command ' . $dummyCommand);
    }

    /**
     * Builds the shell command to execute. Everything except the input FASTA
     * sequence name is known from inside Cppredict2Model, so the only argument
     * is the input FASTA name.          
     *          
     * @param string $inputSeqFasta The path to the input FASTA file, relative to $cp_root
     * 
     * @return string The command to pass to shell_exec() to run CP-predict2           
     */
    public function buildCommand($inputSeqFasta) {


        $this->logRecord('Constructing command for input: ' . $inputSeqFasta);

        # Testing with the cp_predict2 data included by default in the
        # rPredictorDB Python package.
        # $command = 'cp_predict.py';
        $command = 'cp_predict.py -r ' . $this->cpRoot;
        $command = $command . ' -t ' . $this->templates;
        $command = $command . ' -m ' . $this->tmap;
        $command = $command . $this->defaultPredictionSettings;
        $command = $command . ' --tmp_dir ' . $this->tempDir;
        $command = $command . ' -i ' . $inputSeqFasta;

        if ($this->debug) {
            $command = $command . ' -v 2>>' . $this->logFile->getFile();
        }

        $this->logRecord('Constructed command: ' . $command);

        return $command;
    }

}
API documentation generated by ApiGen