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:  * importer for textual descriptions
 9:  */
10: class Importer_Annotations_Description extends AbstractImporter {
11: 
12:     /**
13:      * @inheritDoc
14:      * @param String $separator defaults to TAB
15:      */
16:     static function import($options, $separator = "\t") {
17: 
18:         $filename = $options['file'];
19:         $lines_total = trim(`wc -l $filename | cut -d' ' -f1`);
20:         self::setLineCount($lines_total);
21: 
22:         global $db;
23:         $lines_imported = 0;
24:         $descriptions_added = 0;
25:         try {
26:             $db->beginTransaction();
27:             #shared parameters
28:             $description = null;
29:             $param_feature_uniq = null;
30: 
31:             //statement to add featureprop to feature
32:             $statement_insert_featureprop = $db->prepare(
33:                     sprintf('INSERT INTO featureprop (feature_id, type_id, rank, value) VALUES ((%s), :type_id, 0, :description)', 'SELECT feature_id FROM feature WHERE uniquename=:uniquename AND organism_id=:organism ')
34:             );
35:             $statement_insert_featureprop->bindValue('type_id', CV_ANNOTATION_DESC, PDO::PARAM_INT);
36:             $statement_insert_featureprop->bindParam('uniquename', $param_feature_uniq, PDO::PARAM_STR);
37:             $statement_insert_featureprop->bindParam('description', $description, PDO::PARAM_STR);
38:             $statement_insert_featureprop->bindValue('organism', DB_ORGANISM_ID, PDO::PARAM_INT);
39: 
40:             $file = fopen($filename, 'r');
41:             while (($line = fgetcsv($file, 0, $separator)) !== false) {
42:                 if (count($line) == 0)
43:                     continue;
44:                 $feature = $line[0];
45:                 $description = $line[1];
46:                 $param_feature_uniq = IMPORT_PREFIX . "_" . $feature;
47: 
48:                 $statement_insert_featureprop->execute();
49:                 $descriptions_added+=$statement_insert_featureprop->rowCount();
50: 
51: 
52:                 self::updateProgress(++$lines_imported);
53:             }
54:             self::preCommitMsg();
55:             if (!$db->commit()) {
56:                 $err = $db->errorInfo();
57:                 throw new \ErrorException($err[2], ERRCODE_TRANSACTION_NOT_COMPLETED, 1);
58:             }
59:         } catch (\Exception $error) {
60:             $db->rollback();
61:             throw $error;
62:         }
63:         return array(LINES_IMPORTED => $lines_imported, 'descriptions_added' => $descriptions_added);
64:     }
65: 
66:     /**
67:      * @inheritDoc
68:      */
69:     public static function CLI_longHelp() {
70:         return <<<EOF
71: Tab-Separated file with column 1: feature_id and column 2: feature description
72:    
73: \033[0;31mThis import requires a successful Sequence ID Import!\033[0m
74: EOF;
75:     }
76: 
77:     /**
78:      * @inheritDoc
79:      */
80:     public static function CLI_commandDescription() {
81:         return 'import feature descriptions';
82:     }
83: 
84:     /**
85:      * @inheritDoc
86:      */
87:     public static function CLI_commandName() {
88:         return 'annotation_description';
89:     }
90: 
91: }
92: 
93: ?>
94: 
tbro API documentation generated by ApiGen 2.8.0