Browse Source

Merge pull request #927 from tripal/926-tv3-GFF_ontology_import

Fixed loadOntology function in the GFF3 importer to not return if it …
Stephen Ficklin 5 years ago
parent
commit
707a529ca7
2 changed files with 54 additions and 58 deletions
  1. 25 22
      tripal_chado/includes/TripalImporter/GFF3Importer.inc
  2. 29 36
      tripal_chado/tripal_chado.install

+ 25 - 22
tripal_chado/includes/TripalImporter/GFF3Importer.inc

@@ -860,57 +860,60 @@ class GFF3Importer extends TripalImporter {
               throw new Exception(t("Cound not save record in temporary table, Cannot continue.", []));
             }
           }
-          // add/update the featureloc if the landmark and the ID are not the same
-          // if they are the same then this entry in the GFF is probably a landmark identifier
+          // Add/update the featureloc if the landmark and the ID are not the
+          // same if they are the same then this entry in the GFF is probably
+          // a landmark identifier.
           if (strcmp($landmark, $attr_uniquename) != 0) {
             $this->loadFeatureLoc($feature, $organism,
               $landmark, $fmin, $fmax, $strand, $phase, $attr_fmin_partial,
               $attr_fmax_partial, $attr_residue_info, $attr_locgroup);
           }
 
-          // add any aliases for this feature
+          // Add any aliases for this feature.
           if (array_key_exists('Alias', $tags)) {
             $this->loadAlias($feature, $tags['Alias']);
           }
-          // add any dbxrefs for this feature
+          // Add any dbxrefs for this feature.
           if (array_key_exists('Dbxref', $tags)) {
             $this->loadDbxref($feature, $tags['Dbxref']);
           }
-          // add any ontology terms for this feature
+          // Add any ontology terms for this feature.
           if (array_key_exists('Ontology_term', $tags)) {
             $this->loadOntology($feature, $tags['Ontology_term']);
           }
-          // add parent relationships
+          // Add parent relationships.
           if (array_key_exists('Parent', $tags)) {
             $this->loadParents($feature, $cvterm, $tags['Parent'],
               $feature_organism->organism_id, $strand, $phase, $fmin, $fmax);
           }
 
-          // add target relationships
+          // Add target relationships.
           if (array_key_exists('Target', $tags)) {
             $this->loadTarget($feature, $tags, $target_organism_id, $target_type, $create_target, $attr_locgroup);
           }
-          // add gap information.  This goes in simply as a property
+          // Add gap information.  This goes in simply as a property.
           if (array_key_exists('Gap', $tags)) {
             foreach ($tags['Gap'] as $value) {
               $this->loadProperty($feature, 'Gap', $value);
             }
           }
-          // add notes. This goes in simply as a property
+          // Add notes. This goes in simply as a property.
           if (array_key_exists('Note', $tags)) {
             foreach ($tags['Note'] as $value) {
               $this->loadProperty($feature, 'Note', $value);
             }
           }
-          // add the Derives_from relationship (e.g. polycistronic genes).
+          // Add the Derives_from relationship (e.g. polycistronic genes).
           if (array_key_exists('Derives_from', $tags)) {
             $this->loadDerivesFrom($feature, $cvterm, $tags['Derives_from'][0],
               $feature_organism, $fmin, $fmax);
           }
-          // add in the GFF3_source dbxref so that GBrowse can find the feature using the source column
+          // Add in the GFF3_source dbxref so that GBrowse can find the feature
+          // using the source column.
           $source_ref = ['GFF_source:' . $source];
           $this->loadDbxref($feature, $source_ref);
-          // add any additional attributes
+
+          // Add any additional attributes.
           if ($attr_others) {
             foreach ($attr_others as $tag_name => $values) {
               foreach ($values as $value) {
@@ -1430,7 +1433,7 @@ class GFF3Importer extends TripalImporter {
         $db = chado_select_record('db', ['db_id'], ['name' => "$dbname"]);
         if (sizeof($db) == 0) {
           $this->logMessage("Database, $dbname, is not present. Cannot associate term: $dbname:$accession.", [], TRIPAL_WARNING);
-          return 0;
+          continue;
         }
       }
       $db = $db[0];
@@ -1440,7 +1443,7 @@ class GFF3Importer extends TripalImporter {
         ['accession' => $accession, 'db_id' => $db->db_id]);
       if (sizeof($dbxref) == 0) {
         $this->logMessage("Accession, $accession is missing for reference: $dbname:$accession.", [], TRIPAL_WARNING);
-        return 0;
+        continue;
       }
       $dbxref = $dbxref[0];
 
@@ -1455,7 +1458,7 @@ class GFF3Importer extends TripalImporter {
         ]);
         if (sizeof($cvterm) == 0) {
           $this->logMessage("CV Term is missing for reference: $dbname:$accession.", [], TRIPAL_WARNING);
-          return 0;
+          continue;
         }
       }
       $cvterm = $cvterm[0];
@@ -1481,11 +1484,10 @@ class GFF3Importer extends TripalImporter {
 
         if (!$success) {
           $this->logMessage("Failed to insert ontology term: $dbname:$accession.", [], TRIPAL_WARNING);
-          return 0;
+          continue;
         }
       }
     }
-    return 1;
   }
 
   /**
@@ -1971,7 +1973,7 @@ class GFF3Importer extends TripalImporter {
    */
   private function loadProperty($feature, $property, $value) {
 
-    // first make sure the cvterm exists.  if not, then add it
+    // First make sure the cvterm exists.  if not, then add it.
     $select = [
       'name' => $property,
       'cv_id' => [
@@ -1980,14 +1982,15 @@ class GFF3Importer extends TripalImporter {
     ];
     $result = chado_select_record('cvterm', ['*'], $select);
 
-    // if we don't have a property like this already, then add it otherwise, just return
+    // If we don't have a property like this already, then add it otherwise,
+    // just return.
     if (count($result) == 0) {
       $term = [
-        'id' => "null:$property",
+        'id' => "local:$property",
         'name' => $property,
-        'namespace' => 'feature_property',
         'is_obsolete' => 0,
         'cv_name' => 'feature_property',
+        'db_name' => 'local',
         'is_relationship' => FALSE,
       ];
       $cvterm = (object) chado_insert_cvterm($term, ['update_existing' => FALSE]);
@@ -2001,7 +2004,7 @@ class GFF3Importer extends TripalImporter {
     }
 
 
-    // check to see if the property already exists for this feature
+    // Check to see if the property already exists for this feature
     // if it does but the value is unique then increment the rank and add it.
     // if the value is not unique then don't add it.
     $add = 1;

+ 29 - 36
tripal_chado/tripal_chado.install

@@ -1894,56 +1894,49 @@ function tripal_chado_update_7335() {
  */
 function tripal_chado_update_7336() {
 
-  $bundles = field_info_instances('TripalEntity');
+  try {
+    $bundles = field_info_instances('TripalEntity');
 
-  foreach ($bundles as $bundle_name => $fields) {
+    foreach ($bundles as $bundle_name => $fields) {
 
-    $bundle = tripal_load_bundle_entity(['name' => $bundle_name]);
-    $base = $bundle->data_table;
+      $bundle = tripal_load_bundle_entity(['name' => $bundle_name]);
+      $base = $bundle->data_table;
 
-    $contact_table = $base . '_contact';
-    if (chado_table_exists($contact_table)) {
+      $contact_table = $base . '_contact';
+      if (chado_table_exists($contact_table)) {
 
-      $field_name = $base . '_contact';
-      $instance_info = field_info_instance('TripalEntity', $field_name, $bundle_name);
+        $field_name = $base . '_contact';
+        $instance_info = field_info_instance('TripalEntity', $field_name, $bundle_name);
 
-      if ($instance_info) {
-        $instance_info['type'] = 'chado_linker__contact';
-        $instance_info['widget']['type'] = 'chado_linker__contact_widget';
-        $instance_info['formatter']['type'] = 'chado_linker__contact_widget';
-        field_update_instance($instance_info);
+        if ($instance_info) {
+          $instance_info['type'] = 'chado_linker__contact';
+          $instance_info['widget']['type'] = 'chado_linker__contact_widget';
+          $instance_info['formatter']['type'] = 'chado_linker__contact_widget';
+          field_update_instance($instance_info);
+        }
       }
     }
   }
+  catch (\PDOException $e) {
+    $error = $e->getMessage();
+    throw new DrupalUpdateException('Could not perform update: '. $error);
+  }
 }
 
 /**
  * Update the NCBITaxon DB entry.
  */
-function tripal_chado_update_7337() {
-
-  chado_insert_db(array(
-    'name' => 'NCBITaxon',
-    'description' => 'NCBI organismal classification.',
-    'url' => 'http://www.berkeleybop.org/ontologies/ncbitaxon/',
-    'urlprefix' => 'https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id={accession}',
-  ));
-}
-
-/**
- * Correctly flag SOFP terms as "not" relationships, allowing the mview to
- * populate them.
- */
-function tripal_chado_update_7338() {
-
+function tripal_chado_update_7337(){
   try {
-    // Get all SOFP terms and set their is_relationshiptype to 0
-
-    tripal_chado_fix_legacy_SOFP_7338();
-
-  } catch (\PDOException $e) {
+    chado_insert_db(array(
+      'name' => 'NCBITaxon',
+      'description' => 'NCBI organismal classification.',
+      'url' => 'http://www.berkeleybop.org/ontologies/ncbitaxon/',
+      'urlprefix' => 'https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id={accession}',
+    ));
+  }
+  catch (\PDOException $e) {
     $error = $e->getMessage();
-    throw new DrupalUpdateException('Could not perform update: ' . $error);
+    throw new DrupalUpdateException('Could not perform update: '. $error);
   }
-
 }