Browse Source

Bug Fix during Chado Prepare: unable to look up dbxref due to vocab and accession not being included in the instance details.

Lacey Sanderson 7 years ago
parent
commit
f9644f2513

+ 2 - 0
tripal/api/tripal.entities.api.inc

@@ -561,6 +561,7 @@ function tripal_create_bundle_fields($bundle, $term) {
 
   // Iterate through all of the field instances and create them.
   foreach ($info as $field_name => $details) {
+
     // If the field is already attached to this bundle then skip it.
     $field = field_info_field($details['field_name']);
     if ($field and array_key_exists('bundles', $field) and
@@ -568,6 +569,7 @@ function tripal_create_bundle_fields($bundle, $term) {
         in_array($bundle->name, $field['bundles']['TripalEntity'])) {
       continue;
     }
+
     // Create the field instance.
     $instance = field_create_instance($details);
     $added[] = $field_name;

+ 5 - 0
tripal/api/tripal.terms.api.inc

@@ -218,6 +218,11 @@ function tripal_add_term($details) {
  *   cannot be found.
  */
 function tripal_get_term_details($vocabulary, $accession) {
+
+  if (empty($vocabulary) OR empty($accession)) {
+    tripal_report_error('tripal_term', TRIPAL_ERROR, 'Unable to retrieve details for term due to missing vocabulary and/or accession.');
+  }
+
   // TODO: we need some sort of administrative interface that lets the user
   // switch to the desired vocabulary type. For now, we'll just use the
   // first one in the list.

+ 19 - 1
tripal/includes/TripalFields/TripalField.inc

@@ -108,12 +108,30 @@ class TripalField {
    *   An array containing the instance data as returned by field_instance_info().
    */
   public function __construct($field, $instance) {
+    $vocabulary = $term = NULL;
     $this->field = $field;
     $this->instance = $instance;
 
     $class = get_called_class();
 
-    $this->term = tripal_get_term_details($this->instance['settings']['term_vocabulary'], $this->instance['settings']['term_accession']);
+    // Use the term info defined in the class by default (assuming it's not schema:Thing ;-).
+    if ($class::$default_instance_settings['term_name'] != 'Thing') {
+      $vocabulary = $class::$default_instance_settings['term_vocabulary'];
+      $accession = $class::$default_instance_settings['term_accession'];
+    }
+
+    // Allow the constructor to override the term info.
+    $vocabulary = isset($this->instance['settings']['term_vocabulary']) ? $this->instance['settings']['term_vocabulary'] : $vocabulary;
+    $accession = isset($this->instance['settings']['term_accession']) ? $this->instance['settings']['term_accession'] : $accession;
+
+    // Assuming we have term info, load the term.
+    if (!empty($vocabulary) AND !empty($accession)) {
+      $this->term = tripal_get_term_details($vocabulary, $accession);
+    }
+    else {
+      tripal_report_error('tripal_field', TRIPAL_ERROR, 'Unable to instantiate Field :name due to missing vocabulary and/or accession.',
+        array(':name' => $class::$default_label));
+    }
 
     if (!$instance) {
       tripal_set_message(t('Missing instance of field "%field"', array('%field' => $field['field_name'])), TRIPAL_ERROR);

+ 0 - 1
tripal_chado/includes/TripalFields/schema__alternate_name/schema__alternate_name.inc

@@ -43,7 +43,6 @@ class schema__alternate_name extends ChadoField {
   // The default formatter for this field.
   public static $default_formatter = 'schema__alternate_name_formatter';
 
-
   /**
    *
    * @see TripalField::load()

+ 6 - 0
tripal_chado/includes/setup/tripal_chado.setup.inc

@@ -156,6 +156,7 @@ function tripal_chado_prepare_chado() {
     $real_version = chado_get_version(TRUE);
 
     // Create custom tables depending on the Chado version installed.
+    drush_print("Creating Tripal Materialized Views and Custom Tables...");
     $chado_version = chado_get_version();
     if ($chado_version == '1.1') {
       tripal_chado_add_v1_1_custom_tables();
@@ -171,16 +172,21 @@ function tripal_chado_prepare_chado() {
     }
 
     // Import commonly used ontologies if needed.
+    drush_print("Loading Ontologies...");
     tripal_chado_load_ontologies();
 
     // Populate the semantic web associations for Chado tables/fields.
+    drush_print("Making semantic connections for Chado tables/fields...");
     tripal_chado_populate_chado_semweb_table();
 
     // Initialize the population of the chado_cvterm_mapping table.  This will
     // map existing data types already in Chado so that when users want to
     // add new content types it simplifies the form for them.
+    drush_print("Map Chado Controlled vocabularies to Tripal Terms...");
     tripal_chado_map_cvterms();
 
+    drush_print("Creating common Tripal Content Types...");
+
     // Create the 'Organism' entity type. This uses the obi:organism term.
     $error = '';
     $args = array(