Sfoglia il codice sorgente

Working on cleanup of semantic web term assignments for web services

Stephen Ficklin 8 anni fa
parent
commit
7526753974
31 ha cambiato i file con 662 aggiunte e 283 eliminazioni
  1. 1 1
      legacy/tripal_example/theme/templates/tripal_example_references.tpl.php
  2. 9 9
      legacy/tripal_pub/theme/templates/tripal_pub_references.tpl.php
  3. 9 5
      tripal/api/tripal.entities.api.inc
  4. 2 2
      tripal/includes/TripalField.inc
  5. 6 4
      tripal/includes/TripalTerm.inc
  6. 3 1
      tripal/includes/fields/content_type.inc
  7. 32 2
      tripal/includes/tripal.entity.inc
  8. 90 0
      tripal/includes/tripal.term_lookup.inc
  9. 28 0
      tripal/theme/css/tripal.css
  10. BIN
      tripal/theme/images/info.gif
  11. 9 0
      tripal/theme/js/tripal.js
  12. 24 1
      tripal/tripal.module
  13. 0 1
      tripal_chado/api/modules/tripal_chado.cv.api.inc
  14. 44 0
      tripal_chado/api/modules/tripal_chado.db.api.inc
  15. 1 0
      tripal_chado/api/tripal_chado.api.inc
  16. 38 2
      tripal_chado/api/tripal_chado.semweb.api.inc
  17. 3 10
      tripal_chado/includes/fields/chado_base__dbxref_id.inc
  18. 1 3
      tripal_chado/includes/fields/chado_base__organism_id.inc
  19. 2 2
      tripal_chado/includes/fields/chado_feature__md5checksum.inc
  20. 1 1
      tripal_chado/includes/fields/chado_feature__residues.inc
  21. 1 1
      tripal_chado/includes/fields/chado_feature__seqlen.inc
  22. 3 3
      tripal_chado/includes/fields/chado_gene__transcripts.inc
  23. 1 1
      tripal_chado/includes/fields/chado_linker__cvterm.inc
  24. 1 1
      tripal_chado/includes/fields/chado_organism__type_id.inc
  25. 1 1
      tripal_chado/includes/tripal_chado.entity.inc
  26. 3 3
      tripal_chado/includes/tripal_chado.fields.inc
  27. 2 2
      tripal_chado/includes/tripal_chado.migrate.inc
  28. 306 158
      tripal_chado/includes/tripal_chado.semweb.inc
  29. 6 36
      tripal_chado/includes/tripal_chado.setup.inc
  30. 8 20
      tripal_chado/includes/tripal_chado.vocab_storage.inc
  31. 27 13
      tripal_ws/includes/tripal_ws.rest.inc

+ 1 - 1
legacy/tripal_example/theme/templates/tripal_example_references.tpl.php

@@ -35,7 +35,7 @@ if(count($references) > 0){ ?>
     }
     $accession = $dbxref->db_id->name . ':' . $dbxref->accession;
     if ($dbxref->db_id->urlprefix) {
-      $accession = l($accession, $dbxref->db_id->urlprefix . $dbxref->accession, array('attributes' => array('target' => '_blank')));
+      $accession = l($accession, tripal_get_dbxref_url($dbxref), array('attributes' => array('target' => '_blank')));
     }
     if (property_exists($dbxref, 'is_primary')) {
       $accession .= " <i>(primary cross-reference)</i>";

+ 9 - 9
legacy/tripal_pub/theme/templates/tripal_pub_references.tpl.php

@@ -8,38 +8,38 @@ $pub_dbxrefs = $pub->pub_dbxref;
 
 $references = array();
 if (count($pub_dbxrefs) > 0 ) {
-  foreach ($pub_dbxrefs as $pub_dbxref) {    
+  foreach ($pub_dbxrefs as $pub_dbxref) {
     $references[] = $pub_dbxref->dbxref_id;
   }
 }
 
 if(count($references) > 0){ ?>
-  <div class="tripal_pub-data-block-desc tripal-data-block-desc">This publication is also available in the following databases:</div><?php 
-  
+  <div class="tripal_pub-data-block-desc tripal-data-block-desc">This publication is also available in the following databases:</div><?php
+
   // the $headers array is an array of fields to use as the colum headers.
   // additional documentation can be found here
   // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
   $headers = array('Database', 'Accession');
-  
+
   // the $rows array contains an array of rows where each row is an array
   // of values for each column of the table in that row.  Additional documentation
   // can be found here:
   // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
   $rows = array();
-  
+
   foreach ($references as $dbxref){
     $database = $dbxref->db_id->name . ': ' . $dbxref->db_id->description;
     if ($dbxref->db_id->url) {
-      $database = l($dbxref->db_id->name, $dbxref->db_id->url, array('attributes' => array('target' => '_blank'))) . ': ' . $dbxref->db_id->description; 
+      $database = l($dbxref->db_id->name, $dbxref->db_id->url, array('attributes' => array('target' => '_blank'))) . ': ' . $dbxref->db_id->description;
     }
     $accession = $dbxref->db_id->name . ':' . $dbxref->accession;
     if ($dbxref->db_id->urlprefix) {
-      $accession = l($accession, $dbxref->db_id->urlprefix . $dbxref->accession, array('attributes' => array('target' => '_blank')));
+      $accession = l($accession, tripal_get_dbxref_url($dbxref), array('attributes' => array('target' => '_blank')));
     }
     if (property_exists($dbxref, 'is_primary')) {
       $accession .= " <i>(primary cross-reference)</i>";
     }
-    
+
     $rows[] = array(
       $database,
       $accession
@@ -61,7 +61,7 @@ if(count($references) > 0){ ?>
     'colgroups' => array(),
     'empty' => '',
   );
-  
+
   // once we have our table array structure defined, we call Drupal's theme_table()
   // function to generate the table.
   print theme_table($table);

+ 9 - 5
tripal/api/tripal.entities.api.inc

@@ -948,16 +948,20 @@ function hook_vocab_import_form_submit($form, &$form_state) {
  *
  * @return
  *   An array with at least the following keys:
- *     vocabulary : The short name of the vocabulary (e.g. SO, PATO, foaf).
- *     accession : The name unique ID of the term.
- *     url : The URL for the term.
- *     name : The name of the term.
- *     definition : The term's description.
+ *     -vocabulary : An associative array with the following keys
+ *       -name:  The short name for the vocabulary (e.g. SO, PATO, etc).
+ *       -description: The description of this vocabulary.
+ *       -url: The URL for the vocabulary.
+ *     -accession : The name unique ID of the term.
+ *     -url : The URL for the term.
+ *     -name : The name of the term.
+ *     -definition : The term's description.
  *   any other keys may be added as desired. Returns NULL if the term
  *   cannot be found.
  */
 function hook_vocab_get_term($vocabulary, $accession) {
   // See the tripal_chado_vocab_get_term() function for an example.
+
 }
 
 /**

+ 2 - 2
tripal/includes/TripalField.inc

@@ -386,7 +386,7 @@ class TripalField {
    *   to the user.
    *
    */
-  public function formatterSettingsSummary($field, $instance, $view_mode) {
+  public static function formatterSettingsSummary($field, $instance, $view_mode) {
 
   }
 
@@ -413,7 +413,7 @@ class TripalField {
    * @return
    *   A Drupal Form array containing the settings form for this field.
    */
-  public function formatterSettingsForm($field, $instance,
+  public static function formatterSettingsForm($field, $instance,
       $view_mode, $form, &$form_state) {
 
   }

+ 6 - 4
tripal/includes/TripalTerm.inc

@@ -25,10 +25,12 @@ class TripalTerm extends Entity {
       $function = $module . '_vocab_get_term';
       if (function_exists($function)) {
         $term_details = $function($vocab->vocabulary, $this->accession);
-        $this->details = $term_details;
-        if ($term_details and $term_details['definition']) {
-          $this->definition = $term_details['definition'];
-          $this->url = $term_details['url'];
+        if ($term_details) {
+          $this->details = $term_details;
+          if ($term_details and $term_details['definition']) {
+            $this->definition = $term_details['definition'];
+            $this->url = $term_details['url'];
+          }
         }
       }
     }

+ 3 - 1
tripal/includes/fields/content_type.inc

@@ -72,7 +72,9 @@ class content_type extends TripalField {
       'label' => 'Resource Type',
       'description' => '',
       'required' => FALSE,
-      'settings' => array(),
+      'settings' => array(
+        'auto_attach' => TRUE,
+      ),
       'widget' => array(
         'type' => 'tripal_content_type_widget',
         'settings' => array(

+ 32 - 2
tripal/includes/tripal.entity.inc

@@ -274,19 +274,49 @@ function tripal_form_tripal_entity_form_alter(&$form, &$form_state, $form_id) {
  * Here we want to overwite unattached fields with a div box that will be
  * recognized by JavaScript that will then use AJAX to load the field.
  *
+ * We also want to add tooltips to each field that describes to the user
+ * the meaning of the field.
+ *
  * The tripal_ajax_attach_field() function is called by an AJAX call to
  * retrieve the field.
  */
 function tripal_entity_view($entity, $type, $view_mode, $langcode) {
   if ($type == 'TripalEntity') {
     foreach (element_children($entity->content) as $child_name) {
+
+      // Initailize the prefix and suffix for this field.
+      if (!array_key_exists('#prefix', $entity->content[$child_name])) {
+        $entity->content[$child_name]['#prefix'] = '';
+      }
+      if (!array_key_exists('#suffix', $entity->content[$child_name])) {
+        $entity->content[$child_name]['#suffix'] = '';
+      }
+
+      // Surround the field with a <div> box for AJAX loading if this
+      // field is unattached.  this will allow JS code to automatically load
+      // the field.
       $child = $entity->content[$child_name];
       if (array_key_exists('#items', $child) and
           array_key_exists('0', $child['#items']) and
           array_key_exists('#unattached', $child['#items'][0])
           and $child['#items'][0]['#unattached'] === TRUE) {
-        $entity->content[$child_name]['#prefix'] = '<div id="tripal-entity-' . $entity->id . '--' . $child_name . '" class="tripal-entity-unattached">';
-        $entity->content[$child_name]['#suffix'] = '</div>';
+        $entity->content[$child_name]['#prefix'] .= '<div id="tripal-entity-' . $entity->id . '--' . $child_name . '" class="tripal-entity-unattached">';
+        $entity->content[$child_name]['#suffix'] .= '</div>';
+      }
+
+      // Add a tooltip to the field.
+      $field = field_info_field($child_name);
+      if (array_key_exists('settings', $field) and
+          array_key_exists('semantic_web', $field['settings'])) {
+        list($vocabulary, $accession) = explode(':', $field['settings']['semantic_web']);
+        $term = tripal_get_term_details($vocabulary, $accession);
+        if ($term) {
+          $entity->content[$child_name]['#prefix'] .= '' .
+            '<div class="tripal-tooltip">' .
+              '<img src="' . url(drupal_get_path('module', 'tripal') . '/theme/images/info.gif') . '">' .
+              '<div class="tripal-tooltiptext">' . $term['definition'] . '</div>' .
+            '</div>';
+        }
       }
     }
   }

+ 90 - 0
tripal/includes/tripal.term_lookup.inc

@@ -0,0 +1,90 @@
+<?php
+
+/**
+ *
+ * @param $form
+ * @param string $form_state
+ */
+function tripal_vocabulary_lookup_form($form, &$form_state = NULL) {
+
+}
+/**
+ *
+ * @param $form
+ * @param $form_state
+ */
+function tripal_vocabulary_lookup_form_validate($form, $form_state) {
+
+}
+/**
+ *
+ * @param $form
+ * @param $form_state
+ */
+function tripal_vocabulary_lookup_form_submit($form, $form_state) {
+
+}
+
+/**
+ *
+ * @param $vocabulary
+ * @param $accession
+ *
+ * @return
+ */
+function tripal_vocabulary_lookup_term_page($vocabulary, $accession) {
+  $term = tripal_get_term_details($vocabulary, $accession);
+
+  // If we can't find the term then just return a message.
+  if (!$term) {
+    drupal_set_message('The term cannot be found on this site', 'error');
+    return '';
+  }
+
+  // Build the Term table.
+  $headers = array();
+  $rows = array();
+  $term_name = $term['name'];
+  if ($term['url']) {
+    $term_name = l($term['name'], $term['url'], array('attributes' => array('target' => '_blank')));
+  }
+  $vocab_name = $term['vocabulary']['name'];
+  if ($term['vocabulary']['url']) {
+    $vocab_name = l($term['vocabulary']['name'], $term['vocabulary']['url'], array('attributes' => array('target' => '_blank')));
+  }
+  $rows[] = array(
+    array(
+      'data' => 'Name',
+      'header' => TRUE,
+      'width' => '20%',
+    ),
+    $term_name,
+  );
+  $rows[] = array(
+    array(
+      'data' => 'Vocabulary',
+      'header' => TRUE,
+      'width' => '20%',
+    ),
+    $vocab_name . ': ' . $term['vocabulary']['description']. '',
+  );
+  $rows[] = array(
+    array(
+      'data' => 'Definition',
+      'header' => TRUE,
+      'width' => '20%',
+    ),
+    $term['definition'],
+  );
+  $table = array(
+    'header' => $headers,
+    'rows' => $rows,
+    'attributes' => array(),
+    'sticky' => FALSE,
+    'caption' => '',
+    'colgroups' => array(),
+    'empty' => '',
+  );
+  $content = theme_table($table);
+  return $content;
+}

+ 28 - 0
tripal/theme/css/tripal.css

@@ -0,0 +1,28 @@
+/* Tooltip container */
+.tripal-tooltip {
+    position: relative;
+    display: inline-block;
+    padding-left: 5px;
+    padding-right: 5px;
+}
+
+/* Tooltip text */
+.tripal-tooltip .tripal-tooltiptext {
+    visibility: hidden;
+    width: 300px;
+    background-color: #888888;
+    color: #FFFFFF;
+    text-align: left;
+    padding: 10px;
+    border-radius: 6px;
+ 
+    /* Position the tooltip text - see examples below! */
+    position: absolute;
+    z-index: 1;
+}
+
+/* Show the tooltip text when you mouse over the tooltip container */
+.tripal-tooltip:hover .tripal-tooltiptext {
+    visibility: visible;
+}
+</style>

BIN
tripal/theme/images/info.gif


+ 9 - 0
tripal/theme/js/tripal.js

@@ -18,6 +18,15 @@
           }
         });
       });
+      
+      $(".tripal-tooltip").each(function() {
+        var field = $(this).next('.field');
+        $(this).detach();
+
+        if (field) {
+          field.children('.field-label').append($(this));
+        }
+      });
     }
   }
 })(jQuery);

+ 24 - 1
tripal/tripal.module

@@ -108,7 +108,7 @@ function tripal_menu() {
   );
 
   $items['admin/tripal/storage'] = array(
-    'title' => 'Data Storage Settings',
+    'title' => 'Data Storage',
     'description' => t("Tripal is designed to access biological
         data in any data storage back-end.  A storage back-end must have a
         module that can be installed that interfaces with Tripal.  By default
@@ -242,7 +242,30 @@ function tripal_menu() {
     'file path' => drupal_get_path('module', 'tripal'),
   );
 
+  /*
+   * Term Lookup
+   */
+  $items['cv/lookup'] = array(
+    'title' => 'Vocabulary Lookup',
+    'description' => t("Provides a tool to discover controlled vocabularies and their terms used by this site."),
+    'access arguments' => array('access content'),
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('tripal_vocabulary_lookup_form'),
+    'file' => 'includes/tripal.term_lookup.inc',
+    'file path' => drupal_get_path('module', 'tripal'),
+    'type' => MENU_NORMAL_ITEM,
+  );
 
+  $items['cv/lookup/%/%'] = array(
+    'title' => 'Vocabulary Lookup',
+    'description' => t("Provides a tool to discover controlled vocabularies and their terms used by this site."),
+    'access arguments' => array('access content'),
+    'page callback' => 'tripal_vocabulary_lookup_term_page',
+    'page arguments' => array(2, 3),
+    'file' => 'includes/tripal.term_lookup.inc',
+    'file path' => drupal_get_path('module', 'tripal'),
+    'type' => MENU_CALLBACK,
+  );
 
   return $items;
 }

+ 0 - 1
tripal_chado/api/modules/tripal_chado.cv.api.inc

@@ -275,7 +275,6 @@ function tripal_get_cvterm($identifiers, $options = array()) {
   }
 
 }
-
 /**
  * Create an options array to be used in a form element
  *   which provides a list of all chado cvterms

+ 44 - 0
tripal_chado/api/modules/tripal_chado.db.api.inc

@@ -279,6 +279,50 @@ function tripal_get_dbxref($identifiers, $options = array()) {
   }
 }
 
+/**
+ * Generates a URL for the controlled vocabulary term.
+ *
+ * If the URL and URL prefix are provided for the database record of a cvterm
+ * then a URL can be created for the term.  By default, the db.name and
+ * dbxref.accession are concatenated and appended to the end of the db.urlprefix.
+ * But Tripal supports the use of {db} and {accession} tokens when if present
+ * in the db.urlprefix string will be replaced with the db.name and
+ * dbxref.accession respectively.
+ *
+ * @param $dbxref
+ *   A dbxref object as created by the chado_generate_var() function.
+ *
+ * @return
+ *   A string containing the URL.
+ */
+function tripal_get_dbxref_url($dbxref) {
+  $final_url = '';
+
+  // Create the URL for the term.
+  if ($dbxref->db_id->urlprefix) {
+    $db_count = 0;
+    $acc_count = 0;
+    $url = $dbxref->db_id->urlprefix;
+
+    // If the URL prefix has replacement tokens then use those.
+    $url = preg_replace('/\{db\}/', $dbxref->db_id->name, $url, -1, $db_count);
+    $url = preg_replace('/\{accession\}/', $dbxref->accession, $url, -1, $acc_count);
+    $final_url = $url;
+
+    // If no replacements were made above then tokens weren't used and we can
+    // default to just appending the db name and accession to the end.
+    if (!$db_count and !$acc_count) {
+      $final_url .= $dbxref->db_id->name . ':' . $dbxref->accession;
+    }
+
+    // If the URL prefix is relative then convert it to a full URL.
+    if (!preg_match('/^(http|https)/', $final_url)) {
+      $final_url = url($final_url, array('absolute' => TRUE));
+    }
+  }
+  return $final_url;
+}
+
 /**
  * Adds a new database to the Chado DB table and returns the DB object.
  *

+ 1 - 0
tripal_chado/api/tripal_chado.api.inc

@@ -72,6 +72,7 @@ function tripal_chado_publish_records($values, $job_id = NULL) {
   // Load the bundle entity so we can get information about which Chado
   // table/field this entity belongs to.
   $bundle = tripal_load_bundle_entity(array('name' => $bundle_name));
+
   $bundle_id = $bundle->id;
   $table = tripal_get_bundle_variable('chado_table', $bundle_id);
   $column = tripal_get_bundle_variable('chado_type_column', $bundle_id);

+ 38 - 2
tripal_chado/api/tripal_chado.semweb.api.inc

@@ -101,8 +101,8 @@ function tripal_associate_chado_semweb_term($chado_table, $chado_column, $term,
   // First check to see if a valid record exists that matches the table and
   // column indicated. If it doesn't then insert the record.
   $query = db_select('chado_semweb', 'CS')
-  ->fields('CS', array('chado_semweb_id'))
-  ->condition('chado_column', $chado_column);
+    ->fields('CS', array('chado_semweb_id'))
+    ->condition('chado_column', $chado_column);
   if ($chado_table) {
     $query->condition('chado_table', $chado_table);
   }
@@ -157,3 +157,39 @@ function tripal_associate_chado_semweb_term($chado_table, $chado_column, $term,
 
   return TRUE;
 }
+
+/**
+ * Retrieves the term that maps to the given Chado table and field.
+ *
+ * @param $chado_table
+ *   The name of the Chado table.
+ * @param $chado_column
+ *   The name of the Chado field.
+ * @param $options
+ *   An associative array of one or more of the following keys:
+ *     -return_object:  Set to TRUE to return the cvterm object rather than
+ *      the string version of the term.
+ *
+ * @return
+ *   Returns a string-based representation of the term (e.g. SO:0000704). If
+ *   the 'return_object' options is provided then a cvterm object is returned.
+ *   returns NULL if no term is mapped to the table and column.
+ */
+function tripal_get_chado_semweb_term($chado_table, $chado_column, $options = array()) {
+  $cvterm_id = db_select('chado_semweb', 'CS')
+    ->fields('CS', array('cvterm_id'))
+    ->condition('chado_column', $chado_column)
+    ->condition('chado_table', $chado_table)
+    ->execute()
+    ->fetchField();
+
+  if ($cvterm_id) {
+    $cvterm = tripal_get_cvterm(array('cvterm_id' => $cvterm_id));
+    if (array_key_exists('return_object', $options)) {
+      return $cvterm;
+    }
+
+    return $cvterm->dbxref_id->db_id->name . ':' . $cvterm->dbxref_id->accession;
+  }
+
+}

+ 3 - 10
tripal_chado/includes/fields/chado_base__dbxref_id.inc

@@ -71,6 +71,7 @@ class chado_base__dbxref_id extends TripalField {
     $cv_id      = $this->details['chado_cv_id'];
     $cvterm_id  = $this->details['chado_cvterm_id'];
 
+
     return array(
       'field_name' => $this->field_name,
       'type' => 'chado_base__dbxref_id',
@@ -82,7 +83,7 @@ class chado_base__dbxref_id extends TripalField {
       'settings' => array(
         'chado_table' => $table_name,
         'chado_column' => 'dbxref_id',
-        'semantic_web' => 'data:2091',
+        'semantic_web' => tripal_get_chado_semweb_term($table_name, 'dbxref_id'),
       ),
     );
   }
@@ -160,9 +161,6 @@ class chado_base__dbxref_id extends TripalField {
     foreach ($items as $delta => $item) {
       if ($item['value']) {
         $content = $item['value']['vocabulary'] . ':' . $item['value']['accession'];
-        if ($item['value']['URL']) {
-          $content = l($item['value']['URL'], $item['value']['URL']);
-        }
         $element[$delta] = array(
           '#type' => 'markup',
           '#markup' => $content,
@@ -334,16 +332,11 @@ class chado_base__dbxref_id extends TripalField {
     if ($record->$field_column) {
       $dbxref = $record->$field_column;
       $value = $dbxref->db_id->name . ':' . $dbxref->accession;
-      $URL = '';
-      if ($dbxref->db_id->urlprefix) {
-        $URL = l($value, $dbxref->db_id->urlprefix . '/' . $dbxref->accession);
-      }
-
       $entity->{$field_name}['und'][0] = array(
         'value' => array(
           'vocabulary' => $dbxref->db_id->name,
           'accession' => $dbxref->accession,
-          'URL' => $URL,
+          'URL' => tripal_get_dbxref_url($dbxref),
         ),
         $field_table . '__' . $field_column => $record->$field_column->$field_column,
         $field_table . '__' . $field_column . '--dbxref_id'   => $dbxref->dbxref_id,

+ 1 - 3
tripal_chado/includes/fields/chado_base__organism_id.inc

@@ -94,7 +94,7 @@ class chado_base__organism_id extends TripalField {
       'settings' => array(
         'chado_table' => $table_name,
         'chado_column' => 'organism_id',
-        'semantic_web' => 'local:organism',
+        'semantic_web' => tripal_get_chado_semweb_term($table_name, 'organism_id'),
       ),
     );
   }
@@ -316,8 +316,6 @@ class chado_base__organism_id extends TripalField {
       'colgroups'  => array(),
       'empty'      => 'There are no tokens',
     );
-    $project_details = theme('table', $table_vars);
-
     $element['tokens']['list'] = array(
       '#type' => 'item',
       '#markup' => theme_table($table_vars),

+ 2 - 2
tripal_chado/includes/fields/chado_feature__md5checksum.inc

@@ -74,7 +74,7 @@ class chado_feature__md5checksum  extends TripalField {
       'settings' => array(
         'chado_table' => $table_name,
         'chado_column' => 'md5checksum',
-        'semantic_web' => 'data:2190',
+        'semantic_web' => tripal_get_chado_semweb_term($table_name, 'md5checksum'),
       ),
     );
   }
@@ -104,7 +104,7 @@ class chado_feature__md5checksum  extends TripalField {
         here, then the downloaded sequence is uncorrupted.',
       'required' => FALSE,
       'settings' => array(
-        'auto_attach' => FALSE,
+        'auto_attach' => TRUE,
       ),
       'widget' => array(
         'type' => 'chado_feature__md5checksum_widget',

+ 1 - 1
tripal_chado/includes/fields/chado_feature__residues.inc

@@ -76,7 +76,7 @@ class chado_feature__residues extends TripalField {
       'settings' => array(
         'chado_table' => $table_name,
         'chado_column' => 'residues',
-        'semantic_web' => 'SO:0000110',
+        'semantic_web' => tripal_get_chado_semweb_term($table_name, 'residues'),
       ),
     );
   }

+ 1 - 1
tripal_chado/includes/fields/chado_feature__seqlen.inc

@@ -73,7 +73,7 @@ class chado_feature__seqlen extends TripalField {
       'settings' => array(
         'chado_table' => $table_name,
         'chado_column' => 'seqlen',
-        'semantic_web' => 'data:1249',
+        'semantic_web' => tripal_get_chado_semweb_term($table_name, 'seqlen'),
       ),
     );
   }

+ 3 - 3
tripal_chado/includes/fields/chado_gene__transcripts.inc

@@ -153,7 +153,7 @@ class chado_gene__transcripts extends TripalField {
   /**
    * @see TripalField::formatter_settings_summary()
    */
-  public function formatterSettingsSummary($field, $instance,
+  public static function formatterSettingsSummary($field, $instance,
       $view_mode) {
 
   }
@@ -161,7 +161,7 @@ class chado_gene__transcripts extends TripalField {
   /**
    * @see TripalField::formatter_settings_form()
    */
-  public function formatterSettingsForm($field, $instance,
+  public static function formatterSettingsForm($field, $instance,
       $view_mode, $form, &$form_state) {
 
   }
@@ -176,7 +176,7 @@ class chado_gene__transcripts extends TripalField {
     $settings = $display['settings'];
     $record = $entity->chado_record;
 
-    $headers = array('Feature Name', 'Unique Name', 'Type', 'Location');
+    $headers = array('Transcript Name', 'Identifier', 'Type', 'Location');
     $rows = array();
     foreach ($items as $delta => $item) {
 

+ 1 - 1
tripal_chado/includes/fields/chado_linker__cvterm.inc

@@ -90,7 +90,7 @@ class chado_linker__cvterm extends TripalField {
         // Build the accession.
         $accession = $dbxref->db_id->name . ':' . $dbxref->accession;
         if ($dbxref->db_id->urlprefix) {
-          $accession = l($accession, $dbxref->db_id->urlprefix . '/' . $dbxref->accession, array('attributes' => array('target' => '_blank')));
+          $accession = l($accession, tripal_get_dbxref_url($dbxref), array('attributes' => array('target' => '_blank')));
         }
 
         // Build the publication reference.

+ 1 - 1
tripal_chado/includes/fields/chado_organism__type_id.inc

@@ -76,7 +76,7 @@ class chado_organism__type_id extends TripalField {
       'settings' => array(
         'chado_table' => 'organism',
         'chado_column' => 'type_id',
-        'semantic_web' => 'local:infraspecific_type',
+        'semantic_web' => tripal_get_chado_semweb_term('organism', 'type_id'),
       ),
     );
   }

+ 1 - 1
tripal_chado/includes/tripal_chado.entity.inc

@@ -278,7 +278,7 @@ function tripal_chado_tripal_default_title_format($entity, $available_tokens) {
   // For organism titles  we want the genus and species with no comma separation.
   if ($table == 'organism') {
     $format[] = array(
-      'format' => '[organism.genus] [organism.species]',
+      'format' => '[organism__genus] [organism__species]',
       'weight' => -5
     );
   }

+ 3 - 3
tripal_chado/includes/tripal_chado.fields.inc

@@ -43,9 +43,7 @@ function tripal_chado_field_create_info($entity_type, $bundle) {
   );
 
   $base_fields = tripal_chado_field_create_base('create_info', $entity_type, $bundle, $details);
-  dpm($base_fields);
   $custom_fields = tripal_chado_field_create_info_custom($entity_type, $bundle, $details);
-  dpm($custom_fields);
   return array_merge($base_fields, $custom_fields);
 }
 
@@ -172,6 +170,7 @@ function tripal_chado_field_create_info_base_defaults($field_name, $table_name,
 
   $details = $schema['fields'][$column_name];
 
+
   // Set some defaults for the field.
   $field = array(
     'field_name' => $field_name,
@@ -184,7 +183,7 @@ function tripal_chado_field_create_info_base_defaults($field_name, $table_name,
     'settings' => array(
       'chado_table' => $table_name,
       'chado_column' => $column_name,
-      'semantic_web' => '',
+      'semantic_web' => tripal_get_chado_semweb_term($table_name, $column_name),
     ),
   );
 
@@ -379,6 +378,7 @@ function tripal_chado_field_create_instance_info_base_defaults($bundle_name,
 
   // Set some default semantic web information
   if ($column_name == 'uniquename') {
+    $field['label'] = 'Identifier';
     $field['widget_type'] = 'text_textfield';
   }
   elseif ($field['label'] == 'Timeaccessioned') {

+ 2 - 2
tripal_chado/includes/tripal_chado.migrate.inc

@@ -576,8 +576,8 @@ function tripal_chado_migrate_all_types() {
     }
     else if ($table == 'organism') {
       array_push($types, array(
-        'vocabulary' => 'local',
-        'accession' => 'organism',
+        'vocabulary' => 'OBI',
+        'accession' => '0100026',
         'term_name' => 'organism'
       ));
     }

+ 306 - 158
tripal_chado/includes/tripal_chado.semweb.inc

@@ -11,12 +11,38 @@ function tripal_chado_populate_chado_semweb_table() {
   }
 
   // Now set defaults!
+  tripal_chado_populate_vocab_EDAM();
+  tripal_chado_populate_vocab_FOAF();
+  tripal_chado_populate_vocab_IAO();
+  tripal_chado_populate_vocab_LOCAL();
+  tripal_chado_populate_vocab_NCBITAXON();
+  tripal_chado_populate_vocab_OBI();
+  tripal_chado_populate_vocab_RDFS();
+  tripal_chado_populate_vocab_SBO();
+  tripal_chado_populate_vocab_SCHEMA();
+  tripal_chado_populate_vocab_SWO();
+  tripal_chado_populate_vocab_TAXRANK();
+}
+
+/**
+ * Adds the friend of a friend database and terms.
+ */
+function tripal_chado_populate_vocab_FOAF() {
 
-  //
-  // VOCABUARIES:
+  tripal_insert_cv('foaf','Friend of a Friend');
+  tripal_insert_db(array(
+    'name' => 'foaf',
+    'description' => 'Friend of a Friend',
+    'url' => 'http://www.foaf-project.org/',
+    'urlprefix' => 'http://xmlns.com/foaf/spec/#',
+  ));
+  tripal_insert_cv('foaf','Friend of a Friend. A dictionary of people-related terms that can be used in structured data).');
+}
 
-  // Add in vocabularies of terms that will be used for the semantic web
-  //
+/**
+ * Adds the RDFS database and terms.
+ */
+function tripal_chado_populate_vocab_RDFS() {
   tripal_insert_db(array(
     'name' => 'rdfs',
     'description' => 'Resource Description Framework Schema',
@@ -24,102 +50,153 @@ function tripal_chado_populate_chado_semweb_table() {
     'urlprefix' => 'https://www.w3.org/TR/rdf-schema/#ch_',
   ));
   tripal_insert_cv('rdfs','Resource Description Framework Schema');
+
   $name = tripal_insert_cvterm(array(
     'id' => 'rdfs:type',
     'name' => 'type',
     'cv_name' => 'rdfs',
-    'definition' => 'rdf:type is an instance of rdf:Property that is used to state that a resource is an instance of a class.',
+    'definition' => 'The type of resource.',
   ));
-
-  tripal_insert_cv('foaf','Friend of a Friend');
-  tripal_insert_db(array(
-    'name' => 'foaf',
-    'description' => 'Friend of a Friend. A dictionary of people-related terms that can be used in structured data).',
-    'url' => 'http://www.foaf-project.org/',
-    'urlprefix' => 'http://xmlns.com/foaf/spec/#',
-  ));
-  tripal_insert_cv('foaf','Friend of a Friend');
-
+}
+/**
+ * Adds the Schema.org database and terms.
+ */
+function tripal_chado_populate_vocab_SCHEMA() {
   tripal_insert_db(array(
     'name' => 'schema',
-    'description' => 'Schema.org. Schema.org is sponsored by Google, Microsoft, Yahoo and Yandex. The vocabularies are developed by an open community process.',
+    'description' => 'Schema.org.',
     'url' => 'https://schema.org/',
-    'urlprefix' => 'https://schema.org/',
-  ));
-  tripal_insert_cv('schema','Schema.org');
-
-  tripal_insert_db(array(
-    'name' => 'TAXRANK',
-    'description' => 'Taxonomic rank vocabulary. A vocabulary of taxonomic ranks (species, family, phylum, etc).',
-    'url' => 'https://github.com/phenoscape/taxrank',
-    'urlprefix' => 'http://purl.obolibrary.org/obo/TAXRANK_',
-  ));
-  tripal_insert_cv('taxrank','Taxonomic rank vocabulary');
-
-  tripal_insert_db(array(
-    'name' => 'NCBITaxon',
-    'description' => 'NCBI organismal classification. An ontology representation of the NCBI organismal taxonomy.',
-    'url' => 'http://www.berkeleybop.org/ontologies/ncbitaxon/',
-    'urlprefix' => 'http://purl.obolibrary.org/obo/ncbitaxon#',
+    'urlprefix' => 'https://schema.org/{accession}',
   ));
-  tripal_insert_cv('ncbitaxon','NCBI organismal classification');
+  tripal_insert_cv('schema','Schema.org. Schema.org is sponsored by Google, Microsoft, Yahoo and Yandex. The vocabularies are developed by an open community process.');
 
-  tripal_insert_db(array(
-    'name' => 'SWO',
-    'description' => 'Software Ontology. An ontology representation of the NCBI organismal taxonomy.',
-    'url' => 'http://theswo.sourceforge.net/',
-    'urlprefix' => '',
-  ));
-  tripal_insert_cv('swo','Software Ontology');
 
-  tripal_insert_db(array(
-    'name' => 'IAO',
-    'description' => 'The Information Artifact Ontology (IAO) is a new ' .
-    'ontology of information entities, originally driven by work by the ' .
-    'OBI digital entity and realizable information entity branch.',
-    'url' => 'https://github.com/information-artifact-ontology/IAO/',
-    'urlprefix' => 'http://purl.obolibrary.org/obo/IAO_',
-  ));
-  tripal_insert_cv('IAO','Information Artifact Ontology');
-
-
-  tripal_insert_db(array(
-    'name' => 'SBO',
-    'description' => 'Systems Biology. Terms commonly used in Systems Biology, and in particular in computational modeling.',
-    'url' => 'http://www.ebi.ac.uk/sbo/main/',
-    'urlprefix' => 'http://purl.obolibrary.org/obo/SBO_',
-  ));
-  tripal_insert_cv('sbo','Systems Biology');
-
-  //
-  // ADD TERMS AND SET TERM DEFAULTS
-  //
-  $name = tripal_insert_cvterm(array(
+  $term = tripal_insert_cvterm(array(
     'id' => 'schema:name',
     'name' => 'name',
     'cv_name' => 'schema',
     'definition' => 'The name of the item.',
   ));
-  tripal_associate_chado_semweb_term(NULL, 'uniquename', $name);
-  tripal_associate_chado_semweb_term(NULL, 'name', $name);
+  tripal_associate_chado_semweb_term(NULL, 'name', $term);
 
-  $alternate_name = tripal_insert_cvterm(array(
+  $term = tripal_insert_cvterm(array(
     'id' => 'schema:alternateName',
     'name' => 'alternateName',
     'cv_name' => 'schema',
-    'definition' => 'The name of the item.',
+    'definition' => 'An alias for the item.',
   ));
 
-  $description = tripal_insert_cvterm(array(
+  $term = tripal_insert_cvterm(array(
     'id' => 'schema:description',
     'name' => 'description',
     'cv_name' => 'schema',
     'definition' => 'A description of the item.',
   ));
-  tripal_associate_chado_semweb_term(NULL, 'description', $description);
+  tripal_associate_chado_semweb_term(NULL, 'description', $term);
+
+  $term = tripal_insert_cvterm(array(
+    'id' => 'schema:comment',
+    'name' => 'comment',
+    'cv_name' => 'schema',
+    'definition' => 'Comments, typically from users.',
+  ));
+  tripal_associate_chado_semweb_term(NULL, 'comment', $term);
+  tripal_associate_chado_semweb_term('pub', 'uniquename', $term);
+}
+/**
+ * Adds the EDAM database and terms.
+ */
+function tripal_chado_populate_vocab_EDAM() {
+  tripal_insert_db(array(
+    'name' => 'data',
+    'description' => 'Bioinformatics operations, data types, formats, identifiers and topics.',
+    'url' => 'http://edamontology.org/page',
+    'urlprefix' => 'http://edamontology.org/{db}_{accession}',
+  ));
+  tripal_insert_db(array(
+    'name' => 'EDAM',
+    'description' => 'Bioinformatics operations, data types, formats, identifiers and topics.',
+    'url' => 'http://edamontology.org/page',
+    'urlprefix' => 'http://edamontology.org/{db}_{accession}',
+  ));
+
+  $term = tripal_insert_cvterm(array(
+    'id' => 'data:1249',
+    'name' => 'Sequence length',
+    'cv_name' => 'EDAM',
+    'definition' => 'The size (length) of a sequence, subsequence or region in a sequence, or range(s) of lengths.',
+  ));
+  tripal_associate_chado_semweb_term('feature', 'seqlen', $term);
+
+  $term = tripal_insert_cvterm(array(
+    'id' => 'data:2190',
+    'name' => 'Sequence checksum',
+    'cv_name' => 'EDAM',
+    'definition' => 'A fixed-size datum calculated (by using a hash function) for a molecular sequence, typically for purposes of error detection or indexing.',
+  ));
+  tripal_associate_chado_semweb_term('feature', 'md5checksum', $term);
+
+  $term = tripal_insert_cvterm(array(
+    'id' => 'data:2091',
+    'name' => 'Accession',
+    'cv_name' => 'EDAM',
+    'definition' => 'A persistent (stable) and unique identifier, typically identifying an object (entry) from a database.',
+  ));
+  tripal_associate_chado_semweb_term(NULL, 'dbxref_id', $term);
+
+  $term = tripal_insert_cvterm(array(
+    'id' => 'data:2044',
+    'name' => 'Sequence',
+    'cv_name' => 'EDAM',
+    'definition' => 'One or more molecular sequences, possibly with associated annotation..',
+  ));
+  tripal_associate_chado_semweb_term('feature', 'residues', $term);
+
+  $term = tripal_insert_cvterm(array(
+    'id' => 'data:0842',
+    'name' => 'Identifier',
+    'cv_name' => 'EDAM',
+    'definition' => 'A text token, number or something else which identifies an entity, but which may not be persistent (stable) or unique (the same identifier may identify multiple things).',
+  ));
+  tripal_associate_chado_semweb_term(NULL, 'uniquename', $term);
+}
+
+/**
+ * Adds the Information Artifact Ontology database and terms.
+ */
+function tripal_chado_populate_vocab_OBI() {
+  tripal_insert_db(array(
+    'name' => 'OBI',
+    'description' => 'The Ontology for Biomedical Investigation.',
+    'url' => 'http://obi-ontology.org/page/Main_Page',
+    'urlprefix' => 'http://purl.obolibrary.org/obo/{db}_{accession}',
+  ));
+  tripal_insert_cv('obi','Ontology for Biomedical Investigation. The Ontology for Biomedical Investigations (OBI) is build in a collaborative, international effort and will serve as a resource for annotating biomedical investigations, including the study design, protocols and instrumentation used, the data generated and the types of analysis performed on the data. This ontology arose from the Functional Genomics Investigation Ontology (FuGO) and will contain both terms that are common to all biomedical investigations, including functional genomics investigations and those that are more domain specific.');
+
+  $term = tripal_insert_cvterm(array(
+    'id' => 'OBI:0100026',
+    'name' => 'organism',
+    'cv_name' => 'obi',
+    'definition' => 'A material entity that is an individual living system, such as animal, plant, bacteria or virus, that is capable of replicating or reproducing, growth and maintenance in the right environment. An organism may be unicellular or made up, like humans, of many billions of cells divided into specialized tissues and organs.',
+  ));
+  tripal_associate_chado_semweb_term(NULL, 'organism_id', $term);
+}
+/**
+ * Adds the Information Artifact Ontology database and terms.
+ */
+function tripal_chado_populate_vocab_IAO() {
 
+  tripal_insert_db(array(
+    'name' => 'IAO',
+    'description' => 'The Information Artifact Ontology (IAO).',
+    'url' => 'https://github.com/information-artifact-ontology/IAO/',
+    'urlprefix' => 'http://purl.obolibrary.org/obo/IAO_',
+  ));
+  tripal_insert_cv('IAO','Information Artifact Ontology  is a new ' .
+      'ontology of information entities, originally driven by work by the ' .
+      'OBI digital entity and realizable information entity branch.');
 
-  $definition = tripal_insert_cvterm(array(
+  $term = tripal_insert_cvterm(array(
     'id' => 'IAO:0000115',
     'name' => 'definition',
     'cv_name' => 'iao',
@@ -127,40 +204,126 @@ function tripal_chado_populate_chado_semweb_table() {
       'a class or property. Shall be Aristotelian, formalized and normalized. ' .
       'Can be augmented with colloquial definitions.',
   ));
-  tripal_associate_chado_semweb_term(NULL, 'definition', $definition);
+  tripal_associate_chado_semweb_term(NULL, 'definition', $term);
 
-  $comment = tripal_insert_cvterm(array(
-    'id' => 'schema:comment',
-    'name' => 'comment',
-    'cv_name' => 'schema',
-    'definition' => 'Comments, typically from users.',
+  $term = tripal_insert_cvterm(array(
+    'id' => 'IAO:0000129',
+    'name' => 'version number',
+    'cv_name' => 'IAO',
+    'definition' => 'A version number is an ' .
+    'information content entity which is a sequence of characters ' .
+    'borne by part of each of a class of manufactured products or its ' .
+    'packaging and indicates its order within a set of other products ' .
+    'having the same name.',
+  ));
+  tripal_associate_chado_semweb_term('analysis', 'programversion', $term);
+
+  $term = tripal_insert_cvterm(array(
+    'id' => 'IAO:0000064',
+    'name' => 'algorithm',
+    'cv_name' => 'IAO',
+    'definition' => 'An algorithm is a set of instructions for performing a paticular calculation.',
+  ));
+  tripal_associate_chado_semweb_term('analysis', 'algorithm', $term);
+}
+
+/**
+ * Adds terms to the 'local' database.
+ *
+ * These are terms where an appropriate match could not be found in any other
+ * ontology.
+ */
+function tripal_chado_populate_vocab_LOCAL() {
+  tripal_insert_db(array(
+    'name' => 'local',
+    'description' => 'Terms created for this site.',
+    'url' => '/cv/lookup',
+    'urlprefix' => '/cv/lookup/{db}/{accession}',
   ));
-  tripal_associate_chado_semweb_term(NULL, 'comment', $comment);
 
-  $time_last_modified = tripal_insert_cvterm(array(
+  $term = tripal_insert_cvterm(array(
     'id' => 'local:timelastmodified',
     'name' => 'time_last_modified',
     'cv_name' => 'local',
-    'definition' => 'The time at which a record for an item was first added.',
+    'definition' => 'The time at which the record was last modified.',
   ));
-  tripal_associate_chado_semweb_term(NULL, 'timelastmodified', $time_last_modified);
+  tripal_associate_chado_semweb_term(NULL, 'timelastmodified', $term);
 
 
-  $time_accessioned = tripal_insert_cvterm(array(
+  $term = tripal_insert_cvterm(array(
     'id' => 'local:timeaccessioned',
     'name' => 'time_accessioned',
     'cv_name' => 'local',
-    'definition' => 'The time at which a record for an item was last upated or modified.',
+    'definition' => 'The time at which the record was first added.',
   ));
-  tripal_associate_chado_semweb_term(NULL, 'timeaccessioned', $time_accessioned);
+  tripal_associate_chado_semweb_term(NULL, 'timeaccessioned', $term);
 
-  $time_executed = tripal_insert_cvterm(array(
+  $term = tripal_insert_cvterm(array(
     'id' => 'local:timeexecuted',
     'name' => 'time_executed',
     'cv_name' => 'local',
-    'definition' => 'The time at which a task was executed.',
+    'definition' => 'The time when the task was executed.',
+  ));
+  tripal_associate_chado_semweb_term(NULL, 'timeexecuted', $term);
+
+  $term = tripal_insert_cvterm(array(
+    'id' => 'local:infraspecific_type',
+    'name' => 'infraspecific_type',
+    'definition' => 'The connector type (e.g. subspecies, varietas, forma, etc.) for the infraspecific name',
+    'cv_name' => 'local',
+  ));
+  tripal_associate_chado_semweb_term('organism', 'type_id', $term);
+
+  $term = tripal_insert_cvterm(array(
+    'id' => 'local:abbreviation',
+    'name' => 'abbreviation',
+    'cv_name' => 'local',
+    'definition' => 'A shortened name (or abbreviation) for the item.'
+  ));
+  tripal_associate_chado_semweb_term('organism', 'abbreviation', $term);
+
+  $term = tripal_insert_cvterm(array(
+    'id' => 'local:expression',
+    'name' => 'expression',
+    'definition' => 'Curated expression data',
+    'cv_name' => 'local',
+  ));
+
+  $term = tripal_insert_cvterm(array(
+    'id' => 'local:is_analysis',
+    'name' => 'is_analysis',
+    'definition' => 'Indicates if this feature was predicted computationally using another feature.',
+    'cv_name' => 'local',
+  ));
+  tripal_associate_chado_semweb_term('feature', 'is_analysis', $term);
+
+  $term = tripal_insert_cvterm(array(
+    'id' => 'local:is_obsolete',
+    'name' => 'is_obsolete',
+    'definition' => 'Indicates if this record is obsolete.',
+    'cv_name' => 'local',
+  ));
+  tripal_associate_chado_semweb_term(NULL, 'is_obsolete', $term);
+
+}
+/**
+ * Adds the Systems Biology Ontology database and terms.
+ */
+function tripal_chado_populate_vocab_SBO() {
+  tripal_insert_db(array(
+    'name' => 'SBO',
+    'description' => 'Systems Biology.',
+    'url' => 'http://www.ebi.ac.uk/sbo/main/',
+    'urlprefix' => 'http://purl.obolibrary.org/obo/{db}_{accession}',
+  ));
+  tripal_insert_cv('sbo','Systems Biology.  Terms commonly used in Systems Biology, and in particular in computational modeling.');
+
+  $dbxref = tripal_insert_cvterm(array(
+    'id' => 'SBO:0000358',
+    'name' => 'phenotype',
+    'cv_name' => 'sbo',
+    'definition' => 'A biochemical network can generate phenotypes or affects biological processes. Such processes can take place at different levels and are independent of the biochemical network itself.',
   ));
-  tripal_associate_chado_semweb_term(NULL, 'timeaccessioned', $time_executed);
 
   $dbxref = tripal_insert_cvterm(array(
     'id' => 'SBO:0000554',
@@ -175,10 +338,21 @@ function tripal_chado_populate_chado_semweb_table() {
     'cv_name' => 'sbo',
     'definition' => 'connectedness between entities and/or interactions representing their relatedness or influence. [ src_code:NR ]',
   ));
+}
+
+/**
+ * Adds the Software Ontology database and terms.
+ */
+function tripal_chado_populate_vocab_SWO() {
+  tripal_insert_db(array(
+    'name' => 'SWO',
+    'description' => 'Software Ontology',
+    'url' => 'http://theswo.sourceforge.net/',
+    'urlprefix' => '',
+  ));
+  tripal_insert_cv('swo','Software Ontology. An ontology representation of the NCBI organismal taxonomy.');
+
 
-  //
-  // ANALYSIS TABLE
-  //
   $term = tripal_insert_cvterm(array(
     'id' => 'SWO:0000001',
     'name' => 'software',
@@ -191,59 +365,58 @@ function tripal_chado_populate_chado_semweb_table() {
       'specific operations.',
   ));
   tripal_associate_chado_semweb_term('analysis', 'program', $term);
+}
 
-  $term = tripal_insert_cvterm(array(
-    'id' => 'IAO:0000129',
-    'name' => 'version number',
-    'cv_name' => 'IAO',
-    'definition' => 'A version number is an ' .
-    'information content entity which is a sequence of characters ' .
-    'borne by part of each of a class of manufactured products or its ' .
-    'packaging and indicates its order within a set of other products ' .
-    'having the same name.',
+/**
+ * Adds the Taxonomic Rank Ontology database and terms.
+ */
+function tripal_chado_populate_vocab_TAXRANK() {
+  tripal_insert_db(array(
+    'name' => 'TAXRANK',
+    'description' => 'Taxonomic rank vocabulary.',
+    'url' => 'https://github.com/phenoscape/taxrank',
+    'urlprefix' => 'http://purl.obolibrary.org/obo/TAXRANK_',
   ));
-  tripal_associate_chado_semweb_term('analysis', 'programversion', $term);
+  tripal_insert_cv('taxrank','Taxonomic rank vocabulary. A vocabulary of taxonomic ranks (species, family, phylum, etc).');
 
-  $term = tripal_insert_cvterm(array(
-    'id' => 'IAO:0000064',
-    'name' => 'algorithm',
-    'cv_name' => 'IAO',
-    'definition' => 'An algorithm is a set of instructions for performing a paticular calculation.',
-  ));
-  tripal_associate_chado_semweb_term('analysis', 'algorithm', $term);
 
-  //
-  // ORGANISM TABLE
-  //
   $term = tripal_insert_cvterm(array(
     'id' => 'TAXRANK:0000005',
     'name' => 'genus',
-    'cv_name' => 'taxrank',
+    'cv_name' => 'taxonomic_rank',
+    'description' => 'Taxonomic rank of Genus'
   ));
   tripal_associate_chado_semweb_term('organism', 'genus', $term);
 
   $term = tripal_insert_cvterm(array(
     'id' => 'TAXRANK:0000006',
     'name' => 'species',
-    'cv_name' => 'taxrank',
+    'cv_name' => 'taxonomic_rank',
+    'description' => 'Taxonomic rank of species.'
   ));
   tripal_associate_chado_semweb_term('organism', 'species', $term);
 
   $term = tripal_insert_cvterm(array(
     'id' => 'TAXRANK:0000045',
     'name' => 'infraspecies',
-    'cv_name' => 'taxrank',
+    'cv_name' => 'taxonomic_rank',
+    'description' => 'Taxonomic infraspecies name.'
   ));
   tripal_associate_chado_semweb_term('organism', 'infraspecific_name', $term);
+}
 
-
-  $term = tripal_insert_cvterm(array(
-    'id' => 'local:infraspecific_type',
-    'name' => 'infraspecific_type',
-    'definition' => 'The connector type for the infraspecific name',
-    'cv_name' => 'local',
+/**
+ * Adds the NCBI Taxon vocabulary database and terms.
+ */
+function tripal_chado_populate_vocab_NCBITAXON() {
+  tripal_insert_db(array(
+    'name' => 'NCBITaxon',
+    'description' => 'NCBI organismal classification.',
+    'url' => 'http://www.berkeleybop.org/ontologies/ncbitaxon/',
+    'urlprefix' => 'http://purl.obolibrary.org/obo/ncbitaxon#',
   ));
-  tripal_associate_chado_semweb_term('organism', 'type_id', $term);
+  tripal_insert_cv('ncbitaxon','NCBI organismal classification. An ontology representation of the NCBI organismal taxonomy.');
+
 
   $term = tripal_insert_cvterm(array(
     'id' => 'NCBITaxon:common_name',
@@ -251,31 +424,6 @@ function tripal_chado_populate_chado_semweb_table() {
     'cv_name' => 'ncbitaxon',
   ));
   tripal_associate_chado_semweb_term('organism', 'common_name', $term);
-
-  $term = tripal_insert_cvterm(array(
-    'id' => 'local:abbreviation',
-    'name' => 'abbreviation',
-    'cv_name' => 'local',
-  ));
-  tripal_associate_chado_semweb_term('organism', 'abbreviation', $term);
-
-  //
-  // FEATURE TABLE
-  //
-  tripal_associate_chado_semweb_term('feature', 'name', $alternate_name);
-
-  //
-  // PUB TABLE
-  //
-  tripal_associate_chado_semweb_term('pub', 'uniquename', $comment);
-
-
-  //
-  // STOCK TABLE
-  //
-  tripal_associate_chado_semweb_term('stock', 'name', $alternate_name);
-
-
 }
 
 /**
@@ -290,7 +438,7 @@ function tripal_chado_semweb_form($form, &$form_state, $chado_table = NULL) {
   $chado_tables = array_merge(array('Select a Chado Table'), $chado_tables);
   // Make sure the table name exists. If not, reset it.
   $chado_table = in_array($chado_table, $chado_tables) ? $chado_table: NULL;
-  
+
   $form['chado_table'] = array(
     '#type' => 'select',
     '#title' => 'Chado Table',
@@ -310,7 +458,7 @@ function tripal_chado_semweb_form($form, &$form_state, $chado_table = NULL) {
   if ($chado_table) {
     $schema = chado_get_schema($chado_table);
     $pk = $schema['primary key'][0];
-    $cv_default = 
+    $cv_default =
       db_select('tripal_cv_defaults', 'tc')
       ->fields('tc', array('field_name'))
       ->condition('table_name', $chado_table)
@@ -322,7 +470,7 @@ function tripal_chado_semweb_form($form, &$form_state, $chado_table = NULL) {
     foreach ($columns AS $column => $detail) {
       // Do not show column if it's the primary key or default cv
       if ($column != $pk && $column != $cv_default) {
-        $cvterm_id = 
+        $cvterm_id =
           db_select('chado_semweb', 'cs')
           ->fields('cs', array('cvterm_id'))
           ->condition('chado_table', $chado_table)
@@ -372,7 +520,7 @@ function tripal_chado_semweb_form($form, &$form_state, $chado_table = NULL) {
 /**
  * Implements hook_form()
  * Edit terms used by the semantic web
- * 
+ *
  * @param $form
  * @param $form_state
  * @param $table
@@ -380,7 +528,7 @@ function tripal_chado_semweb_form($form, &$form_state, $chado_table = NULL) {
  * @return $form
  */
 function tripal_chado_semweb_edit_form($form, &$form_state, $table = NULL, $column = NULL) {
-  
+
   $term_name = array_key_exists('values', $form_state) ? $form_state['values']['term_name'] : '';
 
   $form['chado_table'] = array(
@@ -465,7 +613,7 @@ function tripal_chado_semweb_edit_form($form, &$form_state, $table = NULL, $colu
       '#name' => 'use_cvterm'
     );
   }
-  
+
   $form['cancel_button'] = array(
     '#type' => 'button',
     '#value' => t('Cancel'),
@@ -533,14 +681,14 @@ function tripal_chado_semweb_edit_form_submit($form, &$form_state) {
         $column = $form_state['values']['column'];
         $cvterm_id = $form_state['values']['#selected_cvterm_id'];
         // Check if there is already a record
-        $record_id = 
+        $record_id =
           db_select('chado_semweb', 'cs')
           ->fields('cs', array('chado_semweb_id'))
           ->condition('chado_table', $table_name)
           ->condition('chado_column', $column)
           ->execute()
           ->fetchField();
-        
+
         // If the record exists, update it
         if ($record_id) {
           db_update('chado_semweb')
@@ -591,28 +739,28 @@ function tripal_chado_semweb_reset_form($form, &$form_state, $table = NULL, $col
     '#type' => 'value',
     '#value' => $column
   );
-  
+
   $form['submit_button'] = array(
     '#type' => 'submit',
     '#value' => t('Reset'),
     '#name' => 'reset_term'
   );
-  
+
   $form['cancel_button'] = array(
     '#type' => 'button',
     '#value' => t('Cancel'),
     '#name' => 'cancel_button',
     '#limit_validation_errors' => array()
   );
-  
+
   return $form;
 }
 
 /**
  * Implements hook_form_validate()
- * 
+ *
  * Validate function for resetting the semantic web term
- * 
+ *
  * @param unknown $form
  * @param unknown $form_state
  */

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

@@ -320,25 +320,16 @@ function tripal_chado_prepare_chado() {
     //                              Entity Bundles
     /////////////////////////////////////////////////////////////////////////////
 
+    // First, populate the semantic web associations for Chado tables/fields.
+    module_load_include('inc', 'tripal_chado', 'includes/tripal_chado.semweb');
+    tripal_chado_populate_chado_semweb_table();
+
     // Unfortunately, some Chado base tables do not have a type_id, so we must
     // take special action for those tables.  These include: organism and
     // analysis. Until we can find an appropriate controlled vocabulary
     // that is well supported by the community with types for these tables we
     // will have to use in-house terms.
 
-    // Add a term to be used for an inherent 'type_id' for the organism table.
-    tripal_insert_cvterm(array(
-      'id' => 'local:organism',
-      'name' => 'organism',
-      'definition' => 'An individual form of life, such as a bacterium, protist, ' .
-        'fungus, plant, or animal, composed of a single cell or a complex of cells  ' .
-        'in which organelles or organs work together to carry out the various  ' .
-        'processes of life. (American Heritage® Dictionary of the English ' .
-        'Language, Fifth Edition. Copyright © 2011 by Houghton Mifflin ' .
-        'Harcourt Publishing Company).',
-      'cv_name' => 'local',
-    ));
-
     // Add a term to be used for an inherent 'type_id' for the organism table.
     tripal_insert_cvterm(array(
       'id' => 'local:analysis',
@@ -369,17 +360,6 @@ function tripal_chado_prepare_chado() {
       'cv_name' => 'local',
     ));
 
-    tripal_insert_cvterm(array(
-      'id' => 'local:md5_checksum',
-      'name' => 'md5_checksum',
-      'definition' => 'The MD5 message-digest algorithm is a widely used ' .
-         'cryptographic hash function producing a 128-bit (16-byte) hash ' .
-         'value, typically expressed in text format as a 32-digit hexadecimal ' .
-         'number. MD5 has been utilized in a wide variety of cryptographic ' .
-         'applications and is also commonly used to verify data integrity (Wikipedia)',
-      'cv_name' => 'local',
-    ));
-
     tripal_insert_cvterm(array(
       'id' => 'local:relationship',
       'name' => 'relationship',
@@ -417,34 +397,24 @@ function tripal_chado_prepare_chado() {
     module_load_include('inc', 'tripal', 'api/tripal.api');
     module_load_include('inc', 'tripal', 'includes/tripal.admin');
 
-    // Create the 'Organism' entity type. This uses the local:organism term.
+    // Create the 'Organism' entity type. This uses the obi:organism term.
     $error = '';
-    $term = array('name' => 'organism', 'cv_id' => array('name' => 'local'));
-    $cvterm = chado_generate_var('cvterm', $term);
-    if (!tripal_create_bundle('local', 'organism', 'organism', $error)) {
+    if (!tripal_create_bundle('OBI', '0100026', 'organism', $error)) {
       throw new Exception($error);
     }
 
     // Create the 'Analysis' entity type. This uses the local:analysis term.
     $error = '';
-    $term = array('name' => 'analysis', 'cv_id' => array('name' => 'local'));
-    $cvterm = chado_generate_var('cvterm', $term);
     if (!tripal_create_bundle('local', 'analysis', 'analysis', $error)) {
       throw new Exception($error);
     }
 
     // Create the 'Project' entity type. This uses the local:project term.
     $error = '';
-    $term = array('name' => 'project', 'cv_id' => array('name' => 'local'));
-    $cvterm = chado_generate_var('cvterm', $term);
     if (!tripal_create_bundle('local', 'project', 'project', $error)) {
       throw new Exception($error);
     }
 
-    // Finally deal with the semantic web associations.
-    module_load_include('inc', 'tripal_chado', 'includes/tripal_chado.semweb');
-    tripal_chado_populate_chado_semweb_table();
-
     // Set a variable to indicate the site is prepared.
     variable_set('tripal_chado_is_prepared', TRUE);
   }

+ 8 - 20
tripal_chado/includes/tripal_chado.vocab_storage.inc

@@ -22,25 +22,13 @@ function tripal_chado_vocab_storage_info() {
  * This hook is created by the Tripal module and is not a Drupal hook.
  */
 function tripal_chado_vocab_get_term($vocabulary, $accession) {
-  // Create an empty term array for returning if there is a problem.
-  $empty_term = array(
-    'vocabulary' => $vocabulary,
-    'accession'  => $accession,
-    'name'       => '',
-    'definition' => 'Term is undefined.',
-    'url'  => '',
-    // The following are not required for the returned array but we'll
-    // add these for convenience later when we look at the TripalTerm
-    // objects and these will be there.
-    'cvterm'     => NULL,
-  );
 
   // It's possible that Chado is not available (i.e. it gets renamed
   // for copying) but Tripal has already been prepared and the
   // entities exist.  If this is the case we don't want to run the
   // commands below.
   if (!chado_table_exists('cvterm')) {
-    return $empty_term;
+    return FALSE;
   }
   $match = array(
     'dbxref_id' => array(
@@ -52,24 +40,24 @@ function tripal_chado_vocab_get_term($vocabulary, $accession) {
   );
   $cvterm = chado_generate_var('cvterm', $match);
   if (!$cvterm) {
-    return $empty_term;
+    return FALSE;
   }
   $cvterm = chado_expand_var($cvterm, 'field', 'cvterm.definition');
   $term = array(
-    'vocabulary' => $cvterm->dbxref_id->db_id->name,
+    'vocabulary' => array(
+      'name' => $cvterm->dbxref_id->db_id->name,
+      'description' =>  $cvterm->dbxref_id->db_id->description,
+      'url' => $cvterm->dbxref_id->db_id->url
+    ),
     'accession'  => $cvterm->dbxref_id->accession,
     'name'       => $cvterm->name,
-    'url'        => '',
+    'url'        => tripal_get_dbxref_url($cvterm->dbxref_id),
     'definition' => (isset($cvterm->definition)) ? $cvterm->definition : '',
     // The following are not required for the returned array but we'll
     // add these for convenience later when we look at the TripalTerm
     // objects and these will be there.
     'cvterm'     => $cvterm,
   );
-  if ($cvterm->dbxref_id->db_id->urlprefix) {
-    $term['url'] = $cvterm->dbxref_id->db_id->urlprefix .
-      $cvterm->dbxref_id->db_id->name . ':' . $cvterm->dbxref_id->accession;
-  }
   return $term;
 }
 

+ 27 - 13
tripal_ws/includes/tripal_ws.rest.inc

@@ -368,8 +368,6 @@ function tripal_ws_get_content_type($api_url, &$response, $ws_path, $ctype, $par
   $response['totalItems'] = 0;
   $response['label'] = $bundle->label . " collection";
 
-
-
   // Organize the fields by their web service names.
   $fields = field_info_fields();
   $field_ws_names = array();
@@ -475,7 +473,8 @@ function tripal_ws_get_content($api_url, &$response, $ws_path, $ctype, $entity_i
 
   // Next add in the ID and Type for this resources.
   $response['@id'] = $api_url . '/content/' . $ctype . '/' . $entity_id;
-  $response['@type'] = $vocab->vocabulary . ':' . $term->accession;
+  $response['@type'] = $term->name;
+  $context_terms[$term->name] = $term->url;
   $response['label'] = $entity->title;
   $response['itemPage'] = url('/bio_data/' . $entity->id, array('absolute' => TRUE));
 
@@ -499,6 +498,11 @@ function tripal_ws_get_content($api_url, &$response, $ws_path, $ctype, $entity_i
   //$response['fields'] = $fields;
   foreach ($instances as $field_name => $instance) {
 
+    // Ignore the content_type field provided by Tripal.
+    if ($field_name == 'content_type') {
+      continue;
+    }
+
     // Skip hidden fields.
     if ($instance['display']['default']['type'] == 'hidden') {
       continue;
@@ -509,8 +513,8 @@ function tripal_ws_get_content($api_url, &$response, $ws_path, $ctype, $entity_i
     $field = field_info_field($field_name);
 
     // Get the details for this field for the JSON-LD response.
-    $details = tripal_ws_get_field_JSON_LD($field, $instance);
-    print_r($details);
+    $details = tripal_ws_get_field_JSON_LD($entity, $field, $instance, $api_url, $ctype);
+    //print_r($details);
     $context_vocabs += $details['context']['vocabs'];
     $context_terms += $details['context']['terms'];
     $response += $details['value'];
@@ -536,7 +540,7 @@ function tripal_ws_get_content($api_url, &$response, $ws_path, $ctype, $entity_i
 /**
  *
  */
-function tripal_ws_get_field_JSON_LD($field, $instance) {
+function tripal_ws_get_field_JSON_LD($entity, $field, $instance, $api_url, $ctype) {
 
   // Initialized the context array.
   $context = array();
@@ -551,12 +555,19 @@ function tripal_ws_get_field_JSON_LD($field, $instance) {
   // term from the vocabulary that the field is assigned. But in the
   // case that the field is not assigned a term, we must use the field name.
   $key = $field_name;
+  $key = strtolower(preg_replace('/ /', '_', $key));
   if (array_key_exists('semantic_web', $field_settings) and $field_settings['semantic_web']) {
     list($vocabulary, $accession) = explode(':', $field_settings['semantic_web']);
     $term = tripal_get_term_details($vocabulary, $accession);
-    $key = $term['name'];
-    $context['vocabs'][$vocabulary] = $term['url'];
-    $context['terms'][$key] = $field_settings['semantic_web'];
+    if ($term) {
+      $key = $term['name'];
+      $key = strtolower(preg_replace('/ /', '_', $key));
+      //$context['vocabs'][$vocabulary] = ;
+      $context['terms'][$key] = array(
+        '@id' => $term['url'],
+//        $field_settings['semantic_web'];
+      );
+    }
   }
 
   // Don't show fields that are not meant to be auto attached, even if the
@@ -564,9 +575,9 @@ function tripal_ws_get_field_JSON_LD($field, $instance) {
   // We want the end-user to specifically load these.
   $value = array();
   $instance_settings = $instance['settings'];
-  if (array_key_exists('auto_attach', $instance_settings) and
-      $instance_settings['auto_attach'] === TRUE) {
 
+  if (array_key_exists('auto_attach', $instance_settings) and
+      $instance_settings['auto_attach'] == TRUE) {
     $items = field_get_items('TripalEntity', $entity, $field_name);
     for ($i = 0; $i < count($items); $i++) {
 
@@ -586,7 +597,9 @@ function tripal_ws_get_field_JSON_LD($field, $instance) {
 
         if (property_exists($lvocab, 'vocabulary') and !array_key_exists($lvocab->vocabulary, $response['@context'])) {
           $lterm_details = tripal_get_term_details($lvocab->vocabulary, $lterm->vocabulary);
-          $context[$lvocab->vocabulary] = $lterm_details->url;
+          if ($lterm_details) {
+            $context[$lvocab->vocabulary] = $lterm_details->url;
+          }
         }
       }
       else {
@@ -597,7 +610,8 @@ function tripal_ws_get_field_JSON_LD($field, $instance) {
   // If the value shouldn't be attached by default then create a link for the
   // caller to retrieve the information.
   else {
-    $value[] = $api_url . '/content/' . $ctype . '/' . $entity_id;
+    $context['terms'][$key]['@type'] = '@id';
+    $value[] = $api_url . '/content/' . $ctype . '/' . $entity->id . '/' . urlencode($key);
   }
   // Convert a single value to not be an array.
   if (count($value) == 1) {