Skip to content

Commit a71b709

Browse files
committed
Merge branch 'develop'
2 parents 9f43091 + 3b3b440 commit a71b709

File tree

3 files changed

+62
-46
lines changed

3 files changed

+62
-46
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ If you use TBro please cite this publication: [![DOI](https://img.shields.io/bad
1111
> Ankenbrand MJ, Weber L, Becker D, Förster F, and Bemm F. "TBro: Visualization and Management of de Novo Transcriptomes." Database 2016 (October 18, 2016): baw146. doi:10.1093/database/baw146.
1212
1313
## Changes
14+
### 1.1.2 <2017-03-01 We>
15+
- Improve MapMan importer
16+
1417
### 1.1.1 <2016-09-28 Mo>
1518
- Custom annotations for unigenes
1619

src/cli/import/commands/Importer_Annotations_MapMan.php

Lines changed: 56 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
class Importer_Annotations_MapMan extends Importer_Annotations_Dbxref {
99

10+
private static $dbxrefs = array();
11+
private static $cvterms = array();
12+
1013
/**
1114
* @inheritDoc
1215
*/
@@ -97,27 +100,7 @@ public static function import($options) {
97100
*/
98101
$stm_link_dbxref = $db->prepare('INSERT INTO feature_dbxref (feature_id, dbxref_id) VALUES (?,?)');
99102

100-
/**
101-
* get dbxref id. if non-existant, create
102-
* parameters: :dbname, :accession
103-
* returns: dbxref_id
104-
*/
105-
$stm_try_insert_dbxref_id = $db->prepare("SELECT * FROM get_or_insert_dbxref(:dbname, :accession)");
106103

107-
/**
108-
* get cvterm_id. if non-existant, create
109-
* parameters: name, definition, dbxref_id dbxref_id, dbxref_id
110-
* returns: cvterm_id
111-
*/
112-
$stm_try_insert_cvterm = $db->prepare(<<<EOF
113-
WITH new_row AS (
114-
INSERT INTO cvterm (name, definition, cv_id, dbxref_id) SELECT ?,?,(SELECT cv_id FROM cv WHERE name='local'),? WHERE NOT EXISTS (SELECT 1 FROM cvterm WHERE dbxref_id = ?) RETURNING cvterm_id
115-
)
116-
SELECT cvterm_id FROM new_row
117-
UNION
118-
SELECT cvterm_id FROM cvterm WHERE dbxref_id = ?;
119-
EOF
120-
);
121104
/**
122105
* insert cvtermprop if non-existant with these values
123106
* parameters: cvterm_id, type_id, value, cvterm_id, type_id, cvterm_id, type_id, value
@@ -129,37 +112,19 @@ public static function import($options) {
129112
130113
EOF
131114
);
132-
$dbxrefs = array();
133-
$cvterms = array();
134115

135116
$file = fopen($filename, 'r');
136117
//skip header line
137118
fgets($file);
138-
while (($line = fgetcsv($file, 0, "\t")) != false) {
119+
while (($line = fgetcsv($file, 0, "\t", "'")) != false) {
139120
//if..elseif..else: check which section we are in
140121
// header, looks like <BINCODE>\t<H_DESC>
141122
if (count($line) == 2) {
142-
$stm_try_insert_dbxref_id->execute(array(
143-
// parameters: :dbname, :accession
144-
// returns: dbxref_id
145-
self::$db_name,
146-
$line[0]
147-
));
148-
$dbxref_id = $stm_try_insert_dbxref_id->fetchColumn();
149-
$dbxrefs[$line[0]] = $dbxref_id;
150-
$stm_try_insert_cvterm->execute(array(
151-
// parameters: name, definition, dbxref_id dbxref_id, dbxref_id
152-
// returns: cvterm_id
153-
$line[0],
154-
$line[1],
155-
$dbxref_id,
156-
$dbxref_id,
157-
$dbxref_id
158-
));
159-
$cvterms[$line[0]] = $stm_try_insert_cvterm->fetchColumn();
123+
self::try_insert_dbxref_cvterm($line[0], $line[1]);
160124
} else if (count($line) == 5) {
161125
//mapping, looks like <BINCODE>, <H_DESC>, <srcfeature_name>, <feature_description>, "T"
162126
if ($line[4] == 'T') {
127+
self::try_insert_dbxref_cvterm($line[0], $line[1]);
163128
$stm_get_parentfeature->execute(array(
164129
':object_name' => $line[2],
165130
':organism_id' => DB_ORGANISM_ID,
@@ -192,13 +157,14 @@ public static function import($options) {
192157
$stm_link_dbxref->execute(array(
193158
// parameters: feature_id, cvterm_id
194159
$feature_id,
195-
$dbxrefs[$line[0]]
160+
self::$dbxrefs[$line[0]]
196161
));
197162
} else
198163
//footer, looks like: <BINCODE>, <H_DESC>, <CHEM>, <C_DESC>, "M"
199164
if ($line[4] == 'M') {
165+
self::try_insert_dbxref_cvterm($line[0], $line[1]);
200166
$val = sprintf("%s\t%s", $line[2], $line[3]);
201-
$cvterm_id = $cvterms[$line[0]];
167+
$cvterm_id = self::$cvterms[$line[0]];
202168
$stm_try_insert_cvtermprop->execute(array(
203169
//cvterm_id, type_id, value, cvterm_id, type_id, cvterm_id, type_id, value
204170
$cvterm_id,
@@ -236,6 +202,53 @@ public static function CLI_longHelp() {
236202
EOF;
237203
}
238204

205+
private static function try_insert_dbxref_cvterm($bincode, $desc){
206+
global $db;
207+
/**
208+
* get dbxref id. if non-existant, create
209+
* parameters: :dbname, :accession
210+
* returns: dbxref_id
211+
*/
212+
$stm_try_insert_dbxref_id = $db->prepare("SELECT * FROM get_or_insert_dbxref(:dbname, :accession)");
213+
/**
214+
* get cvterm_id. if non-existant, create
215+
* parameters: name, definition, dbxref_id dbxref_id, dbxref_id
216+
* returns: cvterm_id
217+
*/
218+
$stm_try_insert_cvterm = $db->prepare(<<<EOF
219+
WITH new_row AS (
220+
INSERT INTO cvterm (name, definition, cv_id, dbxref_id) SELECT ?,?,(SELECT cv_id FROM cv WHERE name='local'),? WHERE NOT EXISTS (SELECT 1 FROM cvterm WHERE dbxref_id = ?) RETURNING cvterm_id
221+
)
222+
SELECT cvterm_id FROM new_row
223+
UNION
224+
SELECT cvterm_id FROM cvterm WHERE dbxref_id = ?;
225+
EOF
226+
);
227+
if(!array_key_exists($bincode, self::$dbxrefs)){
228+
$stm_try_insert_dbxref_id->execute(array(
229+
// parameters: :dbname, :accession
230+
// returns: dbxref_id
231+
self::$db_name,
232+
$bincode
233+
));
234+
$dbxref_id = $stm_try_insert_dbxref_id->fetchColumn();
235+
self::$dbxrefs[$bincode] = $dbxref_id;
236+
}
237+
$dbxref_id = self::$dbxrefs[$bincode];
238+
if(!array_key_exists($bincode, self::$cvterms)){
239+
$stm_try_insert_cvterm->execute(array(
240+
// parameters: name, definition, dbxref_id dbxref_id, dbxref_id
241+
// returns: cvterm_id
242+
$bincode,
243+
$desc,
244+
$dbxref_id,
245+
$dbxref_id,
246+
$dbxref_id
247+
));
248+
self::$cvterms[$bincode] = $stm_try_insert_cvterm->fetchColumn();
249+
}
250+
}
251+
239252
}
240253

241254
?>

src/web/wwwroot/index.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
require_once('TranscriptDB/webservices/cart/Sync.php');
3232
$smarty->assign('regexCartName', \webservices\cart\Sync::$regexCartName);
3333

34-
$smarty->assign('tbro_version', '1.1.1');
34+
$smarty->assign('tbro_version', '1.1.2');
3535
$smarty->assign('instance_title', INSTANCE_TITLE);
3636
$smarty->assign('logo_url', LOGO_URL);
3737

@@ -75,7 +75,7 @@ function requestVal($key, $regexp = "/^.*$/", $defaultvalue = "") {
7575
header('Location: ' . preg_replace('/([?&])logout(=[^&]+)?(&|$)/', '$1', $redir_url));
7676
die();
7777
}
78-
//standard LightOpenID login code, see LightOpenID documentation
78+
//standard LightOpenID login code, see LightOpenID documentation
7979
try {
8080
$openid = new LightOpenID($_SERVER['HTTP_HOST']);
8181
if (!$openid->mode) {
@@ -155,7 +155,7 @@ function display_feature($organism, $release, $name) {
155155

156156
global $db;
157157
$stm = $db->prepare(<<<EOF
158-
SELECT feature_id
158+
SELECT feature_id
159159
FROM feature JOIN dbxref ON (feature.dbxref_id = dbxref.dbxref_id)
160160
WHERE organism_id = ? AND accession=? AND name=?
161161
EOF

0 commit comments

Comments
 (0)