1: <?php
2:
3: namespace cli_import;
4:
5: require_once ROOT . 'classes/AbstractImporter.php';
6:
7: 8: 9:
10: abstract class Importer_Annotations_Dbxref extends AbstractImporter {
11:
12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 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:
35: $param_accession = null;
36: $param_dbname = null;
37: $param_feature_uniq = null;
38:
39:
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:
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:
58: $statement_insert_feature_dbxref->execute();
59: $dbxref_inserted += $statement_insert_feature_dbxref->rowCount();
60:
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: 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: