Overview

Namespaces

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

Classes

  • AbstractImporter
  • Importer_Annotations_Dbxref
  • Importer_Annotations_Description
  • Importer_Annotations_EC
  • Importer_Annotations_GO
  • Importer_Annotations_Interpro
  • Importer_Annotations_MapMan
  • Importer_Annotations_Repeatmasker
  • Importer_Differential_Expressions
  • Importer_Expressions
  • Importer_Sequence_Ids
  • Importer_Sequences_FASTA

Interfaces

  • Importer
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: 
 3: namespace cli_import;
 4: 
 5: require_once ROOT . 'classes/AbstractImporter.php';
 6: 
 7: /**
 8:  * abstract database crossreference importer
 9:  */
10: abstract class Importer_Annotations_Dbxref extends AbstractImporter {
11: 
12:     /**
13:      * takes a CSV as $options['file']
14:      * @global \PDO $db
15:      * @param Array $options user-specified command-line options
16:      * @param int $feature_pos column with feature name
17:      * @param int $dbxref_pos column with crossref
18:      * @param String $separator column separator, defaults to TAB
19:      * @return array to be displayed as table
20:      * @throws Exception
21:      * @throws ErrorException
22:      */
23:     static function _import($options, $feature_pos = 0, $dbxref_pos = 1, $separator = "\t") {
24: 
25:         $filename = $options['file'];
26:         $lines_total = trim(`wc -l $filename | cut -d' ' -f1`);
27:         self::setLineCount($lines_total);
28: 
29:         global $db;
30:         $lines_imported = 0;
31:         $dbxref_inserted = 0;
32:         try {
33:             $db->beginTransaction();
34:             #shared parameters
35:             $param_accession = null;
36:             $param_dbname = null;
37:             $param_feature_uniq = null;
38: 
39:             //statement inserts feature_dbxref connection. creates dbxref if non-existant.
40:             $statement_insert_feature_dbxref = $db->prepare(
41:                     sprintf('INSERT INTO feature_dbxref (feature_id, dbxref_id) VALUES ((%s), get_or_insert_dbxref(:dbname, :accession))', 'SELECT feature_id FROM feature WHERE uniquename=:uniquename AND organism_id=:organism')
42:             );
43:             $statement_insert_feature_dbxref->bindParam('accession', $param_accession, PDO::PARAM_STR);
44:             $statement_insert_feature_dbxref->bindParam('dbname', $param_dbname, PDO::PARAM_STR);
45:             $statement_insert_feature_dbxref->bindParam('uniquename', $param_feature_uniq, PDO::PARAM_STR);
46:             $statement_insert_feature_dbxref->bindValue('organism', DB_ORGANISM_ID, PDO::PARAM_INT);
47: 
48:             $file = fopen($filename, 'r');
49:             while (($line = fgetcsv($file, 0, $separator)) !== false) {
50:                 //skip empty lines
51:                 if (count($line) == 0)
52:                     continue;
53:                 $feature = $line[$feature_pos];
54:                 $dbxref = $line[$dbxref_pos];
55:                 list($param_dbname, $param_accession) = explode(':', $dbxref);
56:                 $param_feature_uniq = IMPORT_PREFIX . "_" . $feature;
57:                 //execute insert statement
58:                 $statement_insert_feature_dbxref->execute();
59:                 $dbxref_inserted += $statement_insert_feature_dbxref->rowCount();
60:                 //update progress bar
61:                 self::updateProgress(++$lines_imported);
62:             }
63:             self::preCommitMsg();
64:             if (!$db->commit()) {
65:                 $err = $db->errorInfo();
66:                 throw new ErrorException($err[2], ERRCODE_TRANSACTION_NOT_COMPLETED, 1);
67:             }
68:         } catch (\Exception $error) {
69:             $db->rollback();
70:             throw $error;
71:         }
72:         return array(LINES_IMPORTED => $lines_imported, 'references_linked' => $dbxref_inserted);
73:     }
74: 
75:     /**
76:      * @inheritDoc
77:      */
78:     public static function CLI_longHelp() {
79:         return <<<EOF
80: \033[0;31mThis import requires a successful Map File Import!\033[0m
81: \033[0;31mThis import requires a successful Sequence File Import!\033[0m
82: EOF;
83:     }
84: 
85: }
86: 
87: ?>
88: 
tbro API documentation generated by ApiGen 2.8.0