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: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371:
<?php
namespace DispatchModule;
/**
* Sequence is an envelope holding information about one specific sequence
*/
class Sequence {
/**
* String of nucleotide sequence
* @var string
*/
public $sequence;
/**
* Statistics from similarity search
* @var array
*/
public $matches = array();
/**
* Biological identifier
* @var string
*/
public $accession;
/**
* Sequence region start
* @var int
*/
public $startPosition;
/**
* Sequence region stop
* @var int
*/
public $stopPosition;
/**
* Length of sequence
* @var int
*/
public $regionLength;
/**
* Source dataset
* @var string
*/
public $dataset;
/**
* SILVA quality indicator (combination of ambig./homopol./vec.contam.)
* @var double
*/
public $sequenceQuality;
/**
* % of ambiguously sequenced nucleotides
* @var double
*/
public $ambiguities;
/**
* % of homopolymers longer than 4 nt.
* @var double
*/
public $homopolymers;
/**
* % of sequence contaminated by vector
* @var double
*/
public $vectorContamination;
/**
* Conservancy indicator
* @var double
*/
public $alignmentQuality;
/**
* SILVA-specific: possible base pairs in common with SILVA ref. structure
* @var int
*/
public $basePairScore;
/**
* Number of seq. bases aligned to within rRNA gene
* @var int
*/
public $alignedBases;
/**
* Confidence that sequence is not anomalous
* @var int
*/
public $pintailQuality;
/**
* Often contains 16S/23S/... info
* @var string
*/
public $description;
/**
* Sequence source molecule type (rRNA, mRNA, DNA, etc.)
* @var string
*/
public $moleculeType;
/**
* ENA data class annotation
* @var string
*/
public $dataClass;
/**
* ENA taxonomic division annotation
* @var string
*/
public $taxonomicDivision;
/**
* Version of the record in ENA database
* @var int
*/
public $version;
/**
* Date when it was first published
* @var timestamp
*/
public $firstPublic;
/**
* Date of the last update
* @var timestamp
*/
public $lastUpdated;
/**
* Identifier of the last release within this record has been updated
* @var string
*/
public $lastUpdatedRelease;
/**
* Author’s comment
* @var string
*/
public $comment;
/**
* Name of current specie
* @var string
*/
public $name;
/**
*
* @var string
*/
public $pathName;
/**
* Contains names of all of node’s ancestors recursively from the root.
* By default separated by a semicolon.
* @var string
*/
public $annotationSource;
/**
* Allows to classify items
* @var int
*/
public $state;
/**
* Contains information about references (ie. an article, paper,...)
* @var array
*/
public $references;
/**
* Unions some properties of a region of a nucleotide sequence (part of a gene)
* @var array
*/
public $features;
/**
* Contains data about references (links) to external databases.
* Reference can be stored for annotaion (reference to a DB) or annotation reference (journal, webpage) as well
* @var array
*/
public $xrefs;
/**
* Contains information about secondary structure prediction
* @var array
*/
public $predictions;
/**
* Loads data from array into properties
*
* @param array $data array containing values indexed by attributes (properties) name
*/
public function loadData(array $data, $object = null) {
if ($object == null) { $object = $this; }
foreach ($data as $name => $value) {
if (property_exists($object, $name)) {
if (is_array($value)) {
foreach ($value as $k => $arr) {
if (is_array($arr)) {
foreach ($arr as $key => $innerVal) {
$value[$k][$key] = $this->addOrdinal($innerVal);
}
} else {
$value[$k] = $this->addOrdinal($arr);
}
}
$object->$name = $value;
} else {
$object->$name = $this->addOrdinal($value);
}
} else if ($name == 'match') {
$match = new \DispatchModule\BaseMatch($value['label']);
$this->loadData($value, $match);
$this->matches[] = $match;
}
}
}
/**
* Adds preformated value - date/array/formated string
*
* @param mixed $data
* @return mixed
*/
protected function addOrdinal($data) {
if (is_a($data, 'Nette\DateTime')) {
$date = new \DateTime($data);
$return = $date->format('d. m. Y');
} elseif (is_array($data)) {
$return = $data;
} else {
$return = $this->formatString($data);
}
return $return;
}
/**
* Formats string for displaying (newlines, etc)
*
* @param string $string
* @return string
*/
protected function formatString($string) {
if ((string) $string == '') {
$result = null;
} else {
$semicolonSpaces = str_replace(';', '; ', (string) $string);
$order = array("\r\n", "\n", "/n", "\r");
$result = str_replace($order, '<br />', $semicolonSpaces);
}
return $result;
}
/**
* Converts nested array into one string line. If it is a string than the same string is returned. If not string like key:value1|value2|key2:value1||value2 is returned
* @param string|array $object Object to process
* @param int $depth Depth of the array
* @return string
*/
private function getOneDimension($object, $depth = 1) {
if ($object instanceof \DispatchModule\BaseMatch) {
$object = get_object_vars($object);
}
if (!is_array($object)) {
return $object;
}
$returnLine = "";
foreach ($object as $key => $value) {
if (!empty($returnLine)) {
$returnLine .= str_repeat("|", $depth);
}
if (!is_numeric($key)) {
$returnLine .= $key . ":";
}
$returnLine .= $this->getOneDimension($value, $depth + 1);
}
return $returnLine;
}
/**
* Converts Sequence object into one dimensional array
* @return array One dimensional array
*/
public function convertIntoOneDimensionalArray() {
$result = array();
foreach (get_object_vars($this) as $key => $value) {
$result[$key] = $this->getOneDimension($value);
}
return $result;
}
/**
* Gets all info about sequence from database
*
* @param \DispatchModule\SearchParser $searchParser instance of search parser
* @param string $accession accession number
* @param int $start (optional) start position
* @param int $stop (optional) stop position
* @return array sequence data
* @throws \BaseModule\Exceptions\NotFoundException
*/
public static function loadSequenceInfo($searchParser, $accession, $start = null, $stop = null) {
$f = new \BaseModule\Form();
$f->addHidden('db_accession', $accession);
if ($start !== null) {
$f->addHidden('db_start', $start);
}
if ($stop !== null) {
$f->addHidden('db_stop', $stop);
}
$f->addHidden('db', true);
$resultSet = $searchParser->parseForm($f);
$data = $resultSet->getData();
// load information needed - sequence, secondary structure and idString (accesion_predictionId)
if (empty($data[0]->sequence) || !isset($data[0]->predictions) || empty($data[0]->accession)) {
throw new \BaseModule\Exceptions\NotFoundException('Sequence [accesion=' . $accession . ', ' . $start . '-' . $stop . '] not found');
}
return $data[0];
}
/**
* Gets prediction structure from all sequence predictions
*
* @param array $predictions array containing info about all structure predictions
* @param int $prediction_id id of prediction to get
* @return string prediction structure
* @throws \BaseModule\Exceptions\NotFoundException
*/
public static function getPredictionFromGroup($predictions, $prediction_id) {
foreach ($predictions as $prediction) {
if ($prediction['structure_id'] == $prediction_id) {
$resultPrediction = $prediction['structure'];
}
}
if (empty($resultPrediction)) {
throw new \BaseModule\Exceptions\NotFoundException('Prediction not found');
}
return $resultPrediction;
}
/**
* Simplifies the prediction - converts pseudoknots to ordinary knots ({}, [] -> ())
*
* @param string $complexPrediction prediction including curly braces/brackets
* @return string simple dot-paren string suitable for use in ViennaRNA package
*/
public static function makeSimplePrediction($complexPrediction) {
return str_replace('}', '.', str_replace('{', '.', str_replace(']', '.', str_replace('[', '.', $complexPrediction))));
}
}