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;
class PredictParser extends \DispatchModule\BaseParser {
public function parseForm(\BaseModule\Form $form) {
$formValues = $form->values;
$tools = $this->getTools();
foreach ($tools as $toolName => $tool) {
if (!$formValues[$toolName]) {
unset($tools[$toolName]);
}
}
foreach ($formValues as $inputName => $value) {
$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 = "";
foreach ($tools as $tool) {
$outputs = $tool->execute();
}
$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);
if (is_array($outputArray)) {
$result = array('other' => array());
$result['header'] = $outputArray[0];
for ($i = 1; $i < count($outputArray); $i++) {
if ($outputArray[$i] == '') {
continue;
}
if (!preg_match('/[^ACGUTMRWSYKVHDBN\*\-]/i', trim($outputArray[$i]))) {
$result['sequence'] .= $outputArray[$i];
$result['cleaned'] .= $outputArray[$i];
} elseif (!preg_match('/[^\(\.\){}\[\]]/', trim($outputArray[$i]))) {
$result['dotParent'] = $outputArray[$i];
} else {
$result['other'][] = $outputArray[$i];
}
}
}
$results[] = $result;
}
}
}
$idPrefix = microtime(true);
foreach ($results as $index => &$result) {
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;
}
}