Overview

Namespaces

  • cli_db
    • propel
      • map
      • om
  • cli_import
  • LoggedPDO
  • None
  • PHP
  • webservices
    • cart
    • combisearch
    • details
      • annotations
        • feature
    • graphs
      • barplot
      • genome
    • listing
    • queue

Classes

  • Console_CommandLine_Action_ExtendedHelp
  • LightOpenID
  • Log_firebugJSON
  • WebService

Interfaces

  • CLI_Command

Functions

  • acquire_database
  • cli_error_handler
  • connect_queue_db
  • create_job
  • display_feature
  • display_feature_by_id
  • display_isoform_by_id
  • display_unigene_by_id
  • download
  • execute_command
  • execute_job
  • execute_query_dir
  • get_db_connection
  • get_job_results
  • get_program_databases
  • myErrorHandler
  • pdo_connect
  • report_results_cleanup
  • requestVal
  • smarty_function_call_webservice
  • smarty_function_dbxreflink
  • smarty_function_interprolink
  • smarty_function_publink
  • smarty_modifier_clean_id
  • split_fasta
  • unzip
  • Overview
  • Namespace
  • Function
  • Tree
  1: <?php
  2: 
  3: function create_job($type, $database, $additional_data = array(), $paramters = array(), $queries = array()) {
  4:     try {
  5:         //connect to the database
  6:         $pdo = connect_queue_db();
  7: 
  8: 
  9:         //builds an array with every 2*n-th parameter representing a parameter key and every 2*n+1-th parameter representing the respective value
 10:         $parameters_prepared = array();
 11:         foreach ($paramters as $key => $value) {
 12:             $parameters_prepared[] = $key;
 13:             $parameters_prepared[] = $value;
 14:         }
 15:         //builds a string like ARRAY[?,?],ARRAY[?,?] where the total count of questionmarks is is count($parameters)
 16:         $parameter_qmarks = count($parameters_prepared) == 0 ? 'ARRAY[]' : implode(',', array_fill(0, count($parameters_prepared) / 2, 'ARRAY[?,?]'));
 17:         //exit if we have no queries
 18:         if (count($queries) == 0)
 19:             return(array('status' => 'error', 'message' => 'No query sequence specified!'));
 20: 
 21: 
 22:         //builds a string like '?,?,?' where the count of questionmarks is is count($queries)
 23:         $query_qmarks = implode(',', array_fill(0, count($queries), '?'));
 24: 
 25:         //prepare the create_job statement
 26:         $statement_create_job = $pdo->prepare('SELECT * FROM create_job(?,  ?, ?, ARRAY[' . $parameter_qmarks . '], ARRAY[' . $query_qmarks . ']);');
 27:         //and execute it
 28:         $statement_create_job->execute(array_merge(
 29:                         array($type, $database, json_encode($additional_data)), $parameters_prepared, $queries
 30:         ));
 31:         //rowcount should be 1 if job was started, else report an error
 32:         if ($statement_create_job->rowCount() == 0) {
 33:             return(array('status' => 'error', 'message' => 'Job could not be started! Please report this error including all parameters you used.'));
 34:         }
 35: 
 36:         return array('status' => 'success', 'job_id' => $statement_create_job->fetchColumn());
 37:     } catch (\PDOException $e) {
 38:         //report errors
 39:         return(array('status' => 'error', 'message' => 'Job could not be started: ' . $e->getMessage()));
 40:     }
 41: }
 42: 
 43: function get_job_results($job_uid) {
 44:     try {
 45:         //connect to the database
 46:         $pdo = connect_queue_db();
 47:         //prepare our get_job_results statement
 48:         $statement_jobresults = $pdo->prepare('SELECT * FROM get_job_results(?);');
 49:         //execute statement
 50:         $statement_jobresults->execute(array($job_uid));
 51:         $res = array();
 52:         while ($row = $statement_jobresults->fetch(\PDO::FETCH_ASSOC)) {
 53:             //we are the first row, store data that will be the same for every row
 54:             if (empty($res)) {
 55:                 $res['job_status'] = $row['status'];
 56:                 $res['additional_data'] = json_decode($row['additional_data']);
 57:                 if ($row['status'] == 'NOT_PROCESSED') {
 58:                     $statement_queuepos = $pdo->prepare('SELECT * FROM get_queue_position(?);');
 59:                     $statement_queuepos->execute(array($_REQUEST['jobid']));
 60:                     $pos = $statement_queuepos->fetch(\PDO::FETCH_ASSOC);
 61:                     $res['queue_position'] = $pos['queue_position'];
 62:                     $res['queue_length'] = $pos['queue_length'];
 63:                 }
 64:             }
 65:             //store the sub_query results in an array
 66:             $res['processed_results'][] = array(
 67:                 'query' => $row['query'],
 68:                 'status' => $row['query_status'],
 69:                 'result' => $row['query_stdout'],
 70:                 'errors' => $row['query_stderr']
 71:             );
 72:         }
 73:         //just return our data
 74:         return $res;
 75:     } catch (\PDOException $e) {
 76:         //or die on error
 77:         return array('status' => 'ERROR');
 78:     }
 79: }
 80: 
 81: function get_program_databases($filter_string=null) {
 82:     try {
 83:         //connect to the database
 84:         $pdo = connect_queue_db();
 85:         //prepare our get_programname_database statement
 86:         $stm = $pdo->prepare('SELECT * FROM get_programname_database(?)');
 87:         //and execute it
 88:         $stm->execute(array($filter_string));
 89:         $ret = array();
 90:         while ($row = $stm->fetch(\PDO::FETCH_ASSOC)) {
 91:             //put the rows into an array
 92:             $ret[$row['programname']][] = $row['database_name'];
 93:         }
 94:         //and return it
 95:         return $ret;
 96:     } catch (\PDOException $e) {
 97:         //on error, just return an empty json object
 98:         return array();
 99:     }
100: }
101: 
102: /*
103:  * splits fasta input to sequences for processing.
104:  * a simple 
105:  * <b>$queries = explode('>', $query); for ($queries as &$val) $val = '>'.$val;</b>
106:  * would do the same but we also test the sequences for valid format
107:  * fasta format according to http://blast.ncbi.nlm.nih.gov/blastcgihelp.shtml
108:  */
109: 
110: function split_fasta($query, $type) {
111: 
112:     $fasta_allowed = array();
113:     /*
114:       A  adenosine          C  cytidine             G  guanine
115:       T  thymidine          N  A/G/C/T (any)        U  uridine
116:       K  G/T (keto)         S  G/C (strong)         Y  T/C (pyrimidine)
117:       M  A/C (amino)        W  A/T (weak)           R  G/A (purine)
118:       B  G/T/C              D  G/A/T                H  A/C/T
119:       V  G/C/A              -  gap of indeterminate length
120:      */
121:     $fasta_allowed['nucl'] = 'ACGTNUKSYMWRBDHV-';
122:     /*
123:       A  alanine               P  proline
124:       B  aspartate/asparagine  Q  glutamine
125:       C  cystine               R  arginine
126:       D  aspartate             S  serine
127:       E  glutamate             T  threonine
128:       F  phenylalanine         U  selenocysteine
129:       G  glycine               V  valine
130:       H  histidine             W  tryptophan
131:       I  isoleucine            Y  tyrosine
132:       K  lysine                Z  glutamate/glutamine
133:       L  leucine               X  any
134:       M  methionine            *  translation stop
135:       N  asparagine            -  gap of indeterminate length
136:      */
137:     $fasta_allowed['prot'] = 'ABCDEFGHIKLMNPQRSTUVWYZX*-';
138: 
139:     $queries = array();
140: 
141:     //we have just one sequence without header
142:     if (strpos($query, '>') === FALSE) {
143:         $query = trim($query);
144:         if (preg_match('/^[0-9\\s' . $fasta_allowed[$type] . ']+$/im', $query))
145:             if (preg_match('/(\n\n|\r\n\r\n|\n\r\n\r)/im', $query)) {
146:                 throw new Exception('FASTA sequence invalid! If you want to specify multiple sequences, add headers. If you want to query a single sequence, remove blank lines.');
147:             } else {
148:                 $queries[] = $query;
149:             }
150:         else
151:             throw new Exception('FASTA sequence invalid!');
152:     } else {
153:         $require_next_line_header = true;
154:         $lines = explode(PHP_EOL, $query);
155:         foreach ($lines as $nr => $line) {
156:             $line = trim($line);
157:             // header line
158:             if (strpos($line, '>') === 0) {
159:                 $require_next_line_header = false;
160:                 $queries [] = "";
161:                 $current = &$queries[count($queries) - 1];
162:                 $current.=$line;
163:             }
164:             // content line, check for correct sequence
165:             else if (strlen($line) > 0) {
166:                 if ($require_next_line_header)
167:                     throw new Exception(sprintf('Missing FASTA Header at line number %d', $nr));
168:                 if (!preg_match('/^[' . $fasta_allowed[$type] . ']+$/i', $line))
169:                     throw new Exception(sprintf('FASTA sequence invalid in line %d!', $nr));
170:                 $current.="\n" . $line;
171:             }
172:             //empty line, require a new header
173:             else {
174:                 $require_next_line_header = true;
175:             }
176:         }
177:     }
178:     return $queries;
179: }
180: 
181: ?>
182: 
tbro API documentation generated by ApiGen 2.8.0