Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
iimog committed Mar 1, 2017
2 parents 9f43091 + 3b3b440 commit a71b709
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 46 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ If you use TBro please cite this publication: [![DOI](https://img.shields.io/bad
> 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.
## Changes
### 1.1.2 <2017-03-01 We>
- Improve MapMan importer

### 1.1.1 <2016-09-28 Mo>
- Custom annotations for unigenes

Expand Down
99 changes: 56 additions & 43 deletions src/cli/import/commands/Importer_Annotations_MapMan.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

class Importer_Annotations_MapMan extends Importer_Annotations_Dbxref {

private static $dbxrefs = array();
private static $cvterms = array();

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -97,27 +100,7 @@ public static function import($options) {
*/
$stm_link_dbxref = $db->prepare('INSERT INTO feature_dbxref (feature_id, dbxref_id) VALUES (?,?)');

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

/**
* get cvterm_id. if non-existant, create
* parameters: name, definition, dbxref_id dbxref_id, dbxref_id
* returns: cvterm_id
*/
$stm_try_insert_cvterm = $db->prepare(<<<EOF
WITH new_row AS (
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
)
SELECT cvterm_id FROM new_row
UNION
SELECT cvterm_id FROM cvterm WHERE dbxref_id = ?;
EOF
);
/**
* insert cvtermprop if non-existant with these values
* parameters: cvterm_id, type_id, value, cvterm_id, type_id, cvterm_id, type_id, value
Expand All @@ -129,37 +112,19 @@ public static function import($options) {
EOF
);
$dbxrefs = array();
$cvterms = array();

$file = fopen($filename, 'r');
//skip header line
fgets($file);
while (($line = fgetcsv($file, 0, "\t")) != false) {
while (($line = fgetcsv($file, 0, "\t", "'")) != false) {
//if..elseif..else: check which section we are in
// header, looks like <BINCODE>\t<H_DESC>
if (count($line) == 2) {
$stm_try_insert_dbxref_id->execute(array(
// parameters: :dbname, :accession
// returns: dbxref_id
self::$db_name,
$line[0]
));
$dbxref_id = $stm_try_insert_dbxref_id->fetchColumn();
$dbxrefs[$line[0]] = $dbxref_id;
$stm_try_insert_cvterm->execute(array(
// parameters: name, definition, dbxref_id dbxref_id, dbxref_id
// returns: cvterm_id
$line[0],
$line[1],
$dbxref_id,
$dbxref_id,
$dbxref_id
));
$cvterms[$line[0]] = $stm_try_insert_cvterm->fetchColumn();
self::try_insert_dbxref_cvterm($line[0], $line[1]);
} else if (count($line) == 5) {
//mapping, looks like <BINCODE>, <H_DESC>, <srcfeature_name>, <feature_description>, "T"
if ($line[4] == 'T') {
self::try_insert_dbxref_cvterm($line[0], $line[1]);
$stm_get_parentfeature->execute(array(
':object_name' => $line[2],
':organism_id' => DB_ORGANISM_ID,
Expand Down Expand Up @@ -192,13 +157,14 @@ public static function import($options) {
$stm_link_dbxref->execute(array(
// parameters: feature_id, cvterm_id
$feature_id,
$dbxrefs[$line[0]]
self::$dbxrefs[$line[0]]
));
} else
//footer, looks like: <BINCODE>, <H_DESC>, <CHEM>, <C_DESC>, "M"
if ($line[4] == 'M') {
self::try_insert_dbxref_cvterm($line[0], $line[1]);
$val = sprintf("%s\t%s", $line[2], $line[3]);
$cvterm_id = $cvterms[$line[0]];
$cvterm_id = self::$cvterms[$line[0]];
$stm_try_insert_cvtermprop->execute(array(
//cvterm_id, type_id, value, cvterm_id, type_id, cvterm_id, type_id, value
$cvterm_id,
Expand Down Expand Up @@ -236,6 +202,53 @@ public static function CLI_longHelp() {
EOF;
}

private static function try_insert_dbxref_cvterm($bincode, $desc){
global $db;
/**
* get dbxref id. if non-existant, create
* parameters: :dbname, :accession
* returns: dbxref_id
*/
$stm_try_insert_dbxref_id = $db->prepare("SELECT * FROM get_or_insert_dbxref(:dbname, :accession)");
/**
* get cvterm_id. if non-existant, create
* parameters: name, definition, dbxref_id dbxref_id, dbxref_id
* returns: cvterm_id
*/
$stm_try_insert_cvterm = $db->prepare(<<<EOF
WITH new_row AS (
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
)
SELECT cvterm_id FROM new_row
UNION
SELECT cvterm_id FROM cvterm WHERE dbxref_id = ?;
EOF
);
if(!array_key_exists($bincode, self::$dbxrefs)){
$stm_try_insert_dbxref_id->execute(array(
// parameters: :dbname, :accession
// returns: dbxref_id
self::$db_name,
$bincode
));
$dbxref_id = $stm_try_insert_dbxref_id->fetchColumn();
self::$dbxrefs[$bincode] = $dbxref_id;
}
$dbxref_id = self::$dbxrefs[$bincode];
if(!array_key_exists($bincode, self::$cvterms)){
$stm_try_insert_cvterm->execute(array(
// parameters: name, definition, dbxref_id dbxref_id, dbxref_id
// returns: cvterm_id
$bincode,
$desc,
$dbxref_id,
$dbxref_id,
$dbxref_id
));
self::$cvterms[$bincode] = $stm_try_insert_cvterm->fetchColumn();
}
}

}

?>
6 changes: 3 additions & 3 deletions src/web/wwwroot/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
require_once('TranscriptDB/webservices/cart/Sync.php');
$smarty->assign('regexCartName', \webservices\cart\Sync::$regexCartName);

$smarty->assign('tbro_version', '1.1.1');
$smarty->assign('tbro_version', '1.1.2');
$smarty->assign('instance_title', INSTANCE_TITLE);
$smarty->assign('logo_url', LOGO_URL);

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

global $db;
$stm = $db->prepare(<<<EOF
SELECT feature_id
SELECT feature_id
FROM feature JOIN dbxref ON (feature.dbxref_id = dbxref.dbxref_id)
WHERE organism_id = ? AND accession=? AND name=?
EOF
Expand Down

0 comments on commit a71b709

Please sign in to comment.