Browse Source

Fixed bug in tripal_get_organism_scientific_name and in TripalTaxonomy Importer

Stephen Ficklin 7 years ago
parent
commit
ebafb92e13

+ 15 - 5
tripal_chado/api/modules/tripal_chado.organism.api.inc

@@ -138,18 +138,28 @@ function tripal_get_organism_scientific_name($organism) {
   $name = $organism->genus . ' ' . $organism->species;
 
   // For Chado v1.3 we have a type_id and infraspecific name.
-  if (property_exists($organism, type_id)) {
+  if (property_exists($organism, 'type_id')) {
     $rank = '';
     // For organism objects crated using chado_generate_var
     if (is_object($organism->type_id)) {
-      $rank = $orgasnism->type_id->name;
+      if ($organism->type_id) {
+        $rank = $orgasnism->type_id->name;
+      }
     }
     else {
       $rank_term = tripal_get_cvterm(array('cvterm_id' => $organism->type_id));
-      $rank = $rank_term->name;
+      if ($rank_term) {
+        $rank = $rank_term->name;
+      }
+    }
+
+    if ($rank) {
+      $rank = tripal_abbreviate_infraspeicifc_rank($rank);
+      $name .= ' ' . $rank . ' ' . $organism->infraspecific_name;
+    }
+    else if ($organism->infraspecific_name) {
+      $name .= ' ' . $organism->infraspecific_name;
     }
-    $rank = tripal_abbreviate_infraspeicifc_rank($rank);
-    $name .= ' ' . $rank . ' ' . $organism->infraspecific_name;
   }
   return $name;
 }

+ 30 - 1
tripal_chado/includes/TripalImporter/TaxonomyImporter.inc

@@ -244,6 +244,7 @@ class TaxonomyImporter extends TripalImporter {
       $this->logMessage('Updating Existing...');
       $this->updateExisting();
     }
+
     // Now import the tree.
     $options = array('taxonomy' => 1);
     tripal_phylogeny_import_tree($this->tree, $this->phylotree, $options);
@@ -417,6 +418,11 @@ class TaxonomyImporter extends TripalImporter {
         continue;
       }
 
+      $rank_type = 'species';
+      if (property_exists($organism, 'type_id') and $organism->type_id) {
+        $rank_type = $organism->type;
+      }
+
       // Now add in the leaf node
       $sci_name = tripal_get_organism_scientific_name($organism);
       $node = array(
@@ -430,7 +436,7 @@ class TaxonomyImporter extends TripalImporter {
         'parent' => $parent['name'],
         'organism_id' => $organism->organism_id,
         'properties' => array(
-          $rank_cvterm->cvterm_id => $organism->type,
+          $rank_cvterm->cvterm_id => $rank_type,
         ),
       );
       $this->addTaxonomyNode($tree, $node, $lineage_depth);
@@ -673,6 +679,9 @@ class TaxonomyImporter extends TripalImporter {
         }
       }
 
+      // Associate the Dbxref with the organism.
+      $this->addDbxref($organism->organism_id, $taxid);
+
       // Get properties for this organism.
       $lineage = (string) $taxon->Lineage;
       $genetic_code = (string) $taxon->GeneticCode->GCId;
@@ -876,4 +885,24 @@ class TaxonomyImporter extends TripalImporter {
     }
     chado_insert_property($record, $property);
   }
+
+  /**
+   *
+   * @param unknown $organism_id
+   * @param unknown $taxId
+   */
+  private function addDbxref($organism_id, $taxId) {
+    $db = tripal_get_db(array('name' => 'NCBITaxon'));
+    $values = array(
+      'db_id' => $db->db_id,
+      'accession' => $taxId
+    );
+    $dbxref = tripal_insert_dbxref($values);
+
+    $values = array(
+      'dbxref_id' => $dbxref->dbxref_id,
+      'organism_id' => $organism_id,
+    );
+    chado_insert_record('organism_dbxref', $values);
+  }
 }