|
@@ -396,7 +396,13 @@ class OBOImporter extends TripalImporter {
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
public function postRun() {
|
|
public function postRun() {
|
|
- $this->load_cvtermpath($this->newcvs);
|
|
|
|
|
|
+
|
|
|
|
+ // Upate the cvtermpath table for each newly added CV.
|
|
|
|
+ $this->logMessage("Updating cvtermpath table. This may take a while...");
|
|
|
|
+ foreach ($this->newcvs as $namespace => $cvid) {
|
|
|
|
+ $this->logMessage("- Loading paths for @vocab", array('@vocab' => $namespace));
|
|
|
|
+ tripal_update_cvtermpath($cvid);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
* A wrapper function for importing the user specified OBO file into Chado by
|
|
* A wrapper function for importing the user specified OBO file into Chado by
|
|
@@ -464,7 +470,7 @@ class OBOImporter extends TripalImporter {
|
|
tripal_insert_obo($obo_name, $file);
|
|
tripal_insert_obo($obo_name, $file);
|
|
}
|
|
}
|
|
|
|
|
|
- $success = $this->loadOBO_v1_2($file, $this->newcvs);
|
|
|
|
|
|
+ $success = $this->loadOBO_v1_2($file);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -485,8 +491,6 @@ class OBOImporter extends TripalImporter {
|
|
*/
|
|
*/
|
|
private function loadOBO_v1_2_url($obo_name, $url, $is_new = TRUE) {
|
|
private function loadOBO_v1_2_url($obo_name, $url, $is_new = TRUE) {
|
|
|
|
|
|
- $newcvs = array();
|
|
|
|
-
|
|
|
|
// first download the OBO
|
|
// first download the OBO
|
|
$temp = tempnam(sys_get_temp_dir(), 'obo_');
|
|
$temp = tempnam(sys_get_temp_dir(), 'obo_');
|
|
print "Downloading URL $url, saving to $temp\n";
|
|
print "Downloading URL $url, saving to $temp\n";
|
|
@@ -509,34 +513,12 @@ class OBOImporter extends TripalImporter {
|
|
}
|
|
}
|
|
|
|
|
|
// second, parse the OBO
|
|
// second, parse the OBO
|
|
- $this->loadOBO_v1_2($temp, $newcvs);
|
|
|
|
-
|
|
|
|
- // update the cvtermpath table
|
|
|
|
- $this->load_cvtermpath($newcvs);
|
|
|
|
|
|
+ $this->loadOBO_v1_2($temp);
|
|
|
|
|
|
// now remove the temp file
|
|
// now remove the temp file
|
|
unlink($temp);
|
|
unlink($temp);
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * A function for executing the cvtermpath function of Chado. This function
|
|
|
|
- * populates the cvtermpath table of Chado for quick lookup of term
|
|
|
|
- * relationships
|
|
|
|
- *
|
|
|
|
- * @param $newcvs
|
|
|
|
- * An associative array of controlled vocabularies to update. The key must be
|
|
|
|
- * the name of the vocabulary and the value the cv_id from the cv table of chado.
|
|
|
|
- *
|
|
|
|
- * @ingroup tripal_obo_loader
|
|
|
|
- */
|
|
|
|
- private function load_cvtermpath($newcvs) {
|
|
|
|
-
|
|
|
|
- print "\nUpdating cvtermpath table. This may take a while...\n";
|
|
|
|
- foreach ($newcvs as $namespace => $cvid) {
|
|
|
|
- tripal_update_cvtermpath($cvid);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* Imports a given OBO file into Chado. This function is usually called by
|
|
* Imports a given OBO file into Chado. This function is usually called by
|
|
* one of three wrapper functions: loadOBO_v1_2_id,
|
|
* one of three wrapper functions: loadOBO_v1_2_id,
|
|
@@ -546,15 +528,10 @@ class OBOImporter extends TripalImporter {
|
|
*
|
|
*
|
|
* @param $flie
|
|
* @param $flie
|
|
* The full path to the OBO file on the file system
|
|
* The full path to the OBO file on the file system
|
|
- * @param $newcvs
|
|
|
|
- * An empty array passed by reference that upon return will contain the list
|
|
|
|
- * of newly added vocabularies. The key will contain the CV name and the
|
|
|
|
- * value the new cv_id
|
|
|
|
- *
|
|
|
|
*
|
|
*
|
|
* @ingroup tripal_obo_loader
|
|
* @ingroup tripal_obo_loader
|
|
*/
|
|
*/
|
|
- private function loadOBO_v1_2($file, &$newcvs) {
|
|
|
|
|
|
+ private function loadOBO_v1_2($file) {
|
|
|
|
|
|
$header = array();
|
|
$header = array();
|
|
$ret = array();
|
|
$ret = array();
|
|
@@ -577,7 +554,7 @@ class OBOImporter extends TripalImporter {
|
|
if (!$defaultcv) {
|
|
if (!$defaultcv) {
|
|
throw new Exception('Cannot add namespace ' . $header['default-namespace'][0]);
|
|
throw new Exception('Cannot add namespace ' . $header['default-namespace'][0]);
|
|
}
|
|
}
|
|
- $newcvs[$header['default-namespace'][0]] = $defaultcv->cv_id;
|
|
|
|
|
|
+ $this->newcvs[$header['default-namespace'][0]] = $defaultcv->cv_id;
|
|
}
|
|
}
|
|
// If the 'default-namespace' is missing.
|
|
// If the 'default-namespace' is missing.
|
|
else {
|
|
else {
|
|
@@ -589,7 +566,7 @@ class OBOImporter extends TripalImporter {
|
|
if (!$defaultcv) {
|
|
if (!$defaultcv) {
|
|
throw new Exception('Cannot add namespace ' . strtoupper($header['ontology'][0]));
|
|
throw new Exception('Cannot add namespace ' . strtoupper($header['ontology'][0]));
|
|
}
|
|
}
|
|
- $newcvs[strtoupper(strtoupper($header['ontology'][0]))] = $defaultcv->cv_id;
|
|
|
|
|
|
+ $this->newcvs[strtoupper(strtoupper($header['ontology'][0]))] = $defaultcv->cv_id;
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
throw new Exception("Could not find a namespace for this OBO file: $file");
|
|
throw new Exception("Could not find a namespace for this OBO file: $file");
|
|
@@ -601,11 +578,11 @@ class OBOImporter extends TripalImporter {
|
|
}!
|
|
}!
|
|
// Add any typedefs to the vocabulary first.
|
|
// Add any typedefs to the vocabulary first.
|
|
$this->logMessage("Step 2: Loading type defs...");
|
|
$this->logMessage("Step 2: Loading type defs...");
|
|
- $this->loadTypeDefs($defaultcv, $newcvs, $default_db);
|
|
|
|
|
|
+ $this->loadTypeDefs($defaultcv, $default_db);
|
|
|
|
|
|
// Next add terms to the vocabulary.
|
|
// Next add terms to the vocabulary.
|
|
$this->logMessage("Step 3: Loading terms...");
|
|
$this->logMessage("Step 3: Loading terms...");
|
|
- if (!$this->processTerms($defaultcv, $newcvs, $default_db)) {
|
|
|
|
|
|
+ if (!$this->processTerms($defaultcv, $default_db)) {
|
|
throw new Exception('Cannot add terms from this ontology');
|
|
throw new Exception('Cannot add terms from this ontology');
|
|
}
|
|
}
|
|
|
|
|
|
@@ -618,15 +595,12 @@ class OBOImporter extends TripalImporter {
|
|
* @param $defaultcv
|
|
* @param $defaultcv
|
|
* A database object containing a record from the cv table for the
|
|
* A database object containing a record from the cv table for the
|
|
* default controlled vocabulary
|
|
* default controlled vocabulary
|
|
- * @param $newcvs
|
|
|
|
- * An associative array of controlled vocabularies for this OBO. The key must be
|
|
|
|
- * the name of the vocabulary and the value the cv_id from the cv table of chado.
|
|
|
|
* @param $default_db
|
|
* @param $default_db
|
|
* The name of the default database.
|
|
* The name of the default database.
|
|
*
|
|
*
|
|
* @ingroup tripal_obo_loader
|
|
* @ingroup tripal_obo_loader
|
|
*/
|
|
*/
|
|
- private function loadTypeDefs($defaultcv, $newcvs, $default_db) {
|
|
|
|
|
|
+ private function loadTypeDefs($defaultcv, $default_db) {
|
|
$sql = "SELECT * FROM {tripal_obo_temp} WHERE type = 'Typedef' ";
|
|
$sql = "SELECT * FROM {tripal_obo_temp} WHERE type = 'Typedef' ";
|
|
$typedefs = chado_query($sql);
|
|
$typedefs = chado_query($sql);
|
|
|
|
|
|
@@ -644,7 +618,7 @@ class OBOImporter extends TripalImporter {
|
|
foreach ($typedefs as $typedef) {
|
|
foreach ($typedefs as $typedef) {
|
|
$this->setItemsHandled($i);
|
|
$this->setItemsHandled($i);
|
|
$term = unserialize(base64_decode($typedef->stanza));
|
|
$term = unserialize(base64_decode($typedef->stanza));
|
|
- $this->processTerm($term, $defaultcv->name, 1, $newcvs, $default_db);
|
|
|
|
|
|
+ $this->processTerm($term, $defaultcv->name, 1, $default_db);
|
|
$i++;
|
|
$i++;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -660,13 +634,10 @@ class OBOImporter extends TripalImporter {
|
|
* @param $defaultcv
|
|
* @param $defaultcv
|
|
* A database object containing a record from the cv table for the
|
|
* A database object containing a record from the cv table for the
|
|
* default controlled vocabulary
|
|
* default controlled vocabulary
|
|
- * @param $newcvs
|
|
|
|
- * An associative array of controlled vocabularies for this OBO. The key must be
|
|
|
|
- * the name of the vocabulary and the value the cv_id from the cv table of chado.
|
|
|
|
* @param $default_db
|
|
* @param $default_db
|
|
* The name of the default database.
|
|
* The name of the default database.
|
|
*/
|
|
*/
|
|
- private function processTerms($defaultcv, &$newcvs, $default_db) {
|
|
|
|
|
|
+ private function processTerms($defaultcv, $default_db) {
|
|
$i = 0;
|
|
$i = 0;
|
|
|
|
|
|
// Iterate through each term from the OBO file and add it.
|
|
// Iterate through each term from the OBO file and add it.
|
|
@@ -693,7 +664,7 @@ class OBOImporter extends TripalImporter {
|
|
$this->setItemsHandled($i);
|
|
$this->setItemsHandled($i);
|
|
|
|
|
|
// Add/update this term.
|
|
// Add/update this term.
|
|
- if (!$this->processTerm($term, $defaultcv->name, 0, $newcvs, $default_db)) {
|
|
|
|
|
|
+ if (!$this->processTerm($term, $defaultcv->name, 0, $default_db)) {
|
|
throw new Exception("Failed to process terms from the ontology");
|
|
throw new Exception("Failed to process terms from the ontology");
|
|
}
|
|
}
|
|
|
|
|
|
@@ -718,7 +689,7 @@ class OBOImporter extends TripalImporter {
|
|
*
|
|
*
|
|
* @ingroup tripal_obo_loader
|
|
* @ingroup tripal_obo_loader
|
|
*/
|
|
*/
|
|
- private function processTerm($term, $defaultcv, $is_relationship = 0, &$newcvs, $default_db) {
|
|
|
|
|
|
+ private function processTerm($term, $defaultcv, $is_relationship = 0, $default_db) {
|
|
|
|
|
|
// make sure we have a namespace for this term
|
|
// make sure we have a namespace for this term
|
|
if (!array_key_exists('namespace', $term) and !($defaultcv or $defaultcv == '')) {
|
|
if (!array_key_exists('namespace', $term) and !($defaultcv or $defaultcv == '')) {
|
|
@@ -762,7 +733,7 @@ class OBOImporter extends TripalImporter {
|
|
chado_query($sql, array(':cvterm_id' => $cvterm->cvterm_id));
|
|
chado_query($sql, array(':cvterm_id' => $cvterm->cvterm_id));
|
|
|
|
|
|
if (array_key_exists('namespace', $term)) {
|
|
if (array_key_exists('namespace', $term)) {
|
|
- $newcvs[$term['namespace'][0]] = $cvterm->cv_id;
|
|
|
|
|
|
+ $this->newcvs[$term['namespace'][0]] = $cvterm->cv_id;
|
|
}
|
|
}
|
|
|
|
|
|
// now handle other properites
|
|
// now handle other properites
|