Просмотр исходного кода

Fixed a few bugs with loading CHEBI

Stephen Ficklin 6 лет назад
Родитель
Сommit
c468d279f7

+ 1 - 3
tripal_chado/api/modules/tripal_chado.module.DEPRECATED.api.inc

@@ -209,9 +209,7 @@ function tripal_get_cvterm_select_options($cv_id, $rel_type = false) {
 /**
  * Duplicate of fill_cvtermpath() stored procedure in Chado.
  *
- * Identifies all of the root terms of the controlled vocabulary. These
- * root terms are then processed by calling the
- * chado_update_cvtermpath_root_loop() function on each one.
+ * Identifies all of the root terms of the controlled vocabulary. 
  *
  * @param $cvid
  *   The controlled vocabulary ID from the cv table of Chado (i.e. cv.cv_id).

+ 29 - 6
tripal_chado/includes/TripalImporter/OBOImporter.inc

@@ -1901,27 +1901,46 @@ class OBOImporter extends TripalImporter {
     $matches = [];
     if (preg_match('/\"(.*?)\".*(EXACT|NARROW|BROAD|RELATED)/', $synonym, $matches)) {
       $def = $matches[1];
-      $syn_type = $matches[2];
+      $syn_type = strtolower($matches[2]);
     }
     
     // Get the syn type cvterm.
     if (!$syn_type) {  
       $syn_type = 'exact';
     }
-    $syn_type = $this->syn_types[$syn_type];
+    $syn_type_term = $this->syn_types[$syn_type];
+    if (!$syn_type_term) {
+      throw new Exception(t('Cannot find synonym type: !type', ['!type' => $syn_type]));
+    }
+    
+    // The synonym can only be 255 chars in the cvtermsynonym table.
+    // to prevent faling we have to truncate.
+    if (strlen($def) > 255) {
+      $def = substr($def, 0, 252) . "...";
+    }
         
     // Now save the new synonym.
     $cvtermsynonym = new ChadoRecord('cvtermsynonym');
     $cvtermsynonym->setValues([
       'cvterm_id' => $cvterm_id,
       'synonym' => $def,
-      'type_id' => $syn_type->cvterm_id
     ]);
     
     // If the insert fails then catch the error and generate a more meaningful
     // message that helps with debugging.
     try {
-      $cvtermsynonym->insert();
+      // The unique constraint for the cvterm_synonym table is with the
+      // cvterm_id and the synonymn. It does not inclue the type_id.
+      // The CHEBI contains terms with the same synonym but with different
+      // types. For example:
+      // synonym: "2-chloro-N-(2-chloroethyl)-N-methylethanamine hydrochloride" EXACT IUPAC_NAME [IUPAC]
+      // synonym: "2-chloro-N-(2-chloroethyl)-N-methylethanamine hydrochloride" RELATED [ChemIDplus]
+      // In this case on the first one is added.  
+      // @todo: This is a deficiency with Chado that should be corrected.      
+      if (!$cvtermsynonym->find()) {
+        $cvtermsynonym->setValue('type_id', $syn_type_term->cvterm_id);        
+        $cvtermsynonym->insert();
+      }
     }
     catch (Exception $e) {
       throw new Exception(t('Cannot add synonym, "!synonym" to term: !id. ' .
@@ -2280,7 +2299,9 @@ class OBOImporter extends TripalImporter {
       'cvterm_id' => $cvterm_id,
       'dbxref_id' => $dbxref->getID(),
     ]);
-    $cvterm_dbxref->insert();
+    if (!$cvterm_dbxref->find()) {
+      $cvterm_dbxref->insert();
+    }
   }
 
   /**
@@ -2329,7 +2350,9 @@ class OBOImporter extends TripalImporter {
       'cvterm_id' => $cvterm_id,
       'dbxref_id' => $dbxref->getID(),
     ]);
-    $cvterm_dbxref->insert();
+    if (!$cvterm_dbxref->find()) {
+      $cvterm_dbxref->insert();
+    }
   }
 
   /**

+ 1 - 1
tripal_chado/includes/setup/tripal_chado.chado_vx_x.inc

@@ -513,7 +513,7 @@ function tripal_chado_add_cv_root_mview_mview() {
       INNER JOIN cv CV on CV.cv_id = CVT.cv_id
     WHERE CVTR.object_id not in
       (SELECT subject_id FROM cvterm_relationship)
-    AND CVT.is_relationshiptype = 0
+    AND CVT.is_relationshiptype = 0 AND CVT.is_obsolete = 0
   ";
 
   // Create the MView