1: <?php
2:
3: namespace cli_import;
4:
5: require_once ROOT . 'classes/AbstractImporter.php';
6:
7: 8: 9:
10: class Importer_Annotations_Description extends AbstractImporter {
11:
12: 13: 14: 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:
28: $description = null;
29: $param_feature_uniq = null;
30:
31:
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: 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: 79:
80: public static function CLI_commandDescription() {
81: return 'import feature descriptions';
82: }
83:
84: 85: 86:
87: public static function CLI_commandName() {
88: return 'annotation_description';
89: }
90:
91: }
92:
93: ?>
94: