Browse Source

Merge branch '7.x-2.x' of git.drupal.org:sandbox/spficklin/1337878 into 7.x-2.x

Lacey Sanderson 11 years ago
parent
commit
e52670b671
92 changed files with 1385 additions and 1038 deletions
  1. 1 1
      tripal_analysis/theme/templates/tripal_analysis_base.tpl.php
  2. 1 1
      tripal_analysis/theme/templates/tripal_analysis_properties.tpl.php
  3. 1 1
      tripal_analysis/theme/templates/tripal_analysis_teaser.tpl.php
  4. 1 3
      tripal_bulk_loader/tripal_bulk_loader.module
  5. 2 2
      tripal_contact/theme/templates/tripal_contact_properties.tpl.php
  6. 4 4
      tripal_contact/theme/templates/tripal_contact_publications.tpl.php
  7. 3 3
      tripal_contact/theme/templates/tripal_contact_relationships.tpl.php
  8. 1 1
      tripal_core/api/tripal_core.chado_general.api.inc
  9. 0 0
      tripal_core/includes/tripal_core.chado_install.inc
  10. 0 0
      tripal_core/includes/tripal_core.custom_tables.inc
  11. 0 0
      tripal_core/includes/tripal_core.form_elements.inc
  12. 0 0
      tripal_core/includes/tripal_core.jobs.inc
  13. 0 0
      tripal_core/includes/tripal_core.mviews.inc
  14. 2 2
      tripal_core/theme/templates/node--chado-generic.tpl.php
  15. 5 5
      tripal_core/tripal_core.module
  16. 2 2
      tripal_cv/api/tripal_cv.api.inc
  17. 116 1
      tripal_cv/includes/tripal_cv.admin.inc
  18. 6 12
      tripal_cv/tripal_cv.module
  19. 2 2
      tripal_db/api/tripal_db.api.inc
  20. 1 1
      tripal_example/includes/tripal_example.chado_node.inc
  21. 0 0
      tripal_example/theme/css/tripal_example.css
  22. 9 0
      tripal_example/theme/js/tripal_example.js
  23. 1 1
      tripal_example/theme/templates/tripal_example_properties.tpl.php
  24. 7 7
      tripal_example/theme/templates/tripal_example_relationships.tpl.php
  25. 14 0
      tripal_example/theme/templates/tripal_example_teaser.tpl.php
  26. 1 0
      tripal_example/theme/templates/tripal_organism_examples.tpl.php
  27. 2 2
      tripal_example/tripal_example.info
  28. 8 8
      tripal_feature/api/tripal_feature.DEPRECATED.inc
  29. 266 220
      tripal_feature/api/tripal_feature.api.inc
  30. 4 4
      tripal_feature/includes/tripal_feature.chado_node.inc
  31. 10 7
      tripal_feature/theme/css/tripal_feature.css
  32. 12 8
      tripal_feature/theme/js/tripal_feature.js
  33. 2 2
      tripal_feature/theme/templates/tripal_feature_alignments.tpl.php
  34. 1 1
      tripal_feature/theme/templates/tripal_feature_analyses.tpl.php
  35. 3 3
      tripal_feature/theme/templates/tripal_feature_properties.tpl.php
  36. 4 4
      tripal_feature/theme/templates/tripal_feature_publications.tpl.php
  37. 1 1
      tripal_feature/theme/templates/tripal_feature_references.tpl.php
  38. 3 3
      tripal_feature/theme/templates/tripal_feature_relationships.tpl.php
  39. 191 31
      tripal_feature/theme/templates/tripal_feature_sequence.tpl.php
  40. 1 1
      tripal_feature/theme/templates/tripal_feature_synonyms.tpl.php
  41. 1 1
      tripal_feature/theme/templates/tripal_feature_terms.tpl.php
  42. 1 1
      tripal_feature/theme/templates/tripal_organism_feature_browser.tpl.php
  43. 584 1
      tripal_feature/theme/tripal_feature.theme.inc
  44. 0 580
      tripal_feature/tripal_feature.module
  45. 2 2
      tripal_featuremap/theme/templates/tripal_feature_featurepos.tpl.php
  46. 1 1
      tripal_featuremap/theme/templates/tripal_featuremap_base.tpl.php
  47. 2 2
      tripal_featuremap/theme/templates/tripal_featuremap_featurepos.tpl.php
  48. 2 2
      tripal_featuremap/theme/templates/tripal_featuremap_properties.tpl.php
  49. 4 4
      tripal_featuremap/theme/templates/tripal_featuremap_publication.tpl.php
  50. 1 1
      tripal_featuremap/theme/templates/tripal_featuremap_references.tpl.php
  51. 1 1
      tripal_featuremap/theme/templates/tripal_featuremap_teaser.tpl.php
  52. 3 3
      tripal_genetic/theme/templates/tripal_feature_genotypes.tpl.php
  53. 3 3
      tripal_genetic/theme/templates/tripal_stock_genotypes.tpl.php
  54. 1 1
      tripal_library/theme/templates/tripal_feature_libraries.tpl.php
  55. 1 1
      tripal_library/theme/templates/tripal_library_features.tpl.php
  56. 2 2
      tripal_library/theme/templates/tripal_library_properties.tpl.php
  57. 4 4
      tripal_library/theme/templates/tripal_library_publications.tpl.php
  58. 1 1
      tripal_library/theme/templates/tripal_library_references.tpl.php
  59. 1 1
      tripal_library/theme/templates/tripal_library_synonyms.tpl.php
  60. 1 1
      tripal_library/theme/templates/tripal_library_terms.tpl.php
  61. 1 1
      tripal_library/theme/templates/tripal_organism_libraries.tpl.php
  62. 5 5
      tripal_natural_diversity/theme/templates/tripal_feature_nd_genotypes.tpl.php
  63. 3 3
      tripal_natural_diversity/theme/templates/tripal_stock_nd_genotypes.tpl.php
  64. 1 1
      tripal_natural_diversity/theme/templates/tripal_stock_nd_phenotypes.tpl.php
  65. 1 1
      tripal_organism/theme/templates/tripal_organism_base.tpl.php
  66. 2 2
      tripal_organism/theme/templates/tripal_organism_properties.tpl.php
  67. 1 1
      tripal_organism/theme/templates/tripal_organism_references.tpl.php
  68. 4 4
      tripal_phenotype/theme/templates/tripal_feature_phenotypes.tpl.php
  69. 3 3
      tripal_project/theme/templates/tripal_project_contact.tpl.php
  70. 2 2
      tripal_project/theme/templates/tripal_project_properties.tpl.php
  71. 4 4
      tripal_project/theme/templates/tripal_project_publications.tpl.php
  72. 3 3
      tripal_project/theme/templates/tripal_project_relationships.tpl.php
  73. 4 4
      tripal_pub/theme/templates/tripal_pub_authors.tpl.php
  74. 11 11
      tripal_pub/theme/templates/tripal_pub_base.tpl.php
  75. 1 1
      tripal_pub/theme/templates/tripal_pub_featuremaps.tpl.php
  76. 1 1
      tripal_pub/theme/templates/tripal_pub_features.tpl.php
  77. 1 1
      tripal_pub/theme/templates/tripal_pub_libraries.tpl.php
  78. 1 1
      tripal_pub/theme/templates/tripal_pub_projects.tpl.php
  79. 2 2
      tripal_pub/theme/templates/tripal_pub_properties.tpl.php
  80. 1 1
      tripal_pub/theme/templates/tripal_pub_references.tpl.php
  81. 7 7
      tripal_pub/theme/templates/tripal_pub_relationships.tpl.php
  82. 1 1
      tripal_pub/theme/templates/tripal_pub_stocks.tpl.php
  83. 4 4
      tripal_pub/theme/templates/tripal_pub_teaser.tpl.php
  84. 1 1
      tripal_stock/theme/templates/tripal_organism_stocks.tpl.php
  85. 2 2
      tripal_stock/theme/templates/tripal_stock_base.tpl.php
  86. 1 1
      tripal_stock/theme/templates/tripal_stock_collections.tpl.php
  87. 3 3
      tripal_stock/theme/templates/tripal_stock_properties.tpl.php
  88. 4 4
      tripal_stock/theme/templates/tripal_stock_publications.tpl.php
  89. 1 1
      tripal_stock/theme/templates/tripal_stock_references.tpl.php
  90. 3 3
      tripal_stock/theme/templates/tripal_stock_relationships.tpl.php
  91. 1 1
      tripal_stock/theme/templates/tripal_stock_synonyms.tpl.php
  92. 1 1
      tripal_stock/theme/templates/tripal_stock_teaser.tpl.php

+ 1 - 1
tripal_analysis/theme/templates/tripal_analysis_base.tpl.php

@@ -1,6 +1,6 @@
 <?php
 $analysis = $variables['node']->analysis;
-$analysis = tripal_core_expand_chado_vars($analysis,'field','analysis.description'); ?>
+$analysis = chado_expand_var($analysis,'field','analysis.description'); ?>
 
 <div class="tripal__analysis-data-block-desc tripal-data-block-desc"></div><?php 
   

+ 1 - 1
tripal_analysis/theme/templates/tripal_analysis_properties.tpl.php

@@ -2,7 +2,7 @@
 
 // get the analysis object and expand it to include the records from the analysisprop table
 $analysis = $variables['node']->analysis;
-$analysis = tripal_core_expand_chado_vars($analysis,'table', 'analysisprop', array('return_array' => 1));
+$analysis = chado_expand_var($analysis,'table', 'analysisprop', array('return_array' => 1));
 $properties = $analysis->analysisprop;
 
 if (count($properties) > 0) { ?>

+ 1 - 1
tripal_analysis/theme/templates/tripal_analysis_teaser.tpl.php

@@ -1,7 +1,7 @@
 <?php
 $node = $variables['node'];
 $analysis = $variables['node']->analysis;
-$analysis = tripal_core_expand_chado_vars($analysis,'field','analysis.description'); ?>
+$analysis = chado_expand_var($analysis,'field','analysis.description'); ?>
 
 <div class="tripal_analysis_blast-teaser tripal-teaser"> 
   <div class="tripal-analysis-blast-teaser-title tripal-teaser-title"><?php 

+ 1 - 3
tripal_bulk_loader/tripal_bulk_loader.module

@@ -36,9 +36,7 @@ require_once 'api/tripal_bulk_loader.DEPRECATED.inc';
  * @ingroup tripal_bulk_loader
  */
 function tripal_bulk_loader_init() {
-  // Add javascript and style sheet
-  drupal_add_css(drupal_get_path('theme', 'tripal') . '/css/tripal_bulk_loader.css');
-  drupal_add_js(drupal_get_path('theme', 'tripal') . '/js/tripal_bulk_loader.js');
+
 }
 
 /**

+ 2 - 2
tripal_contact/theme/templates/tripal_contact_properties.tpl.php

@@ -2,7 +2,7 @@
 
 // expand the contact to include the properties.
 $contact = $variables['node']->contact;
-$contact = tripal_core_expand_chado_vars($contact,'table', 'contactprop', array('return_array' => 1));
+$contact = chado_expand_var($contact,'table', 'contactprop', array('return_array' => 1));
 $contactprops = $contact->contactprop;
 
 // put the properties in an array so we can remove the contact_description property
@@ -12,7 +12,7 @@ if ($contactprops) {
     // we want to keep all properties but the contact_description as that
     // property is shown on the base template page.
     if($property->type_id->name != 'contact_description') {
-      $property = tripal_core_expand_chado_vars($property,'field','contactprop.value');
+      $property = chado_expand_var($property,'field','contactprop.value');
       $properties[] = $property;
     }
   }

+ 4 - 4
tripal_contact/theme/templates/tripal_contact_publications.tpl.php

@@ -3,7 +3,7 @@ $contact = $variables['node']->contact;
 
 // expand contact to include pubs 
 $options = array('return_array' => 1);
-$contact = tripal_core_expand_chado_vars($contact, 'table', 'pubauthor_contact', $options);
+$contact = chado_expand_var($contact, 'table', 'pubauthor_contact', $options);
 $pubauthor_contacts = $contact->pubauthor_contact; 
 
 
@@ -23,7 +23,7 @@ if (count($pubauthor_contacts) > 0) { ?>
   
   foreach ($pubauthor_contacts as $pubauthor_contact) {
     $pub = $pubauthor_contact->pubauthor_id->pub_id;
-    $pub = tripal_core_expand_chado_vars($pub, 'field', 'pub.title');
+    $pub = chado_expand_var($pub, 'field', 'pub.title');
     $citation = $pub->title;  // use the title as the default citation
     
     // get the citation for this pub if it exists
@@ -34,9 +34,9 @@ if (count($pubauthor_contacts) > 0) { ?>
       ),
     );
     $options = array('return_array' => 1);
-    $citation_prop = tripal_core_generate_chado_var('pubprop', $values, $options); 
+    $citation_prop = chado_generate_var('pubprop', $values, $options); 
     if (count($citation_prop) == 1) {
-      $citation_prop = tripal_core_expand_chado_vars($citation_prop, 'field', 'pubprop.value');
+      $citation_prop = chado_expand_var($citation_prop, 'field', 'pubprop.value');
       $citation = $citation_prop[0]->value;
     }
     

+ 3 - 3
tripal_contact/theme/templates/tripal_contact_relationships.tpl.php

@@ -1,12 +1,12 @@
 <?php
 /* Typically in a Tripal template, the data needed is retrieved using a call to
- * tripal_core_expand_chado_vars function.  For example, to retrieve all 
+ * chado_expand_var function.  For example, to retrieve all 
  * of the contact relationships for this node, the following function call would be made:
  * 
- *   $contact = tripal_core_expand_chado_vars($contact,'table','contact_relationship');
+ *   $contact = chado_expand_var($contact,'table','contact_relationship');
  * 
  * However, this function call can be extremely slow when there are numerous relationships.
- * This is because the tripal_core_expand_chado_vars function is recursive and expands 
+ * This is because the chado_expand_var function is recursive and expands 
  * all data following the foreign key relationships tree.  Therefore, to speed retrieval
  * of data, a special variable is provided to this template:
  * 

+ 1 - 1
tripal_core/api/tripal_core.chado_general.api.inc

@@ -18,7 +18,7 @@ require_once 'tripal_core.schema_v1.11.api.inc';
  * for inserts and updates.
  *
  * Also, a set of functions is provided for creating template variables.  First,
- * is the tripal_core_generate_chado_vars which is used to select one ore more
+ * is the chado_generate_var which is used to select one ore more
  * records from a table and return an array with foreign key relationships fully
  * populated.  For example, if selecting a feature, the organism_id and type_id
  * would be present in the returned array as a nested array with their respective

+ 0 - 0
tripal_core/includes/chado_install.inc → tripal_core/includes/tripal_core.chado_install.inc


+ 0 - 0
tripal_core/includes/custom_tables.inc → tripal_core/includes/tripal_core.custom_tables.inc


+ 0 - 0
tripal_core/includes/form_elements.inc → tripal_core/includes/tripal_core.form_elements.inc


+ 0 - 0
tripal_core/includes/jobs.inc → tripal_core/includes/tripal_core.jobs.inc


+ 0 - 0
tripal_core/includes/mviews.inc → tripal_core/includes/tripal_core.mviews.inc


+ 2 - 2
tripal_core/theme/templates/node--chado-generic.tpl.php

@@ -3,7 +3,7 @@
 if($teaser) {
   print render($content);
 }
-else { 
+else {
   $node_type = $node->type; ?>
   
   <script type="text/javascript">
@@ -25,7 +25,7 @@ else {
   
       // if a ?block= is specified in the URL then we want to show the
       // requested block
-      var block = window.location.href.match(/[\?|\&]block=(.+?)\&/)
+      var block = window.location.href.match(/[\?|\&]block=(.+?)[\&|\#]/)
       if(block == null){
         block = window.location.href.match(/[\?|\&]block=(.+)/)
       }

+ 5 - 5
tripal_core/tripal_core.module

@@ -36,11 +36,11 @@ require_once 'api/tripal_core.tripal.api.inc';
 require_once 'api/tripal_core.DEPRECATED.inc';
 
 // INCLUDES -------------------------------------
-require_once 'includes/jobs.inc';
-require_once 'includes/mviews.inc';
-require_once 'includes/custom_tables.inc';
-require_once 'includes/chado_install.inc';
-require_once 'includes/form_elements.inc';
+require_once 'includes/tripal_core.jobs.inc';
+require_once 'includes/tripal_core.mviews.inc';
+require_once 'includes/tripal_core.custom_tables.inc';
+require_once 'includes/tripal_core.chado_install.inc';
+require_once 'includes/tripal_core.form_elements.inc';
 
 tripal_core_set_globals();
 /**

+ 2 - 2
tripal_cv/api/tripal_cv.api.inc

@@ -127,7 +127,7 @@ function tripal_get_cv($identifiers, $options = array()) {
  */
 function tripal_get_cv_select_options() {
 
-  $results = chado_select_record('cv', array('cv_id', 'name'), array());
+  $results = chado_select_record('cv', array('cv_id', 'name'), array(), array('order_by' => array('name' => 'ASC')));
 
   $options = array();
   foreach ($results as $r) {
@@ -548,7 +548,7 @@ function tripal_insert_cvterm($term, $options = array()) {
 
   // add the database. The function will just return the DB object if the
   // database already exists.
-  $db = tripal_db_get_db_by_name($dbname);
+  $db = tripal_get_db(array('name' => $dbname));
   if (!$db) {
     $db = tripal_db_add_db($dbname);
   }

+ 116 - 1
tripal_cv/includes/tripal_cv.admin.inc

@@ -52,8 +52,123 @@ function tripal_cv_admin_set_defaults_form() {
   $form = array();
   
   $form['instructions'] = array(
-    '#markup' => 'use the following...'
+    '#markup' => t('Much of the data housed in Chado is typed, meaning that a ' .
+        'controlled vocabulary describes what type of data the record is. For example, '.
+        'a feature must have a "type" which is typically a term from ' .
+        'the Sequence Ontology. Record properties typically have a type as well. '.
+        'Tripal allows the administrator to set a default type for each table in '.
+        'Chado that requires a type from a vocabulary. By default, autocomplete fields, '.
+        'type select boxes and type validation occur using the default vocabularies set below. '),
   );
   
+  // get the list of all tables that use the cvterm table as an FK
+  $cvterm_schema = chado_get_schema('cvterm');
+  $referring_tables = $cvterm_schema['referring_tables'];
+  
+  // get the list of tables that already have default set
+  $cv_defaults = db_select('tripal_cv_defaults', 'TCD')
+    ->fields('TCD', array('cv_default_id', 'table_name', 'field_name', 'cv_id'))
+    ->orderBy('table_name', 'ASC')
+    ->execute();
+  
+  // get the list of vocabularies
+  $cvs = tripal_get_cv_select_options();
+  
+  $form['settings'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Configured Defaults'),
+    '#description' => t('The following tables have a default vocabulary'),
+    '#tree' => TRUE,
+  );
+  foreach ($cv_defaults as $cv_default) {
+    $cv_default_id = $cv_default->cv_default_id;
+    $cv = tripal_get_cv(array('cv_id' => $cv_default->cv_id));
+    $form['settings']['existing'][$cv_default_id]["id"] = array(
+      '#type' => 'hidden',
+      '#value' => $cv_default_id,
+    );
+    $form['settings']['existing'][$cv_default_id]["table_name"] = array(
+      '#type' => 'markup',
+      '#markup' => $cv_default->table_name
+    );
+    $form['settings']['existing'][$cv_default_id]["field_name"] = array(
+      '#type' => 'markup',
+      '#markup' => $cv_default->field_name
+    );
+    $form['settings']['existing'][$cv_default_id]["vocabulary"] = array(
+      '#type' => 'select',
+      '#options' => $cvs,
+      '#default_value' => $cv_default->cv_id,
+      '#suffix' => '<a target="_blank" href="'. url('admin/tripal/chado/tripal_cv/cvterms') . '?cv=' . $cv->name . '">View terms</a>'
+    );
+    // remove button
+    $form['settings']['existing'][$cv_default_id]['remove'] = array(
+      '#type' => 'submit',
+      '#value' => t('Remove'),
+      '#name' => "cv_remove-$cv_default_id",
+      '#ajax' => array(
+        'callback' => "tripal_cv_admin_set_defaults_ajax_update",
+        'wrapper' => 'tripal-generic-edit-properties-table',
+        'effect'   => 'fade',
+        'method'   => 'replace',
+        'prevent'  => 'click'
+      ),
+      // When this button is clicked, the form will be validated and submitted.
+      // Therefore, we set custom submit and validate functions to override the
+      // default node form submit.  In the validate function we validate only the
+      // property fields and in the submit we remove the indicated property
+      // from the chado_properties array. In order to keep validate errors
+      // from the node form validate and Drupal required errors for non-property fields
+      // preventing the user from removing properties we set the #limit_validation_errors below
+      '#validate' => array('chado_add_node_form_properties_remove_button_validate'),
+      '#submit' => array('chado_add_node_form_properties_remove_button_submit'),
+      // Limit the validation of the form upon clicking this button to the property_table tree
+      // No other fields will be validated (ie: no fields from the main form or any other api
+      // added form).
+      '#limit_validation_errors' => array(
+        array('property_table')  // Validate all fields within $form_state['values']['property_table']
+      )
+    );
+  }
+  
   return $form;
+}
+
+/**
+ * 
+ * @param unknown $variables
+ */
+function theme_tripal_cv_admin_set_defaults_form($variables) {
+  $element = $variables['element'];
+
+  $header = array(
+    'table_name'      => array('data' => t('Table Name'),      'width' => '20%'),
+    'field_name'      => array('data' => t('Field Name'),      'width' => '20%'),
+    'vocabulary'      => array('data' => t('Default Vocabulary'), 'width' => '40%'),
+    'property_action' => array('data' => t('Actions'),    'width' => '20%'),
+  );
+
+  $rows = array();
+  
+  foreach ($element['settings']['existing'] as $key => $value) {
+    if (is_numeric($key)) {
+      $rows[] = array(
+        drupal_render($value['table_name']),
+        drupal_render($value['field_name']),
+        drupal_render($value['vocabulary']),
+        drupal_render($value['remove']),
+      );
+    }
+  } 
+  $settings_table = theme('table', array(
+    'header' => $header,
+    'rows' => $rows
+  ));
+  $element['settings']['existing'] = array(
+    '#type' => 'markup',
+    '#markup' => $settings_table,
+  );
+  
+  return drupal_render_children($element);
+  
 }

+ 6 - 12
tripal_cv/tripal_cv.module

@@ -34,17 +34,6 @@ require_once 'includes/tripal_cv.cvtermpath_form.inc';
  */
 function tripal_cv_init() {
 
-  // add the tripal_cv JS and CSS
-  drupal_add_css(drupal_get_path('module', 'tripal_cv') . '/theme/css/tripal_cv.css');
-  drupal_add_js(drupal_get_path('module', 'tripal_cv') . '/theme/js/tripal_cv.js');
-
-  // add the jgCharts.js
-  drupal_add_js(drupal_get_path('module', 'tripal_cv') . '/theme/js/jgcharts/jgcharts.js');
-
-  // add the jsTree JS and CSS
-  drupal_add_css(drupal_get_path('module', 'tripal_cv') . '/theme/js/jsTree/source/tree_component.css');
-  drupal_add_js(drupal_get_path('module', 'tripal_cv') . '/theme/js/jsTree/source/_lib.js');
-  drupal_add_js(drupal_get_path('module', 'tripal_cv') . '/theme/js/jsTree/source/tree_component.js');
 }
 
 /**
@@ -337,7 +326,12 @@ function tripal_cv_theme($existing, $type, $theme, $path) {
       'template' => 'tripal_cv_help',
       'variables' =>  array(NULL),
       'path' => "$path/theme/templates"
-    )
+    ),
+    // Default CV form
+    'tripal_cv_admin_set_defaults_form' => array(
+      'function' => 'theme_tripal_cv_admin_set_defaults_form',
+      'render element' => 'element',
+    ),
   );
 
   return $items;

+ 2 - 2
tripal_db/api/tripal_db.api.inc

@@ -37,8 +37,8 @@
  * @param $identifier
  *   An array with the key stating what the identifier is. Supported keys (only on of the
  *   following unique keys is required):
- *    - db_id: the chado cv.cv_id primary key
- *    - name: the chado cv.name field (assume unique)
+ *    - db_id: the chado db.db_id primary key
+ *    - name: the chado db.name field (assume unique)
  * @param $options
  *   An array of options. Supported keys include:
  *     - Any keys supported by chado_generate_var(). See that function definition for

+ 1 - 1
tripal_example/includes/tripal_example.chado_node.inc

@@ -566,7 +566,7 @@ function chado_example_load($nodes) {
     $example = chado_generate_var('example', $values);
 
     // for fields in the table that are of type 'text' you may want to include those
-    // by default, the tripal_core_generate_chado_var does not include text fields as
+    // by default, the chado_generate_var does not include text fields as
     // they may be very large and including a large text field can slow the page load.
     // If you know a text field will never be large and it is important for the
     // other functions that will see the node to have access to a field you can

+ 0 - 0
tripal_example/theme/css/tripal_example.css


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

@@ -0,0 +1,9 @@
+(function($) {
+  Drupal.behaviors.tripal_exampleBehavior = {
+    attach: function (context, settings){
+
+      // Place JavaScript code here
+
+    }
+  };
+})(jQuery);

+ 1 - 1
tripal_example/theme/templates/tripal_example_properties.tpl.php

@@ -6,7 +6,7 @@ $options = array(
   'return_array' => 1,
   'order_by' => array('rank' => 'ASC'),
 );
-$example = tripal_core_expand_chado_vars($example,'table', 'exampleprop', $options);
+$example = chado_expand_var($example,'table', 'exampleprop', $options);
 $exampleprops = $example->exampleprop;
 $properties = array();
 

+ 7 - 7
tripal_example/theme/templates/tripal_example_relationships.tpl.php

@@ -1,12 +1,12 @@
 <?php
 /* Typically in a Tripal template, the data needed is retrieved using a call to
- * tripal_core_expand_chado_vars function.  For example, to retrieve all 
+ * chado_expand_var function.  For example, to retrieve all 
  * of the example relationships for this node, the following function call would be made:
  * 
- *   $example = tripal_core_expand_chado_vars($example,'table','example_relationship');
+ *   $example = chado_expand_var($example,'table','example_relationship');
  * 
  * However, this function call can be extremely slow when there are numerous relationships.
- * This is because the tripal_core_expand_chado_vars function is recursive and expands 
+ * This is because the chado_expand_var function is recursive and expands 
  * all data following the foreign key relationships tree.  Therefore, to speed retrieval
  * of data, a special variable is provided to this template:
  * 
@@ -55,8 +55,8 @@ if (count($object_rels) > 0 or count($subject_rels) > 0) { ?>
             'name' => 'Citation',
           ),
         );
-        $citation = tripal_core_generate_chado_var('exampleprop', $values);
-        $citation = tripal_core_expand_chado_vars($citation, 'field', 'exampleprop.value');
+        $citation = chado_generate_var('exampleprop', $values);
+        $citation = chado_expand_var($citation, 'field', 'exampleprop.value');
         
         $rows[] = array(
           $title . '<br>' . htmlspecialchars($citation->value),
@@ -116,8 +116,8 @@ if (count($object_rels) > 0 or count($subject_rels) > 0) { ?>
             'name' => 'Citation',
           ),
         );
-        $citation = tripal_core_generate_chado_var('exampleprop', $values);
-        $citation = tripal_core_expand_chado_vars($citation, 'field', 'exampleprop.value');
+        $citation = chado_generate_var('exampleprop', $values);
+        $citation = chado_expand_var($citation, 'field', 'exampleprop.value');
         
         $rows[] = array(
           $title . '<br>' . htmlspecialchars($citation->value),

+ 14 - 0
tripal_example/theme/templates/tripal_example_teaser.tpl.php

@@ -0,0 +1,14 @@
+<?php
+$example  = $variables['node']->example; ?>
+
+<div class="tripal_example-teaser tripal-teaser"> 
+  <div class="tripal-example-teaser-title tripal-teaser-title"><?php 
+    print l("<i>$example->uniquename", "node/$node->nid", array('html' => TRUE));?>
+  </div>
+  <div class="tripal-example-teaser-text tripal-teaser-text"> <?php
+    print substr($example->description, 0, 650);
+    if (strlen($example->description) > 650) {
+      print "... " . l("[more]", "node/$node->nid");
+    } ?>
+  </div>
+</div>

+ 1 - 0
tripal_example/theme/templates/tripal_organism_examples.tpl.php

@@ -0,0 +1 @@
+<?php

+ 2 - 2
tripal_example/tripal_example.info

@@ -32,13 +32,13 @@ version = 7.x-2.0.1-alpha
 ; Stylesheets containing CSS that should always be available for the
 ; module should be specified here.  
 ;
-stylesheets[all][] = theme/css/tripal_feature.css
+stylesheets[all][] = theme/css/tripal_example.css
 
 ;
 ; Javascript files that should always be available for the
 ; module should be specified here.  
 ;
-scripts[]          = theme/js/tripal_feature.js
+scripts[]          = theme/js/tripal_example.js
 
 ; 
 ; Add additional dependencies for other modules using the module project name.

+ 8 - 8
tripal_feature/api/tripal_feature.DEPRECATED.inc

@@ -376,9 +376,9 @@ function tripal_feature_reverse_complement($sequence) {
 /**
  * @deprecated Restructured API to make naming more readable and consistent.
  * Function was deprecated in Tripal 2.0 and will be removed 2 releases from now.
- * This function has been replaced by tripal_format_sequence().
+ * This function has been replaced by tripal_get_sequence().
  *
- * @see tripal_format_sequence().
+ * @see tripal_get_sequence().
  */
 function tripal_feature_get_formatted_sequence($feature_id, $feature_name, $num_bases_per_line, $derive_from_parent, $aggregate, $output_format, $upstream, $downstream, $sub_features = array(), $relationship = '', $rel_part = '') {
 
@@ -388,11 +388,11 @@ function tripal_feature_get_formatted_sequence($feature_id, $feature_name, $num_
     "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
     array(
       '%old_function'=>'tripal_feature_get_formatted_sequence',
-      '%new_function' => 'tripal_format_sequence'
+      '%new_function' => 'tripal_get_sequence'
     )
   );
 
-  return tripal_format_sequence(
+  return tripal_get_sequence(
     // Feature
     array(
       'feature_id' => $feature_id,
@@ -474,9 +474,9 @@ function tripal_feature_add_cvterm($feature_id, $cvname, $cvterm) {
 /**
  * @deprecated Restructured API to make naming more readable and consistent.
  * Function was deprecated in Tripal 2.0 and will be removed 2 releases from now.
- * This function has been replaced by tripal_get_fasta_sequence().
+ * This function has been replaced by tripal_format_fasta_sequence().
  *
- * @see tripal_get_fasta_sequence().
+ * @see tripal_format_fasta_sequence().
  */
 function tripal_feature_return_fasta($feature, $desc) {
 
@@ -486,9 +486,9 @@ function tripal_feature_return_fasta($feature, $desc) {
     "DEPRECATED: %old_function has been replaced with %new_function. Please update your code.",
     array(
       '%old_function'=>'tripal_feature_return_fasta',
-      '%new_function' => 'tripal_get_fasta_sequence'
+      '%new_function' => 'tripal_format_fasta_sequence'
     )
   );
 
-  return tripal_get_fasta_sequence($feature, $desc);
+  return tripal_format_fasta_sequence($feature, $desc);
 }

+ 266 - 220
tripal_feature/api/tripal_feature.api.inc

@@ -51,67 +51,75 @@ function tripal_reverse_compliment_sequence($sequence) {
  *   An associative array describing the feature. Valid keys include:
  *    - feature_id: The feature_id of the feature for which the sequence will be retrieved
  *    - name: The feature name. This will appear on the FASTA definition line
+ *    - parent_id:  (optional) only retrieve a sequence if 'derive_from_parent' is true 
+ *        and the parent matches this ID.
+ *    - featureloc_id: (optional) only retrieve a sequence if 'derive_from_parent' is 
+ *        true and the alignment is defined with this featureloc_id
  * @param $options
  *   An associative array of options. Valid keys include:
  *    - width: Indicate the number of bases to use per line.  A new line will be added
- *      after the specified number of bases on each line.
+ *        after the specified number of bases on each line.
  *    - derive_from_parent: Set to '1' if the sequence should be obtained from the parent
- *      to which this feature is aligned.
+ *        to which this feature is aligned.
  *    - aggregate: Set to '1' if the sequence should only contain sub features, excluding
- *      intro sub feature sequence.  For example, set this option to obtain just
- *      the coding sequence of an mRNA.
+ *        intro sub feature sequence.  For example, set this option to obtain just
+ *        the coding sequence of an mRNA.
  *    - output_format: The type of format.  Valid formats include 'fasta_html', 'fasta_txt' and
- *      'raw'.  The format 'fasta_txt' outputs line breaks as <br> tags and the entire
- *      return value is in a <span> tag with a fixed-width font definition.  'fasta_txt'
- *      outputs line breaks with windows format carriage returns (e.g. \r\n) with no other
- *      formatting. The raw format is simply the sequence with now FASTA formatting and no
- *      line breaks.
+ *        'raw'.  The format 'fasta_txt' outputs line breaks as <br> tags and the entire
+ *        return value is in a <span> tag with a fixed-width font definition.  'fasta_txt'
+ *        outputs line breaks with windows format carriage returns (e.g. \r\n) with no other
+ *        formatting. The raw format is simply the sequence with no FASTA formatting and no
+ *        line breaks.
  *    - num_upstream: An integer specifing the number of upstream bases to include in the output
  *    - num_downstream: An integer specifying the number of downstream bases to include in the
- *      output.
+ *        output.
  *    - sub_feature_types: Only include sub features (or child features) of the types
- *      provided in the array
+ *        provided in the array
  *    - relationship_type: If a relationship name is provided (e.g. sequence_of) then any
- *      sequences that are in relationships of this type with matched sequences are also included
+ *        sequences that are in relationships of this type with matched sequences are also included
  *    - relationship_part: If a relationship is provided in the preceeding argument then
- *      the rel_part must be either 'object' or 'subject' to indicate which side of the
- *      relationship the matched features belong
+ *        the rel_part must be either 'object' or 'subject' to indicate which side of the
+ *        relationship the matched features belong
  *
  * @return
- *   The DNA/protein sequence formated as requested.
+ *   an array of matching sequence formated as requested.
  *
  * @ingroup tripal_feature_api
  */
-function tripal_format_sequence($feature, $options) {
-
-  // Default Values
-  $feature_id = $feature['feature_id'];
-  $feature_name = $feature['name'];
-
-  $num_bases_per_line = $options['width'];
-  $derive_from_parent = $options['derive_from_parent'];
-  $aggregate = $options['aggregate'];
-  $output_format = $options['output_format'];
-  $upstream = $options['num_upstream'];
-  $downstream = $options['num_downstream'];
-  $sub_features = $options['sub_feature_types'];
-  $relationship = $options['relationship_type'];
-  $rel_part = $options['relationship_part'];
-
-  // to speed things up we need to make sure we have a persistent connection
-  $connection = tripal_db_persistent_chado();
-
-  if (!$upstream) {
-     $upstream = 0;
-  }
-  if (!$downstream) {
-     $downstream = 0;
+function tripal_get_sequence($feature, $options) {
+
+  // default values for finding the feature
+  $feature_id    = array_key_exists('feature_id', $feature)     ? $feature['feature_id']     : 0;
+  $parent_id     = array_key_exists('parent_id', $feature)      ? $feature['parent_id']      : 0;
+  $featureloc_id = array_key_exists('featureloc_id', $feature)  ? $feature['featureloc_id']  : 0;
+  $feature_name  = array_key_exists('name', $feature)           ? $feature['name']           : '';
+
+  // default values for building the sequence
+  $num_bases_per_line = array_key_exists('width', $options)              ? $options['width']              : 50;
+  $derive_from_parent = array_key_exists('derive_from_parent', $options) ? $options['derive_from_parent'] : 0;
+  $aggregate          = array_key_exists('aggregate', $options)          ? $options['aggregate']          : 0;
+  $output_format      = array_key_exists('output_format', $options)      ? $options['output_format']      : 'fasta_txt';
+  $upstream           = array_key_exists('num_upstream', $options)       ? $options['num_upstream']       : 0;
+  $downstream         = array_key_exists('num_downstream', $options)     ? $options['num_downstream']     : 0;
+  $sub_features       = array_key_exists('sub_feature_types', $options)  ? $options['sub_feature_types']  : array();
+  $relationship       = array_key_exists('relationship_type', $options)  ? $options['relationship_type']  : '';
+  $rel_part           = array_key_exists('relationship_part', $options)  ? $options['relationship_part']  : '';
+  
+  // make sure the sub_features variable is an array
+  if (!is_array($sub_features)) {
+    tripal_report_error('tripal_deprecated', TRIPAL_ERROR,
+      "'sub_features' option must be an array for function tripal_get_sequence().",
+      array()
+    );
+    return array();
   }
 
+  // if a relationship was specified then retreive and the sequences that
+  // have the given relationship and the recurse to extract the appropriate 
+  // sequence
   if ($rel_part == "object" or $rel_part == "subject") {
     if ($rel_part == "subject") {
-      $psql = '
-        PREPARE feature_rel_get_object (int, text) AS
+      $sql = '
         SELECT FO.feature_id, FO.name, FO.uniquename, CVTO.name as feature_type, O.genus, O.species
         FROM feature FS
           INNER JOIN feature_relationship FR ON FR.subject_id   = FS.feature_id
@@ -120,20 +128,13 @@ function tripal_format_sequence($feature, $options) {
           INNER JOIN cvterm CVTO             ON CVTO.cvterm_id  = FO.type_id
           INNER JOIN organism O              ON O.organism_id   = FO.organism_id
         WHERE
-          FS.feature_id = $1 AND
-          CVTFR.name    = $2
+          FS.feature_id = :feature_id AND
+          CVTFR.name    = :relationship
       ';
-      $status = tripal_core_chado_prepare('feature_rel_get_object', $psql, array('int', 'text'));
-      if (!$status) {
-        tripal_report_error('tripal_feature', TRIPAL_ERROR, "init: not able to prepare SQL statement '%name'",
-          array('%name' => 'feature_by_subject'));
-      }
-      $sql = "EXECUTE feature_rel_get_object(:feature_id, :relationship)";
       $features = chado_query($sql, array(':feature_id' => $feature_id, ':relationship' => $relationship));
     }
     if ($rel_part == "object") {
-      $psql = '
-        PREPARE feature_rel_get_subject (int, text) AS
+      $sql = '
         SELECT FS.feature_id, FS.name, FS.uniquename, CVTO.name as feature_type, O.genus, O.species
         FROM feature FO
           INNER JOIN feature_relationship FR ON FR.object_id    = FO.feature_id
@@ -142,15 +143,9 @@ function tripal_format_sequence($feature, $options) {
           INNER JOIN cvterm CVTO             ON CVTO.cvterm_id  = FS.type_id
           INNER JOIN organism O              ON O.organism_id   = FS.organism_id
         WHERE
-          FO.feature_id = $1 AND
-          CVTFR.name    = $2
+          FO.feature_id = :feature_id AND
+          CVTFR.name    = :relationship
       ';
-      $status = tripal_core_chado_prepare('feature_rel_get_subject', $psql, array('int', 'text'));
-      if (!$status) {
-        tripal_report_error('tripal_feature', TRIPAL_ERROR, "init: not able to prepare SQL statement '%name'",
-          array('%name' => 'feature_by_object'));
-      }
-      $sql = "EXECUTE feature_rel_get_subject(:feature_id, :relationship)";
       $features = chado_query($sql, array(':feature_id' => $feature_id, ':relationship' => $relationship));
     }
     $sequences = '';
@@ -163,137 +158,140 @@ function tripal_format_sequence($feature, $options) {
       if ($rel_part == "object") {
         $defline = "$feature->uniquename $feature->feature_type ($feature->genus $feature->species), $relationship, $feature_name";
       }
-      $sequences .= tripal_feature_get_formatted_sequence($feature->feature_id, $defline,
-        $num_bases_per_line, $derive_from_parent, $aggregate, $output_format,
-        $upstream, $downstream, $sub_features, '', '');
-    }
-    return $sequences;
-  }
-
-  // prepare statements we'll need to use later
-  if (!tripal_core_is_sql_prepared('sequence_by_parent')) {
-    // prepare the queries we're going to use later during the render phase
-    // This SQL statement uses conditionals in the select clause to handle
-    // cases cases where the alignment is in the reverse direction and when
-    // the upstream and downstream extensions go beyond the lenght of the
-    // parent sequence.
-    $psql ='
-      PREPARE sequence_by_parent (int, int, int) AS
-      SELECT srcname, srcfeature_id, strand, srctypename, typename,
-        fmin, fmax, upstream, downstream, adjfmin, adjfmax,
-        substring(residues from (adjfmin + 1) for (upstream + (fmax - fmin) + downstream))  as residues,
-        genus, species
-      FROM (
-        SELECT
-          OF.name srcname, FL.srcfeature_id, FL.strand,
-          OCVT.name as srctypename, SCVT.name as typename,
-          FL.fmin, FL.fmax, OO.genus, OO.species,
-          CASE
-            WHEN FL.strand >= 0 THEN
-              CASE
-                 WHEN FL.fmin - $1 <= 0 THEN 0
-                 ELSE FL.fmin - $1
-              END
-            WHEN FL.strand < 0 THEN
-              CASE
-                 WHEN FL.fmin - $2 <= 0 THEN 0
-                 ELSE FL.fmin - $2
-              END
-          END as adjfmin,
-          CASE
-            WHEN FL.strand >= 0 THEN
-              CASE
-                WHEN FL.fmax + $2 > OF.seqlen THEN OF.seqlen
-                ELSE FL.fmax + $2
-              END
-            WHEN FL.strand < 0 THEN
-              CASE
-                WHEN FL.fmax + $1 > OF.seqlen THEN OF.seqlen
-                ELSE FL.fmax + $1
-              END
-          END as adjfmax,
-          CASE
-            WHEN FL.strand >= 0 THEN
-              CASE
-                 WHEN FL.fmin - $1 <= 0 THEN FL.fmin
-                 ELSE $1
-              END
-            ELSE
-              CASE
-                 WHEN FL.fmax + $1 > OF.seqlen THEN OF.seqlen - FL.fmax
-                 ELSE $1
-              END
-          END as upstream,
-          CASE
-            WHEN FL.strand >= 0 THEN
-              CASE
-                 WHEN FL.fmax + $2 > OF.seqlen THEN OF.seqlen - FL.fmax
-                 ELSE $2
-              END
-            ELSE
-              CASE
-                 WHEN FL.fmin - $2 <= 0 THEN FL.fmin
-                 ELSE $2
-              END
-          END as downstream,
-          OF.residues
-        FROM {featureloc} FL
-          INNER JOIN {feature} SF   on FL.feature_id    = SF.feature_id
-          INNER JOIN {cvterm}  SCVT on SF.type_id       = SCVT.cvterm_id
-          INNER JOIN {feature} OF   on FL.srcfeature_id = OF.feature_id
-          INNER JOIN {cvterm}  OCVT on OF.type_id       = OCVT.cvterm_id
-          INNER JOIN {organism} OO  on OF.organism_id   = OO.organism_id
-        WHERE SF.feature_id = $3 and NOT (OF.residues = \'\' or OF.residues IS NULL)) as tbl1
-    ';
-    $status = tripal_core_chado_prepare('sequence_by_parent', $psql, array('int', 'int', 'int'));
-    if (!$status) {
-      tripal_report_error('tripal_feature', TRIPAL_ERROR,
-        "init: not able to prepare SQL statement '%name'",
-        array('%name' => 'sequence_by_parent'));
-    }
-
-    // this query is meant to get all of the sub features of any given
-    // feature (arg #1) and order them as they appear on the reference
-    // feature (arg #2).
-    $psql ='PREPARE sub_features (int, int) AS
-            SELECT SF.feature_id, CVT.name as type_name, SF.type_id
-            FROM {feature_relationship} FR
-              INNER JOIN {feature} SF on SF.feature_id = FR.subject_id
-              INNER JOIN {cvterm} CVT on CVT.cvterm_id = SF.type_id
-              INNER JOIN {featureloc} FL on FL.feature_id = FR.subject_id
-              INNER JOIN {feature} PF on PF.feature_id = FL.srcfeature_id
-            WHERE FR.object_id = $1 and PF.feature_id = $2
-            ORDER BY FL.fmin ASC';
-    $status = tripal_core_chado_prepare('sub_features', $psql, array('int', 'int'));
-    if (!$status) {
-      tripal_report_error('tripal_feature', TRIPAL_ERROR,
-        "init: not able to prepare SQL statement '%name'",
-        array('%name' => 'ssub_features'));
-    }
-    $psql ='PREPARE count_sub_features (int, int) AS
-            SELECT count(*) as num_children
-            FROM {feature_relationship} FR
-              INNER JOIN {feature} SF on SF.feature_id = FR.subject_id
-              INNER JOIN {cvterm} CVT on CVT.cvterm_id = SF.type_id
-              INNER JOIN {featureloc} FL on FL.feature_id = FR.subject_id
-              INNER JOIN {feature} PF on PF.feature_id = FL.srcfeature_id
-            WHERE FR.object_id = $1 and PF.feature_id = $2';
-    $status = tripal_core_chado_prepare('count_sub_features', $psql, array('int', 'int'));
-    if (!$status) {
-      tripal_report_error('tripal_feature', TRIPAL_ERROR,
-        "init: not able to prepare SQL statement '%name'",
-        array('%name' => 'count_sub_features'));
+      return tripal_get_sequence(
+        array(
+          'feature_id' => $feature->feature_id, 
+          'name' => $defline,
+          'parent_id' => $parent_id,
+        ),
+        array(
+          'width' => $num_bases_per_line, 
+          'derive_from_pareht' => $derive_from_parent, 
+          'aggregate' => $aggregate, 
+          'output_format' => $output_format,
+          'upstream' => $upstream, 
+          'downstream' => $downstream, 
+          'sub_features' => $sub_features, 
+        )
+      );
     }
   }
 
+  // prepare the queries we're going to use later during the render phase
+  // This SQL statement uses conditionals in the select clause to handle
+  // cases cases where the alignment is in the reverse direction and when
+  // the upstream and downstream extensions go beyond the lenght of the
+  // parent sequence.
+  $sql ='
+    SELECT featureloc_id, srcname, srcfeature_id, strand, srctypename, typename,
+      fmin, fmax, upstream, downstream, adjfmin, adjfmax,
+      substring(residues from (adjfmin + 1) for (upstream + (fmax - fmin) + downstream))  as residues,
+      genus, species
+    FROM (
+      SELECT
+        FL.featureloc_id, OF.name srcname, FL.srcfeature_id, FL.strand,
+        OCVT.name as srctypename, SCVT.name as typename,
+        FL.fmin, FL.fmax, OO.genus, OO.species,
+        CASE
+          WHEN FL.strand >= 0 THEN
+            CASE
+               WHEN FL.fmin - :upstream <= 0 THEN 0
+               ELSE FL.fmin - :upstream
+            END
+          WHEN FL.strand < 0 THEN
+            CASE
+               WHEN FL.fmin - :downstream <= 0 THEN 0
+               ELSE FL.fmin - :downstream
+            END
+        END as adjfmin,
+        CASE
+          WHEN FL.strand >= 0 THEN
+            CASE
+              WHEN FL.fmax + :downstream > OF.seqlen THEN OF.seqlen
+              ELSE FL.fmax + :downstream
+            END
+          WHEN FL.strand < 0 THEN
+            CASE
+              WHEN FL.fmax + :upstream > OF.seqlen THEN OF.seqlen
+              ELSE FL.fmax + :upstream
+            END
+        END as adjfmax,
+        CASE
+          WHEN FL.strand >= 0 THEN
+            CASE
+               WHEN FL.fmin - :upstream <= 0 THEN FL.fmin
+               ELSE :upstream
+            END
+          ELSE
+            CASE
+               WHEN FL.fmax + :upstream > OF.seqlen THEN OF.seqlen - FL.fmax
+               ELSE :upstream
+            END
+        END as upstream,
+        CASE
+          WHEN FL.strand >= 0 THEN
+            CASE
+               WHEN FL.fmax + :downstream > OF.seqlen THEN OF.seqlen - FL.fmax
+               ELSE :downstream
+            END
+          ELSE
+            CASE
+               WHEN FL.fmin - :downstream <= 0 THEN FL.fmin
+               ELSE :downstream
+            END
+        END as downstream,
+        OF.residues
+      FROM {featureloc} FL
+        INNER JOIN {feature} SF   on FL.feature_id    = SF.feature_id
+        INNER JOIN {cvterm}  SCVT on SF.type_id       = SCVT.cvterm_id
+        INNER JOIN {feature} OF   on FL.srcfeature_id = OF.feature_id
+        INNER JOIN {cvterm}  OCVT on OF.type_id       = OCVT.cvterm_id
+        INNER JOIN {organism} OO  on OF.organism_id   = OO.organism_id
+      WHERE SF.feature_id = :feature_id and NOT (OF.residues = \'\' or OF.residues IS NULL)) as tbl1
+  ';
+  // this query is meant to get all of the sub features of any given
+  // feature (arg #1) and order them as they appear on the reference
+  // feature (arg #2).
+  $sfsql = '
+    SELECT SF.feature_id, CVT.name as type_name, SF.type_id
+    FROM {feature_relationship} FR
+      INNER JOIN {feature} SF on SF.feature_id = FR.subject_id
+      INNER JOIN {cvterm} CVT on CVT.cvterm_id = SF.type_id
+      INNER JOIN {featureloc} FL on FL.feature_id = FR.subject_id
+      INNER JOIN {feature} PF on PF.feature_id = FL.srcfeature_id
+    WHERE FR.object_id = :feature_id and PF.feature_id = :srcfeature_id
+    ORDER BY FL.fmin ASC
+  ';
+  // for counting the number of children
+  $fsql ='
+    SELECT count(*) as num_children
+    FROM {feature_relationship} FR
+      INNER JOIN {feature} SF on SF.feature_id = FR.subject_id
+      INNER JOIN {cvterm} CVT on CVT.cvterm_id = SF.type_id
+      INNER JOIN {featureloc} FL on FL.feature_id = FR.subject_id
+      INNER JOIN {feature} PF on PF.feature_id = FL.srcfeature_id
+    WHERE FR.object_id = :feature_id and PF.feature_id = :srcfeature_id
+  ';
+
+  // the array to be returned
+  $sequences = array();
+  
   // if we need to get the sequence from the parent then do so now.
   if ($derive_from_parent) {
 
     // execute the query to get the sequence from the parent
-    $sql = "EXECUTE sequence_by_parent (:upstream, :downstream, :feature_id)";
-    $parents = chado_query($sql, array(':uptream' => $upstream, ':downstream' => $downstream, ':feature_id' => $feature_id));
+    $parents = chado_query($sql, array(':upstream' => $upstream, ':downstream' => $downstream, ':feature_id' => $feature_id));
 
     while ($parent = $parents->fetchObject()) {
+      
+      // if the user specified a particular parent and this one doesn't match then skip it
+      if ($parent_id and $parent_id != $parent->srcfeature_id) {
+        continue;
+      }
+      // if the user specified a particular featureloc_id and this one doesn't match then skip it
+      if ($featureloc_id and $featureloc_id != $parent->featureloc_id) {
+        continue;
+      }
       $seq = '';  // initialize the sequence for each parent
 
       // if we are to aggregate then we will ignore the feature returned
@@ -301,11 +299,8 @@ function tripal_format_sequence($feature, $options) {
       if ($aggregate) {
 
         // now get the sub features that are located on the parent.
-        $sql = "EXECUTE sub_features (:feature_id, :srcfeature_id)";
-        $children = chado_query($sql, array(':feature_id' => $feature_id, ':srcfeature_id' => $parent->srcfeature_id));
-        $sql = "EXECUTE count_sub_features (:feature_id, :srcfeature_id)";
-        $sub_features = chado_query($sql, array(':feature_id' => $feature_id, ':srcfeature_id' => $parent->srcfeature_id));
-        $num_children = $sub_features->fetchObject();
+        $children = chado_query($sfsql, array(':feature_id' => $feature_id, ':srcfeature_id' => $parent->srcfeature_id));
+        $num_children = chado_query($fsql, array(':feature_id' => $feature_id, ':srcfeature_id' => $parent->srcfeature_id))->fetchObject();
 
         // iterate through the sub features and concat their sequences. They
         // should already be in order.
@@ -324,8 +319,6 @@ function tripal_format_sequence($feature, $options) {
             $types[] = $child->type_name;
           }
 
-          $sql = "EXECUTE sequence_by_parent (:upstream, %d, :feature_id)";
-
           // if the first sub feature we need to include the upstream bases. first check if
           // the feature is in the foward direction or the reverse.
           if ($i == 0 and $parent->strand >= 0) {  // forward direction
@@ -358,7 +351,6 @@ function tripal_format_sequence($feature, $options) {
 
           // for internal sub features we don't want upstream or downstream bases
           else {
-            $sql = "EXECUTE sequence_by_parent (%d, %d, %d)";
             $q = chado_query($sql, array(':upstream' => 0, ':downstream' => 0, ':feature_id' => $child->feature_id));
           }
 
@@ -378,11 +370,11 @@ function tripal_format_sequence($feature, $options) {
 
       // get the reverse compliment if feature is on the reverse strand
       $dir = 'forward';
+      $notes = '';
       if ($parent->strand < 0) {
         $seq = tripal_feature_reverse_complement($seq);
         $dir = 'reverse';
       }
-
       // now format for display
       if ($output_format == 'fasta_html') {
          $seq = wordwrap($seq, $num_bases_per_line, "<br>", TRUE);
@@ -390,34 +382,35 @@ function tripal_format_sequence($feature, $options) {
       elseif ($output_format == 'fasta_txt') {
          $seq = wordwrap($seq, $num_bases_per_line, "\r\n", TRUE);
       }
-      $residues .= ">$feature_name. Sequence derived from feature of type, '$parent->srctypename', of $parent->genus $parent->species: $parent->srcname:" . ($parent->adjfmin + 1) . ".." . $parent->adjfmax . " ($dir). ";
-      if (count($types) > 0) {
-        $residues .= "Excludes all bases but those of type(s): " . implode(', ', $types) . ". " ;
-      }
-      if ($parent->upstream > 0) {
-         $residues .= "Includes " . $parent->upstream . " bases upstream.  ";
-      }
-      if ($parent->downstream > 0) {
-         $residues .= "Includes " . $parent->downstream . " bases downstream.  ";
-      }
       if (!$seq) {
-
         if ($output_format == 'fasta_html') {
-          $residues .= "No sequence available.</br>";
+          $notes .= "No sequence available.</br>";
         }
         else {
-          $residues .= "No sequence available.\r\n";
+          $notes .= "No sequence available.\r\n";
         }
       }
-      else {
-        if ($output_format == 'fasta_html') {
-          $residues .= "<br>";
-        }
-        $residues .= "\r\n" . $seq . "\r\n";
-        if ($output_format == 'fasta_html') {
-          $residues .= "<br>";
-        }
+      
+      $notes = "Sequence derived from feature of type, '$parent->srctypename', of $parent->genus $parent->species: $parent->srcname:" . ($parent->adjfmin + 1) . ".." . $parent->adjfmax . " ($dir). ";
+      /*
+      if (count($types) > 0) {
+        $notes .= "Excludes all bases but those of type(s): " . implode(', ', $types) . ". " ;
       }
+      if ($parent->upstream > 0) {
+         $notes .= "Includes " . $parent->upstream . " bases upstream.  ";
+      }
+      if ($parent->downstream > 0) {
+         $notes .= "Includes " . $parent->downstream . " bases downstream.  ";
+      }      
+      */
+      $sequences[] = array(
+        'types'         => $types,
+        'upstream'      => $parent->upstream,
+        'downstream'    => $parent->downstream,
+        'notes'         => $notes,
+        'residues'      => $seq,
+        'featureloc_id' => $parent->featureloc_id,
+      );
     }
   }
   // if we are not getting the sequence from the parent sequence then
@@ -432,16 +425,17 @@ function tripal_format_sequence($feature, $options) {
     elseif ($output_format == 'fasta_txt') {
        $residues = wordwrap($residues, $num_bases_per_line, "\r\n", TRUE);
     }
-    $residues = ">$feature_name\r\n$residues\r\n";
-  }
 
-  // format the residues for display
-  if ($residues and $num_bases_per_line) {
-    if ($output_format == 'fasta_html') {
-       $residues = '<span style="font-family: monospace;">' . $residues . '</span>';
-    }
+    $sequences[] = array(
+      'types'      => $values->type,
+      'upstream'   => 0,
+      'downstream' => 0,
+      'notes'      => '',
+      'residues'   => $residues,
+    );
   }
-  return $residues;
+
+  return $sequences;
 }
 
 /**
@@ -458,7 +452,7 @@ function tripal_format_sequence($feature, $options) {
  *
  * @ingroup tripal_feature_api
  */
-function tripal_get_fasta_sequence($feature, $desc) {
+function tripal_format_fasta_sequence($feature, $desc) {
 
   $fasta  = ">" . variable_get('chado_feature_accession_prefix', 'FID') . "$feature->feature_id|$feature->name";
   $fasta .= " $desc\n";
@@ -467,4 +461,56 @@ function tripal_get_fasta_sequence($feature, $desc) {
 
   return $fasta;
 
+}
+
+/**
+ * Returns a definition line that can be used in a FASTA file
+ * 
+ * @param $feature
+ *   A single feature object containing all the fields from the chado.feature table
+ * @param $featureloc
+ *   Optional: A single featureloc object generated using chado_generate_var that
+ *   contains a record from the chado.featureloc table.
+ * @param $type
+ *   Optional: the type of sequence. By default the feature type is used.
+ *   
+ * @return
+ *   A string of the format: uniquename|name|type|feature_id
+ *   or if an alignment:  srcfeature_name:fmin..fmax[+-]; alignment of uniquename|name|type|feature_id 
+ */
+function tripal_get_fasta_defline($feature, $featureloc = NULL, $type = '') {
+  
+  if (!$type) {
+    $type = $feature->type_id->name;
+  }
+  $defline = $feature->uniquename . "|" . $feature->name . "|" . $type . "|" . $feature->feature_id; 
+  if ($featureloc) {
+    $defline = $defline . "; derived from alignment at " .tripal_get_location_string($featureloc);
+  }
+  
+  return $defline;
+}
+
+/**
+ * Returns a string representing a feature location in an alignment
+ *  
+ * @param unknown $featureloc
+ *   A single featureloc object generated using chado_generate_var that
+ *   contains a record from the chado.featureloc table.
+ */
+function tripal_get_location_string($featureloc) {
+  $feature = $featureloc->feature_id;
+  
+  if ($featureloc->strand < 0) {
+    $residues = tripal_feature_reverse_complement($residues);
+  }
+  $strand = '.';
+  if ($featureloc->strand == 1) {
+    $strand = '+';
+  }
+  elseif ($featureloc->strand == -1) {
+    $strand = '-';
+  }
+  
+  return $featureloc->srcfeature_id->name . ":" . ($featureloc->fmin + 1) . ".." . $featureloc->fmax .  $strand;  
 }

+ 4 - 4
tripal_feature/includes/tripal_feature.chado_node.inc

@@ -233,7 +233,7 @@ function chado_feature_form($node, &$form_state) {
   
   // TODO: For some reason adding a relationship to the form breaks AJAX
   // for features (works for other node type)... need to debug
-  /*
+  
   // RELATIONSHIPS FORM
   //---------------------------------------------
   $relationship_cv = tripal_get_default_cv('feature_relationship', 'type_id');
@@ -247,7 +247,7 @@ function chado_feature_form($node, &$form_state) {
     'cv_id' => $cv_id
   );
   chado_add_node_form_relationships($form, $form_state, $details);
-  */
+  
 
   return $form;
 }
@@ -951,8 +951,8 @@ function tripal_feature_node_view($node, $view_mode, $langcode) {
         );
         $node->content['tripal_feature_seqence'] = array(
           '#markup' => theme('tripal_feature_sequence', array('node' => $node)),
-          '#tripal_toc_id'    => 'sequence',
-          '#tripal_toc_title' => 'Sequence',
+          '#tripal_toc_id'    => 'sequences',
+          '#tripal_toc_title' => 'Sequences',
         );
         $node->content['tripal_feature_synonyms'] = array(
           '#markup' => theme('tripal_feature_synonyms', array('node' => $node)),

+ 10 - 7
tripal_feature/theme/css/tripal_feature.css

@@ -1,17 +1,20 @@
-#tripal_feature-featureloc_sequence,
-#tripal_feature-sequence-residues {
+.tripal_feature-sequence {
   background-color: #FFFFFF;
   font-family: monospace;
   margin: 10px 0 0 0;
   padding: 0px;
   font-size: medium;
 }
-
-pre#tripal_feature-featureloc_sequence {
+.tripal_feature-sequence-item {
+  margin-top: 20px;
+}
+pre.tripal_feature-sequence {
   color: #000000;
-  /*
-  height: 400px;
-  overflow: scroll; */
+  height: 300px;
+  overflow: scroll; 
+  border: 1px solid #DDDDDD;
+  max-width: 500px;
+  white-space: normal;
 }
 
 div#tripal_feature-featureloc_sequence-legend {

+ 12 - 8
tripal_feature/theme/js/tripal_feature.js

@@ -1,15 +1,19 @@
-if (Drupal.jsEnabled) {
-  $(document).ready(function() {
-    $('.tripal_feature-legend-item').bind("mouseover", function(){
+(function($) {
+  Drupal.behaviors.tripal_featureBehavior = {
+    attach: function (context, settings){
 
+      // the following function is used when viewing sequence alignments
+      // on the feature page. When mousing over the feature type legend
+      // it should highlight regions in the sequence
+      $('.tripal_feature-legend-item').bind("mouseover", function(){
         var classes = $(this).attr('class').split(" ");
         var type_class = classes[1];       
-  
-        $("." + type_class).css("border", "1px solid red");
 
+        $("." + type_class).css("border", "1px solid red");
         $(this).bind("mouseout", function(){
           $("." + type_class).css("border", "0px");
         })    
-    });
-  });
-}
+      });
+    }
+  };
+})(jQuery);

+ 2 - 2
tripal_feature/theme/templates/tripal_feature_alignments.tpl.php

@@ -1,10 +1,10 @@
 <?php
 /*
 * Typically in a Tripal template, the data needed is retrieved using a call to
-* tripal_core_expand_chado_vars function.  For example, to retrieve all 
+* chado_expand_var function.  For example, to retrieve all 
 * of the feature alignments for this node, the following function call would be made:
 * 
-*   $feature = tripal_core_expand_chado_vars($feature,'table','featureloc');
+*   $feature = chado_expand_var($feature,'table','featureloc');
 *   
 * However, this will return all records from the featureloc table without any context.
 * To help provide context, a special variable is provided to this template named

+ 1 - 1
tripal_feature/theme/templates/tripal_feature_analyses.tpl.php

@@ -1,7 +1,7 @@
 <?php
 $feature = $variables['node']->feature;
 $options = array('return_array' => 1);
-$feature = tripal_core_expand_chado_vars($feature, 'table', 'analysisfeature', $options);
+$feature = chado_expand_var($feature, 'table', 'analysisfeature', $options);
 $analyses = $feature->analysisfeature;
 
 // don't show this page if there are no analyses

+ 3 - 3
tripal_feature/theme/templates/tripal_feature_properties.tpl.php

@@ -2,11 +2,11 @@
 
 $feature = $variables['node']->feature;
 $options = array('return_array' => 1);
-$feature = tripal_core_expand_chado_vars($feature, 'table', 'featureprop', $options);
+$feature = chado_expand_var($feature, 'table', 'featureprop', $options);
 $properties = $feature->featureprop;
 
 if(count($properties) > 0){ 
-    
+  
   // 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
@@ -19,7 +19,7 @@ if(count($properties) > 0){
   $rows = array();
   
   foreach ($properties as $property){
-    $property = tripal_core_expand_chado_vars($property,'field','featureprop.value');
+    $property = chado_expand_var($property,'field','featureprop.value');
     $rows[] = array(
       array(
         'data' => ucfirst(preg_replace('/_/', ' ', $property->type_id->name)),

+ 4 - 4
tripal_feature/theme/templates/tripal_feature_publications.tpl.php

@@ -3,7 +3,7 @@ $feature = $variables['node']->feature;
 
 // expand feature to include pubs 
 $options = array('return_array' => 1);
-$feature = tripal_core_expand_chado_vars($feature, 'table', 'feature_pub', $options);
+$feature = chado_expand_var($feature, 'table', 'feature_pub', $options);
 $feature_pubs = $feature->feature_pub; 
 
 
@@ -23,7 +23,7 @@ if (count($feature_pubs) > 0) { ?>
   
   foreach ($feature_pubs as $feature_pub) {
     $pub = $feature_pub->pub_id;
-    $pub = tripal_core_expand_chado_vars($pub, 'field', 'pub.title');
+    $pub = chado_expand_var($pub, 'field', 'pub.title');
     $citation = $pub->title;  // use the title as the default citation
     
     // get the citation for this pub if it exists
@@ -34,9 +34,9 @@ if (count($feature_pubs) > 0) { ?>
       ),
     );
     $options = array('return_array' => 1);
-    $citation_prop = tripal_core_generate_chado_var('pubprop', $values, $options); 
+    $citation_prop = chado_generate_var('pubprop', $values, $options); 
     if (count($citation_prop) == 1) {
-      $citation_prop = tripal_core_expand_chado_vars($citation_prop, 'field', 'pubprop.value');
+      $citation_prop = chado_expand_var($citation_prop, 'field', 'pubprop.value');
       $citation = $citation_prop[0]->value;
     }
     

+ 1 - 1
tripal_feature/theme/templates/tripal_feature_references.tpl.php

@@ -10,7 +10,7 @@ if ($feature->dbxref_id) {
 
 // Second, expand the feature object to include the records from the feature_dbxref table
 $options = array('return_array' => 1);
-$feature = tripal_core_expand_chado_vars($feature, 'table', 'feature_dbxref', $options);
+$feature = chado_expand_var($feature, 'table', 'feature_dbxref', $options);
 $feature_dbxrefs = $feature->feature_dbxref;
 if (count($feature_dbxrefs) > 0 ) {
   foreach ($feature_dbxrefs as $feature_dbxref) {    

+ 3 - 3
tripal_feature/theme/templates/tripal_feature_relationships.tpl.php

@@ -1,12 +1,12 @@
 <?php
 /* Typically in a Tripal template, the data needed is retrieved using a call to
- * tripal_core_expand_chado_vars function.  For example, to retrieve all 
+ * chado_expand_var function.  For example, to retrieve all 
  * of the feature relationships for this node, the following function call would be made:
  * 
- *   $feature = tripal_core_expand_chado_vars($feature,'table','feature_relationship');
+ *   $feature = chado_expand_var($feature,'table','feature_relationship');
  * 
  * However, this function call can be extremely slow when there are numerous relationships.
- * This is because the tripal_core_expand_chado_vars function is recursive and expands 
+ * This is because the chado_expand_var function is recursive and expands 
  * all data following the foreign key relationships tree.  Therefore, to speed retrieval
  * of data, a special variable is provided to this template:
  * 

+ 191 - 31
tripal_feature/theme/templates/tripal_feature_sequence.tpl.php

@@ -1,25 +1,15 @@
 <?php
 /*
- * There are two ways that sequences can be displayed.  They can come from the 
- * feature.residues column or they can come from an alignment with another feature.  
- * This template will show both or one or the other depending on the data available.
- * 
- * For retreiving the sequence from an alignment we would typically make a call to
- * tripal_core_expand_chado_vars function.  For example, to retrieve all
- * of the featurelocs in order to get the sequences needed for this template, the
- * following function call would be made:
- *
- *   $feature = tripal_core_expand_chado_vars($feature,'table','featureloc');
- *
- * Then all of the sequences would need to be retreived from the alignments and
- * formatted for display below.  However, to simplify this template, this has already
- * been done by the tripal_feature module and the sequences are made available in
- * the variable:
- *
- *   $feature->featureloc_sequences
+ * There are several ways that sequences can be displayed.  They can come from the 
+ * feature.residues column,  they can come from an alignment with another feature,
+ * they can come from a protein sequence that has relationship with this sequence,
+ * or they can come from sub children (e.g. CDS coding sequences).
+ *   
+ * This template will show all types depending on the data available.
  *
  */
 
+
 $feature = $variables['node']->feature;
 
 // we don't want to get the sequence for traditionally large types. They are
@@ -30,7 +20,7 @@ if(strcmp($feature->type_id->name,'scaffold') !=0 and
    strcmp($feature->type_id->name,'chromosome') !=0 and
    strcmp($feature->type_id->name,'supercontig') !=0 and
    strcmp($feature->type_id->name,'pseudomolecule') !=0) {
-  $feature = tripal_core_expand_chado_vars($feature,'field','feature.residues');
+  $feature = chado_expand_var($feature,'field','feature.residues');
   $residues = $feature->residues;
 } 
 
@@ -38,21 +28,191 @@ if(strcmp($feature->type_id->name,'scaffold') !=0 and
 $feature = $variables['node']->feature;
 $featureloc_sequences = $feature->featureloc_sequences;
 
-if ($residues or count($featureloc_sequences) > 0) { ?>
-  <div class="tripal_feature-data-block-desc tripal-data-block-desc"></div> <?php
+if ($residues or count($featureloc_sequences) > 0) { 
+
+  $sequences_html = '';  // a variable for holding all sequences HTML text
+  $list_items = array(); // a list to be used for theming of content on this page
   
-  // show the alignment sequences first as they are colored with child features
-  if(count($featureloc_sequences) > 0){
-    foreach($featureloc_sequences as $src => $attrs){ 
-      print $attrs['formatted_seq'];
-    } 
+  // ADD IN RESIDUES FOR THIS FEATURE
+  // add in the residues if they are present
+  if ($residues) {
+    $list_items[] = '<a href="#residues">' . $feature->type_id->name . ' sequence</a>';
+     
+    // format the sequence to break every 50 residues
+    $sequences_html .= '<a name="residues"></a>';
+    $sequences_html .= '<div id="residues" class="tripal_feature-sequence-item">';
+    $sequences_html .= '<p><b>' . $feature->type_id->name . ' sequence</b></p>';
+    $sequences_html .= '<pre class="tripal_feature-sequence">';
+    $sequences_html .= '>' . tripal_get_fasta_defline($feature) . "\n";
+    $sequences_html .= preg_replace("/(.{50})/","\\1<br>",$feature->residues);
+    $sequences_html .= '</pre>';
+    $sequences_html .= '<a href="#sequences-top">back to top</a>';
+    $sequences_html .= '</div>';
+    
   }
   
-  // add in the residues if they are present
-  if ($residues) { ?>
-    <pre id="tripal_feature-sequence-residues"><?php 
-      // format the sequence to break every 100 residues
-      print preg_replace("/(.{50})/","\\1<br>",$feature->residues); ?>  
-    </pre> <?php 
+  // ADD IN RELATIONSHIP SEQUENCES (e.g. proteins)
+  // see the explanation in the tripal_feature_relationships.tpl.php 
+  // template for how the 'all_relationships' is provided. It is this
+  // variable that we use to get the proteins.
+  $all_relationships = $feature->all_relationships;
+  $object_rels = $all_relationships['object'];
+  $has_coding_seq = 0;
+  $coding_seq = '';
+  foreach ($object_rels as $rel_type => $rels){
+    foreach ($rels as $subject_type => $subjects){
+      foreach ($subjects as $subject){
+        
+        // add in protein sequence if it has residues
+        if ($rel_type == 'derives from' and $subject_type == 'polypeptide') {
+          $protein = $subject->record->subject_id;
+          $protein = chado_expand_var($protein, 'field', 'feature.residues');
+          
+          if ($protein->residues) {
+            $list_items[] = '<a href="#residues">protein sequence</a>';
+            $sequences_html .= '<a name="protein-' . $protein->feature_id . '"></a>';
+            $sequences_html .= '<div id="protein-' . $protein->feature_id . '" class="tripal_feature-sequence-item">';
+            $sequences_html .= '<p><b>protein sequence of ' . $protein->name . '</b></p>';
+            $sequences_html .= '<pre class="tripal_feature-sequence">';
+            $sequences_html .= '>' . tripal_get_fasta_defline($protein) . "\n";
+            $sequences_html .= preg_replace("/(.{50})/","\\1<br>", $protein->residues);
+            $sequences_html .= '</pre>';
+            $sequences_html .= '<a href="#sequences-top">back to top</a>';
+            $sequences_html .= '</div>';
+          }
+        }
+        
+        // If the CDS has sequences then concatenate those. The objects 
+        // should be returned in order of rank
+        if ($rel_type == 'part of' and $subject_type == 'CDS') {
+          $cds = $subject->record->subject_id;
+          $cds = chado_expand_var($cds, 'field', 'feature.residues');
+          if ($cds->residues) {
+            $has_coding_seq = 1;
+            $coding_seq .= $cds->residues;
+          }
+        }
+        
+        // add any other sequences that are related through a relationship
+        // and that have values in the 'residues' column
+      }
+    }
+  }
+  
+  // CODING SEQUENCES FROM RELATIONSHIPS
+  // add in any CDS sequences.
+  if ($has_coding_seq) {
+    $list_items[] = '<a href="#coding_sequence">coding sequence </a>';
+    $sequences_html .= '<a name="coding_sequence"></a>';
+    $sequences_html .= '<div id="coding_sequence" class="tripal_feature-sequence-item">';
+    $sequences_html .= '<p><b>coding sequence</b></p>';
+    $sequences_html .= '<pre class="tripal_feature-sequence">';
+    $sequences_html .= $coding_seq;
+    $sequences_html .= '</pre>';
+    $sequences_html .= '<a href="#sequences-top">back to top</a>';
+    $sequences_html .= '</div>';
+  }
+  
+  /* ADD IN ALIGNMENT SEQUENCES FOR THIS FEATURE
+   * For retreiving the sequence from an alignment we would typically make a call to
+   * chado_expand_var function.  For example, to retrieve all
+   * of the featurelocs in order to get the sequences needed for this template, the
+   * following function call would be made:
+   *
+   *   $feature = chado_expand_var($feature,'table','featureloc');
+   *
+   * Then all of the sequences would need to be retreived from the alignments and
+   * formatted for display below.  However, to simplify this template, this has already
+   * been done by the tripal_feature module and the sequences are made available in
+   * the variable: 
+   *
+   *   $feature->featureloc_sequences
+   */
+  if(count($featureloc_sequences) > 0){
+    foreach($featureloc_sequences as $src => $attrs){
+      // the $attrs array has the following keys
+      //   * id:  a unique identifier combining the feature id with the cvterm id
+      //   * type: the type of sequence (e.g. mRNA, etc)
+      //   * location:  the alignment location
+      //   * defline: the definition line
+      //   * formatted_seq: the formatted sequences
+      //   * featureloc:  the feature object aligned to
+      $list_items[] = '<a href="#' . $attrs['id'] . '">'. $feature->type_id->name . ' from alignment at  ' . $attrs['location'] . "</a>";
+      $sequences_html .= '<a name="' . $attrs['id'] . '"></a>';
+      $sequences_html .= '<div id="' . $attrs['id'] . '" class="tripal_feature-sequence-item">';
+      $sequences_html .= '<p><b>'. $feature->type_id->name . ' from alignment at  ' . $attrs['location'] .'</b></p>';
+      $sequences_html .= $attrs['formatted_seq'];
+      $sequences_html .= '<a href="#sequences-top">back to top</a>';
+      $sequences_html .= '</div>';
+    }
+    
+    // check to see if this alignment has any CDS. If so, generate a CDS sequence
+    $cds_sequence = tripal_get_sequence(
+        array(
+          'feature_id' => $feature->feature_id,
+          'parent_id' => $attrs['featureloc']->srcfeature_id->feature_id,
+          'name' => $feature->name,
+          'featureloc_id' => $attrs['featureloc']->featureloc_id,
+        ),
+        array(
+          'width' => 50,  // FASTA sequence should have 50 chars per line
+          'derive_from_parent' => 1, // CDS are in parent-child relationships so we want to use the sequence from the parent
+          'aggregate' => 1, // we want to combine all CDS for this feature into a single sequence
+          'output_format' => 'fasta_txt', // we just want plain text, we'll format it here.
+          'sub_feature_types' => array('CDS'), // we're looking for CDS features
+          ''
+        )
+    );
+    if (count($cds_sequence) > 0) {
+      if ($cds_sequence[0]['residues']) {
+        $list_items[] = '<a href="#coding_' . $attrs['id'] . '">coding sequnece from alignment at  ' . $attrs['location'] . "</a>";
+        $sequences_html .= '<a name="ccoding_' . $attrs['id'] . '"></a>';
+        $sequences_html .= '<div id="coding_' . $attrs['id'] . '" class="tripal_feature-sequence-item">';
+        $sequences_html .= '<p><b>Coding sequence (CDS) from alignment at  ' . $attrs['location'] . '</b></p>';
+        $sequences_html .= '<pre class="tripal_feature-sequence">';
+        $sequences_html .= '>' . tripal_get_fasta_defline($feature, $attrs['featureloc'], 'CDS') . "\n";
+        $sequences_html .= $cds_sequence[0]['residues'];
+        $sequences_html .= '</pre>';
+        $sequences_html .= '<a href="#sequences-top">back to top</a>';
+        $sequences_html .= '</div>';
+      }
+    }
   } 
+  ?>
+
+  <div class="tripal_feature-data-block-desc tripal-data-block-desc">The following sequences are available for this feature:</div> 
+  <?php
+  
+  // first add a list at the top of the page that can be formatted as the
+  // user desires.  We use the theme_item_list function of Drupal to create 
+  // the list rather than hard-code the HTML here.  Instructions for how
+  // to create the list can be found here:
+  // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_item_list/7
+  print '<a name="sequences-top"></a>';
+  print theme_item_list(array(
+    'items' => $list_items,
+    'title' => '',
+    'type' => 'ul',
+    'attributes' => array(),
+  ));
+
+  $message = 'Administrators, sequences will appear on this page if:
+    <ul>
+      <li>This feature has residues stored in the "residues" field of the feature table of Chado.</li>
+      <li>This feature has a protein feature associated via the "feature_relationship" table of Chado with a
+          relationship of type "derives from" and the protein feature has residues.</li>
+      <li>This feature has one or more CDS features associated via the "feature_relationship" table of Chado with a
+          relationship of type "part of". If the CDS features have residues then those will be concatenated
+          and presented as a sequence.</li>
+      <li>This feature is aligned to another feature (e.g. scaffold, or chromosome). In this case, the
+          sequence underlying the alignment will be shown.</li>
+      <li>This feature is aligned to another feature (e.g. scaffold, or chromosome) and this feature has
+          one or more CDS features associated.  The CDS sequenes underlying the alignment will be
+          shown.</li>
+    </ul>
+    </p>';
+  print tripal_set_message($message, TRIPAL_INFO, array('return_html' => 1));
+  
+  // now print the sequences
+  print $sequences_html;
 }

+ 1 - 1
tripal_feature/theme/templates/tripal_feature_synonyms.tpl.php

@@ -4,7 +4,7 @@ $feature = $variables['node']->feature;
 // expand the feature object to include the synonyms from the feature_synonym 
 // table in chado.
 $options = array('return_array' => 1);
-$feature = tripal_core_expand_chado_vars($feature, 'table', 'feature_synonym', $options);
+$feature = chado_expand_var($feature, 'table', 'feature_synonym', $options);
 $synonyms = $feature->feature_synonym;
 
 if(count($synonyms) > 0){ ?>

+ 1 - 1
tripal_feature/theme/templates/tripal_feature_terms.tpl.php

@@ -3,7 +3,7 @@
 $feature = $variables['node']->feature;
 
 $options = array('return_array' => 1);
-$feature = tripal_core_expand_chado_vars($feature, 'table', 'feature_cvterm', $options);
+$feature = chado_expand_var($feature, 'table', 'feature_cvterm', $options);
 $terms = $feature->feature_cvterm;
 
 // order the terms by CV

+ 1 - 1
tripal_feature/theme/templates/tripal_organism_feature_browser.tpl.php

@@ -43,7 +43,7 @@ foreach ($results as $result) {
       'type_id' => 1
     )
   );
-  $features[] = tripal_core_generate_chado_var('feature', $values, $options);
+  $features[] = chado_generate_var('feature', $values, $options);
 }
 
 if (count($features) > 0) { ?>

+ 584 - 1
tripal_feature/theme/tripal_feature.theme.inc

@@ -27,6 +27,436 @@ function tripal_feature_preprocess_tripal_feature_sequence(&$variables) {
   // now extract the sequences
   $featureloc_sequences = tripal_feature_load_featureloc_sequences($feature->feature_id, $ffeaturelocs);
   $feature->featureloc_sequences = $featureloc_sequences;
+  
+  // if this feature has associated protein sequences (or others via relationships
+  // then we want to make sure the relationships are added so that we can 
+  // show the protein sequences
+  if (!$feature->all_relationships) {
+    $feature->all_relationships = tripal_feature_get_feature_relationships($feature);
+  }
+}
+
+/**
+ * Get the sequence this feature is located on
+ *
+ * @param $feature_id
+ * @param $featurelocs
+ *
+ * @ingroup tripal_feature
+ */
+function tripal_feature_load_featureloc_sequences($feature_id, $featurelocs) {
+
+  // if we don't have any featurelocs then no point in continuing
+  if (!$featurelocs) {
+    return array();
+  }
+
+  // get the list of relationships (including any aggregators) and iterate
+  // through each one to find information needed to color-code the reference sequence
+  $relationships = tripal_feature_get_aggregate_relationships($feature_id);
+  if (!$relationships) {
+    return array();
+  }
+
+
+  // iterate through each of the realtionships features and get their
+  // locations
+  foreach ($relationships as $rindex => $rel) {
+    // get the featurelocs for each of the relationship features
+    $rel_featurelocs = tripal_feature_load_featurelocs($rel->subject_id, 'as_child', 0);
+    foreach ($rel_featurelocs as $rfindex => $rel_featureloc) {
+      // keep track of this unique source feature
+      $src = $rel_featureloc->src_feature_id . "-" . $rel_featureloc->src_cvterm_id;
+
+      // copy over the results to the relationship object.  Since there can
+      // be more than one feature location for each relationship feature we
+      // use the '$src' variable to keep track of these.
+      $rel->featurelocs = new stdClass();
+      $rel->featurelocs->$src = new stdClass();
+      $rel->featurelocs->$src->src_uniquename = $rel_featureloc->src_uniquename;
+      $rel->featurelocs->$src->src_cvterm_id  = $rel_featureloc->src_cvterm_id;
+      $rel->featurelocs->$src->src_cvname     = $rel_featureloc->src_cvname;
+      $rel->featurelocs->$src->fmin           = $rel_featureloc->fmin;
+      $rel->featurelocs->$src->fmax           = $rel_featureloc->fmax;
+      $rel->featurelocs->$src->src_name       = $rel_featureloc->src_name;
+
+      // keep track of the individual parts for each relationship
+      $start = $rel->featurelocs->$src->fmin;
+      $end   = $rel->featurelocs->$src->fmax;
+      $type  = $rel->subject_type;
+      $rel_locs[$src]['parts'][$start][$type]['start'] = $start;
+      $rel_locs[$src]['parts'][$start][$type]['end']   = $end;
+      $rel_locs[$src]['parts'][$start][$type]['type']  = $type;
+    }
+  }
+
+  // the featurelocs array provided to the function contains the locations
+  // where this feature is found.   We want to get the sequence for each
+  // location and then annotate it with the parts found from the relationships
+  // locations determiend above.
+  $floc_sequences = array();
+  foreach ($featurelocs as $featureloc) {
+
+    // build the src name so we can keep track of the different parts for each feature
+    $src = $featureloc->srcfeature_id->feature_id . "-" . $featureloc->srcfeature_id->type_id->cvterm_id;
+
+    // orient the parts to the beginning of the feature sequence
+    if (!empty($rel_locs[$src]['parts'])) {
+      $parts = $rel_locs[$src]['parts'];
+      $rparts = array();  // we will fill this up if we're on the reverse strand
+
+      foreach ($parts as $start => $types) {
+        foreach ($types as $type_name => $type) {
+          if ($featureloc->strand >= 0) {
+            // this is on the forward strand.  We need to convert the start on the src feature to the
+            // start on this feature's sequence
+            $parts[$start][$type_name]['start'] = $parts[$start][$type_name]['start'] - $featureloc->fmin;
+            $parts[$start][$type_name]['end']   = $parts[$start][$type_name]['end'] - $featureloc->fmin;
+            $parts[$start][$type_name]['type']  = $type_name;
+          }
+          else {
+            // this is on the reverse strand.  We need to swap the start and stop and calculate from the
+            // begining of the reverse sequence
+            $size = ($featureloc->fmax - $featureloc->fmin);
+            $start_orig = $parts[$start][$type_name]['start'];
+            $end_orig = $parts[$start][$type_name]['end'];
+            $new_start = $size - ($end_orig - $featureloc->fmin);
+            $new_end = $size - ($start_orig - $featureloc->fmin);
+
+            $rparts[$new_start][$type_name]['start'] = $new_start;
+            $rparts[$new_start][$type_name]['end']   = $new_end;
+            $rparts[$new_start][$type_name]['type']  = $type_name;
+          }
+        }
+      }
+
+      // now sort the parts
+      // if we're on the reverse strand we need to resort
+      if ($featureloc->strand >= 0) {
+        usort($parts, 'tripal_feature_sort_rel_parts_by_start');
+      }
+      else {
+        usort($rparts, 'tripal_feature_sort_rel_parts_by_start');
+        $parts = $rparts;
+      }
+
+      $floc_sequences[$src]['id'] = $src;
+      $floc_sequences[$src]['type'] = $featureloc->feature_id->type_id->name;
+      $args = array(':feature_id' => $featureloc->srcfeature_id->feature_id);
+      $start = $featureloc->fmin + 1;
+      $size = $featureloc->fmax - $featureloc->fmin;
+      
+      // TODO: fix the hard coded $start and $size
+      // the $start and $size variables are hard-coded in the SQL statement
+      // because the db_query function places quotes around all placeholders
+      // (e.g. :start & :size) and screws up the substring function
+      $sql = "
+        SELECT substring(residues from $start for $size) as residues
+        FROM {feature}
+        WHERE feature_id = :feature_id
+      ";
+      $sequence = chado_query($sql, $args)->fetchObject();
+      $residues = $sequence->residues;
+      if ($featureloc->strand < 0) {
+        $residues = tripal_feature_reverse_complement($residues);
+      }
+      $strand = '.';
+      if ($featureloc->strand == 1) {
+        $strand = '+';
+      }
+      elseif ($featureloc->strand == -1) {
+        $strand = '-';
+      }
+      $floc_sequences[$src]['location'] = tripal_get_location_string($featureloc);
+      $floc_sequences[$src]['defline'] = tripal_get_fasta_defline($featureloc->feature_id, $featureloc);
+      $floc_sequences[$src]['featureloc'] = $featureloc;
+      $floc_sequences[$src]['formatted_seq'] =  tripal_feature_color_sequence($residues, $parts, $floc_sequences[$src]['defline']);
+    }
+  }
+  return $floc_sequences;
+}
+/**
+ * Used to sort the list of relationship parts by start position
+ *
+ * @ingroup tripal_feature
+ */
+function tripal_feature_sort_rel_parts_by_start($a, $b) {
+  foreach ($a as $type_name => $details) {
+    $astart = $a[$type_name]['start'];
+    break;
+  }
+  foreach ($b as $type_name => $details) {
+    $bstart = $b[$type_name]['start'];
+    break;
+  }
+  return strnatcmp($astart, $bstart);
+}
+/**
+ * Load the locations for a given feature
+ *
+ * @param $feature_id
+ *   The feature to look up locations for
+ * @param $side
+ *   Whether the feature is the scrfeature, 'as_parent', or feature, 'as_child'
+ * @param $aggregate
+ *   Whether or not to get the locations for related features
+ *
+ * @ingroup tripal_feature
+ */
+function tripal_feature_load_featurelocs($feature_id, $side = 'as_parent', $aggregate = 1) {
+
+  $sql = "
+    SELECT
+       F.name, F.feature_id, F.uniquename,
+       FS.name as src_name, FS.feature_id as src_feature_id, FS.uniquename as src_uniquename,
+       CVT.name as cvname, CVT.cvterm_id,
+       CVTS.name as src_cvname, CVTS.cvterm_id as src_cvterm_id,
+       FL.fmin, FL.fmax, FL.is_fmin_partial, FL.is_fmax_partial,FL.strand, FL.phase
+     FROM {featureloc} FL
+       INNER JOIN {feature} F   ON FL.feature_id = F.feature_id
+       INNER JOIN {feature} FS  ON FS.feature_id = FL.srcfeature_id
+       INNER JOIN {cvterm} CVT  ON F.type_id     = CVT.cvterm_id
+       INNER JOIN {cvterm} CVTS ON FS.type_id    = CVTS.cvterm_id
+   ";
+  if (strcmp($side, 'as_parent')==0) {
+    $sql .= "WHERE FL.srcfeature_id = :feature_id ";
+  }
+  if (strcmp($side, 'as_child')==0) {
+    $sql .= "WHERE FL.feature_id = :feature_id ";
+  }
+
+  $flresults = chado_query($sql, array(':feature_id' => $feature_id));
+
+  // copy the results into an array
+  $i=0;
+  $featurelocs = array();
+  while ($loc = $flresults->fetchObject()) {
+    // if a drupal node exists for this feature then add the nid to the
+    // results object
+    $loc->fnid = chado_get_nid_from_id('feature', $loc->feature_id);
+    $loc->snid = chado_get_nid_from_id('feature', $loc->src_feature_id);
+    // add the result to the array
+    $featurelocs[$i++] = $loc;
+  }
+
+  // Add the relationship feature locs if aggregate is turned on
+  if ($aggregate and strcmp($side, 'as_parent')==0) {
+    // get the relationships for this feature without substituting any children
+    // for the parent. We want all relationships
+    $relationships = tripal_feature_get_aggregate_relationships($feature_id, 0);
+    foreach ($relationships as $rindex => $rel) {
+      // get the featurelocs for each of the relationship features
+      $rel_featurelocs = tripal_feature_load_featurelocs($rel->subject_id, 'as_child', 0);
+      foreach ($rel_featurelocs as $findex => $rfloc) {
+        $featurelocs[$i++] = $rfloc;
+      }
+    }
+  }
+
+  usort($featurelocs, 'tripal_feature_sort_locations');
+  return $featurelocs;
+}
+
+/**
+ * Used to sort the feature locs by start position
+ *
+ * @param $a
+ *   One featureloc record (as an object)
+ * @param $b
+ *   The other featureloc record (as an object)
+ *
+ * @return
+ *   Which feature location comes first
+ *
+ * @ingroup tripal_feature
+ */
+function tripal_feature_sort_locations($a, $b) {
+  return strnatcmp($a->fmin, $b->fmin);
+}
+
+
+/**
+ * Get features related to the current feature to a given depth. Recursive function.
+ *
+ * @param $feature_id
+ * @param $substitute
+ * @param $levels
+ * @param $base_type_id
+ * @param $depth
+ *
+ * @ingroup tripal_feature
+ */
+function tripal_feature_get_aggregate_relationships($feature_id, $substitute=1,
+    $levels=0, $base_type_id=NULL, $depth=0) {
+
+  // we only want to recurse to as many levels deep as indicated by the
+  // $levels variable, but only if this variable is > 0. If 0 then we
+  // recurse until we reach the end of the relationships tree.
+  if ($levels > 0 and $levels == $depth) {
+    return NULL;
+  }
+
+  // first get the relationships for this feature
+  return tripal_feature_load_relationships($feature_id, 'as_object');
+
+}
+/**
+ * Get the relationships for a feature.
+ *
+ * @param $feature_id
+ *   The feature to get relationships for
+ * @param $side
+ *   The side of the relationship this feature is (ie: 'as_subject' or 'as_object')
+ *
+ * @ingroup tripal_feature
+ */
+function tripal_feature_load_relationships($feature_id, $side = 'as_subject') {
+  // get the relationships for this feature.  The query below is used for both
+  // querying the object and subject relationships
+  $sql = "
+    SELECT
+      FS.name as subject_name, FS.uniquename as subject_uniquename,
+      CVTS.name as subject_type, CVTS.cvterm_id as subject_type_id,
+      FR.subject_id, FR.type_id as relationship_type_id, FR.object_id, FR.rank,
+      CVT.name as rel_type,
+      FO.name as object_name, FO.uniquename as object_uniquename,
+      CVTO.name as object_type, CVTO.cvterm_id as object_type_id
+    FROM {feature_relationship} FR
+     INNER JOIN {cvterm} CVT  ON FR.type_id    = CVT.cvterm_id
+     INNER JOIN {feature} FS  ON FS.feature_id = FR.subject_id
+     INNER JOIN {feature} FO  ON FO.feature_id = FR.object_id
+     INNER JOIN {cvterm} CVTO ON FO.type_id    = CVTO.cvterm_id
+     INNER JOIN {cvterm} CVTS ON FS.type_id    = CVTS.cvterm_id
+  ";
+  if (strcmp($side, 'as_object')==0) {
+    $sql .= " WHERE FR.object_id = :feature_id";
+  }
+  if (strcmp($side, 'as_subject')==0) {
+    $sql .= " WHERE FR.subject_id = :feature_id";
+  }
+  $sql .= " ORDER BY FR.rank";
+
+  // get the relationships
+  $results = chado_query($sql, array(':feature_id' => $feature_id));
+
+
+  // iterate through the relationships, put these in an array and add
+  // in the Drupal node id if one exists
+  $i=0;
+  $nodesql = "SELECT nid FROM {chado_feature} WHERE feature_id = :feature_id";
+  $relationships = array();
+  while ($rel = $results->fetchObject()) {
+    $node = db_query($nodesql, array(':feature_id' => $rel->subject_id))->fetchObject();
+    if ($node) {
+      $rel->subject_nid = $node->nid;
+    }
+    $node = db_query($nodesql, array(':feature_id' => $rel->object_id))->fetchObject();
+    if ($node) {
+      $rel->object_nid = $node->nid;
+    }
+    $relationships[$i++] = $rel;
+  }
+  return $relationships;
+}
+
+/**
+ * Returns the marked up fasta sequence for the described feature
+ *
+ * @param $sequence
+ * @param $parts
+ * @param $defline
+ *
+ * @ingroup tripal_feature
+ */
+function tripal_feature_color_sequence($sequence, $parts, $defline) {
+
+
+  $types = array();
+  // first get the list of types so we can create a color legend
+  foreach ($parts as $index => $t) {
+    foreach ($t as $type_name => $details) {
+      $types[$type_name] = 1;
+    }
+  }
+
+  $newseq = "<div id=\"tripal_feature-featureloc_sequence-legend\">Legend: ";
+  foreach ($types as $type_name => $present) {
+    $newseq .= "<span id=\"tripal_feature-legend-$type_name\" class=\"tripal_feature-legend-item tripal_feature-featureloc_sequence-$type_name\" script=\"\">$type_name</span>";
+  }
+  $newseq .= "</div>Hold the cursor over a type above to highlight its positions in the sequence below.";
+
+
+  // set the background color of the rows based on the type
+  $pos = 0;
+  $newseq .= "<pre class=\"tripal_feature-sequence\">";
+  $newseq .= ">$defline\n";
+
+  // iterate through the parts. They should be in order.
+  $starts   = array(); // an array holding all of the children starting locations
+  $ends     = array(); // an array holding all of the children's ending locations
+  $seqcount = 0;
+  foreach ($parts as $index => $types) {
+
+    // get the start for this part.  All types in this part start at the
+    // same position so we only need the first record
+    foreach ($types as $type => $child) {
+      $start = $child['start'];
+      $starts[$start][] = $type;
+    }
+
+    // next, sort the parts by their end. We want the span tag to
+    // to be added in the order the parts end.
+    usort($types, 'tripal_feature_sort_rel_parts_by_end');
+
+    // iterate through the types in order that then end and create a
+    // span for it.
+    foreach ($types as $type) {
+      $end = $type['end'];
+      $ends[$end][] = $type;
+    }
+  }
+
+  // iterate through each nucleotide in the sequence, add a new line very
+  // 50 characters and add the spans as we encounter them
+  for ($i = 0; $i < strlen($sequence); $i++) {
+
+    // if we are at and end of a span then close it
+    if (array_key_exists($i, $ends)) {
+      foreach ($ends[$i] as $index => $type) {
+        $newseq .= "</span>";
+      }
+    }
+
+    // if we are at and end of a span then close it
+    if (array_key_exists($i, $starts)) {
+      foreach ($starts[$i] as $index => $type) {
+        $class = "tripal_feature-featureloc_sequence-" . $type;
+        $newseq .= "<span class=\"$class\">";
+      }
+    }
+
+    $newseq .= $sequence{$i};
+    $seqcount++;
+    if ($seqcount % 50 == 0) {
+      $newseq .= "\n";
+    }
+  }
+
+  $newseq .= "</pre>";
+  return $newseq;
+}
+
+/**
+ * Used to sort the list of relationship parts by start position
+ *
+ * @ingroup tripal_feature
+ */
+function tripal_feature_sort_rel_parts_by_end($a, $b) {
+  $val = strnatcmp($b['end'], $a['end']);
+  if ($val == 0) {
+    return strcmp($a['type'], $b['type']);
+  }
+  return $val;
 }
 /**
  *
@@ -164,6 +594,77 @@ function tripal_feature_preprocess_tripal_feature_alignments(&$variables) {
   }
   $feature->all_featurelocs = $alignments;
 }
+/**
+ * This function is for features that align through an intermediate such
+ * as 'EST_match' or 'match'.  This occurs in the case where two sequences
+ * align but where one does not align perfectly.  Some ESTs may be in a contig
+ * but not all of the EST.  Portions may overhang and not be included in the
+ * consensus if quality is bad.
+ * For example:
+ *    Feature 1: Contig --------------------
+ *    Feature 2: EST_match           -------
+ *    Feature 3: EST                 ---------
+ *
+ * The feature provided to the function will always be the feature 1.  The
+ * featureloc columns prefixed with 'right' (e.g. right_fmin) belong to the
+ * alignment of feature 3 with feature 2
+ *
+ * Features may align to more than one feature and are not matches. We do
+   * not want to include these, so we have to filter on the SO terms:
+ * match, or %_match
+ *
+ * @ingroup tripal_feature
+ */
+function tripal_feature_get_matched_alignments($feature) {
+
+  $sql = "
+     SELECT
+       FL1.featureloc_id    as left_featureloc_id,
+       FL1.srcfeature_id    as left_srcfeature_id,
+       FL1.feature_id       as left_feature_id,
+       FL1.fmin             as left_fmin,
+       FL1.is_fmin_partial  as left_is_fmin_partial,
+       FL1.fmax             as left_fmax,
+       FL1.is_fmax_partial  as left_is_fmax_partial,
+       FL1.strand           as left_strand,
+       FL1.phase            as left_phase,
+       FL1.locgroup         as left_locgroup,
+       FL1.rank             as left_rank,
+       FL2.featureloc_id    as right_featureloc_id,
+       FL2.srcfeature_id    as right_srcfeature_id,
+       FL2.feature_id       as right_feature_id,
+       FL2.fmin             as right_fmin,
+       FL2.is_fmin_partial  as right_is_fmin_partial,
+       FL2.fmax             as right_fmax,
+       FL2.is_fmax_partial  as right_is_fmax_partial,
+       FL2.strand           as right_strand,
+       FL2.phase            as right_phase,
+       FL2.locgroup         as right_locgroup,
+       FL2.rank             as right_rank
+     FROM {feature} F1
+       INNER JOIN {featureloc} FL1 on FL1.srcfeature_id = F1.feature_id
+       INNER JOIN {feature} F2 on FL1.feature_id = F2.feature_id
+       INNER JOIN {featureloc} FL2 on FL2.feature_id = F2.feature_id
+       INNER JOIN {cvterm} CVT2 on F2.type_id = CVT2.cvterm_id
+     WHERE
+       F1.feature_id = :feature_id  AND
+       (CVT2.name = 'match' or CVT2.name like '%_match')
+     ORDER BY FL1.fmin
+   ";
+
+  $results = chado_query($sql, array(':feature_id' => $feature->feature_id));
+
+  // iterate through the results and add them to our featurelocs array
+  $featurelocs = array();
+  while ($fl = $results->fetchObject()) {
+    // ignore featurelocs where the left and right srcfeature is the same
+    if (strcmp($fl->left_srcfeature_id, $fl->right_srcfeature_id) == 0) {
+      continue;
+    }
+    $featurelocs[] = $fl ;
+  }
+  return $featurelocs;
+}
 /**
  *
  *
@@ -173,9 +674,91 @@ function tripal_feature_preprocess_tripal_organism_feature_counts(&$variables, $
   $organism = $variables['node']->organism;
   $organism->feature_counts = tripal_feature_load_organism_feature_counts($organism);
 }
+/**
+ * Load the arguments for the organism feature counts browser
+ *
+ * @param $organism
+ *  The organism of interest
+ *
+ * @ingroup tripal_feature
+ */
+function tripal_feature_load_organism_feature_counts($organism) {
+
+  $args = array();
+  $order = array();
+  $names = array();
+
+  // build the where clause for the SQL statement if we have a custom term list
+  // we'll also keep track of the names the admin provided (if any) and the
+  // order that the terms should appear.
+  $is_custom = 0;
+  $temp = rtrim(variable_get('tripal_feature_summary_report_mapping', ''));
+  $where = '';
+  if ($temp) {
+    $is_custom = 1;
+    $temp = explode("\n", $temp);
+    $i = 0;
+    foreach ($temp as $value) {
+      // separate the key value pairs
+      $temp2 = explode("=", $value);
+      $feature_type = rtrim($temp2[0]);
+      $order[] = $feature_type;  // save the order of the these terms
+      $where .= " OFC.feature_type = :name$i OR ";
+      $args[":name$i"] = rtrim($temp2[0]);
+
+      // if the admin specified a new name then store that otherwise use the
+      // the default sequence ontology term name
+      if(count($temp2) == 2) {
+        $names[] = rtrim($temp2[1]);
+      }
+      else {
+        $names[] = $feature_type;
+      }
+      $i++;
+    }
+    if ($where) {
+      $where = drupal_substr($where, 0, -4);  # remove OR from the end
+      $where = "($where) AND";
+    }
+  }
+
+  // get the feature counts.  This is dependent on a materialized view
+  // installed with the organism module
+  $sql = "
+  SELECT OFC.num_features,OFC.feature_type,CVT.definition
+  FROM {organism_feature_count} OFC
+  INNER JOIN {cvterm} CVT on OFC.cvterm_id = CVT.cvterm_id
+  WHERE $where organism_id = :organism_id
+  ORDER BY num_features desc
+  ";
+  $args[':organism_id'] = $organism->organism_id;
+  $org_features = chado_query($sql, $args);
+
+  // iterate through the types
+  $types = array();
+  while ($type = $org_features->fetchObject()) {
+  $types[$type->feature_type] = $type;
+  // if we don't have an order this means we didn't go through the loop
+  // above to set the names, so do that now
+  if (!$is_custom) {
+  $names[] = $type->feature_type;
+  $order[] = $type->feature_type;
+  }
+  }
+
+  // now reorder the types
+  $ordered_types = array();
+  foreach ($order as $type) {
+  $ordered_types[] = $types[$type];
+  }
+  return array(
+  'types' => $ordered_types,
+      'names' => $names
+  );
+}
 
 /**
- * Using the tripal_core_expand_chado_vars function to retrieve a set
+ * Using the chado_expand_var function to retrieve a set
  * of relationships can be very slow, especialy if there are many relationships
  * This function is intended to help speed up the retrieval of relationships
  * by only retrieving the base information for the relationship and returning

+ 0 - 580
tripal_feature/tripal_feature.module

@@ -336,587 +336,7 @@ function tripal_feature_theme($existing, $type, $theme, $path) {
   return $items;
 }
 
-/**
- * Load the locations for a given feature
- *
- * @param $feature_id
- *   The feature to look up locations for
- * @param $side
- *   Whether the feature is the scrfeature, 'as_parent', or feature, 'as_child'
- * @param $aggregate
- *   Whether or not to get the locations for related features
- *
- * @ingroup tripal_feature
- */
-function tripal_feature_load_featurelocs($feature_id, $side = 'as_parent', $aggregate = 1) {
-
-  $sql = "
-    SELECT
-       F.name, F.feature_id, F.uniquename,
-       FS.name as src_name, FS.feature_id as src_feature_id, FS.uniquename as src_uniquename,
-       CVT.name as cvname, CVT.cvterm_id,
-       CVTS.name as src_cvname, CVTS.cvterm_id as src_cvterm_id,
-       FL.fmin, FL.fmax, FL.is_fmin_partial, FL.is_fmax_partial,FL.strand, FL.phase
-     FROM {featureloc} FL
-       INNER JOIN {feature} F   ON FL.feature_id = F.feature_id
-       INNER JOIN {feature} FS  ON FS.feature_id = FL.srcfeature_id
-       INNER JOIN {cvterm} CVT  ON F.type_id     = CVT.cvterm_id
-       INNER JOIN {cvterm} CVTS ON FS.type_id    = CVTS.cvterm_id
-   ";
-  if (strcmp($side, 'as_parent')==0) {
-    $sql .= "WHERE FL.srcfeature_id = :feature_id ";
-  }
-  if (strcmp($side, 'as_child')==0) {
-    $sql .= "WHERE FL.feature_id = :feature_id ";
-  }
-
-  $flresults = chado_query($sql, array(':feature_id' => $feature_id));
-
-  // copy the results into an array
-  $i=0;
-  $featurelocs = array();
-  while ($loc = $flresults->fetchObject()) {
-    // if a drupal node exists for this feature then add the nid to the
-    // results object
-    $loc->fnid = chado_get_nid_from_id('feature', $loc->feature_id);
-    $loc->snid = chado_get_nid_from_id('feature', $loc->src_feature_id);
-    // add the result to the array
-    $featurelocs[$i++] = $loc;
-  }
-
-  // Add the relationship feature locs if aggregate is turned on
-  if ($aggregate and strcmp($side, 'as_parent')==0) {
-    // get the relationships for this feature without substituting any children
-    // for the parent. We want all relationships
-    $relationships = tripal_feature_get_aggregate_relationships($feature_id, 0);
-    foreach ($relationships as $rindex => $rel) {
-      // get the featurelocs for each of the relationship features
-      $rel_featurelocs = tripal_feature_load_featurelocs($rel->subject_id, 'as_child', 0);
-      foreach ($rel_featurelocs as $findex => $rfloc) {
-        $featurelocs[$i++] = $rfloc;
-      }
-    }
-  }
-
-  usort($featurelocs, 'tripal_feature_sort_locations');
-  return $featurelocs;
-}
-
-/**
- * Used to sort the feature locs by start position
- *
- * @param $a
- *   One featureloc record (as an object)
- * @param $b
- *   The other featureloc record (as an object)
- *
- * @return
- *   Which feature location comes first
- *
- * @ingroup tripal_feature
- */
-function tripal_feature_sort_locations($a, $b) {
-  return strnatcmp($a->fmin, $b->fmin);
-}
-
-/**
- * Get the relationships for a feature.
- *
- * @param $feature_id
- *   The feature to get relationships for
- * @param $side
- *   The side of the relationship this feature is (ie: 'as_subject' or 'as_object')
- *
- * @ingroup tripal_feature
- */
-function tripal_feature_load_relationships($feature_id, $side = 'as_subject') {
-  // get the relationships for this feature.  The query below is used for both
-  // querying the object and subject relationships
-  $sql = "
-    SELECT
-      FS.name as subject_name, FS.uniquename as subject_uniquename,
-      CVTS.name as subject_type, CVTS.cvterm_id as subject_type_id,
-      FR.subject_id, FR.type_id as relationship_type_id, FR.object_id, FR.rank,
-      CVT.name as rel_type,
-      FO.name as object_name, FO.uniquename as object_uniquename,
-      CVTO.name as object_type, CVTO.cvterm_id as object_type_id
-    FROM {feature_relationship} FR
-     INNER JOIN {cvterm} CVT  ON FR.type_id    = CVT.cvterm_id
-     INNER JOIN {feature} FS  ON FS.feature_id = FR.subject_id
-     INNER JOIN {feature} FO  ON FO.feature_id = FR.object_id
-     INNER JOIN {cvterm} CVTO ON FO.type_id    = CVTO.cvterm_id
-     INNER JOIN {cvterm} CVTS ON FS.type_id    = CVTS.cvterm_id
-  ";
-  if (strcmp($side, 'as_object')==0) {
-    $sql .= " WHERE FR.object_id = :feature_id";
-  }
-  if (strcmp($side, 'as_subject')==0) {
-    $sql .= " WHERE FR.subject_id = :feature_id";
-  }
-  $sql .= " ORDER BY FR.rank";
-
-  // get the relationships
-  $results = chado_query($sql, array(':feature_id' => $feature_id));
-
-
-  // iterate through the relationships, put these in an array and add
-  // in the Drupal node id if one exists
-  $i=0;
-  $nodesql = "SELECT nid FROM {chado_feature} WHERE feature_id = :feature_id";
-  $relationships = array();
-  while ($rel = $results->fetchObject()) {
-    $node = db_query($nodesql, array(':feature_id' => $rel->subject_id))->fetchObject();
-    if ($node) {
-      $rel->subject_nid = $node->nid;
-    }
-    $node = db_query($nodesql, array(':feature_id' => $rel->object_id))->fetchObject();
-    if ($node) {
-      $rel->object_nid = $node->nid;
-    }
-    $relationships[$i++] = $rel;
-  }
-  return $relationships;
-}
-
-/**
- * Get features related to the current feature to a given depth. Recursive function.
- *
- * @param $feature_id
- * @param $substitute
- * @param $levels
- * @param $base_type_id
- * @param $depth
- *
- * @ingroup tripal_feature
- */
-function tripal_feature_get_aggregate_relationships($feature_id, $substitute=1,
-  $levels=0, $base_type_id=NULL, $depth=0) {
-
-  // we only want to recurse to as many levels deep as indicated by the
-  // $levels variable, but only if this variable is > 0. If 0 then we
-  // recurse until we reach the end of the relationships tree.
-  if ($levels > 0 and $levels == $depth) {
-    return NULL;
-  }
-
-  // first get the relationships for this feature
-  return tripal_feature_load_relationships($feature_id, 'as_object');
-
-}
-
-/**
- * Get the sequence this feature is located on
- *
- * @param $feature_id
- * @param $featurelocs
- *
- * @ingroup tripal_feature
- */
-function tripal_feature_load_featureloc_sequences($feature_id, $featurelocs) {
-
-  // if we don't have any featurelocs then no point in continuing
-  if (!$featurelocs) {
-    return array();
-  }
-
-  // get the list of relationships (including any aggregators) and iterate
-  // through each one to find information needed to color-code the reference sequence
-  $relationships = tripal_feature_get_aggregate_relationships($feature_id);
-  if (!$relationships) {
-    return array();
-  }
-
-
-  // iterate through each of the realtionships features and get their
-  // locations
-  foreach ($relationships as $rindex => $rel) {
-    // get the featurelocs for each of the relationship features
-    $rel_featurelocs = tripal_feature_load_featurelocs($rel->subject_id, 'as_child', 0);
-    foreach ($rel_featurelocs as $rfindex => $rel_featureloc) {
-      // keep track of this unique source feature
-      $src = $rel_featureloc->src_feature_id . "-" . $rel_featureloc->src_cvterm_id;
-
-      // copy over the results to the relationship object.  Since there can
-      // be more than one feature location for each relationship feature we
-      // use the '$src' variable to keep track of these.
-      $rel->featurelocs = new stdClass();
-      $rel->featurelocs->$src = new stdClass();
-      $rel->featurelocs->$src->src_uniquename = $rel_featureloc->src_uniquename;
-      $rel->featurelocs->$src->src_cvterm_id  = $rel_featureloc->src_cvterm_id;
-      $rel->featurelocs->$src->src_cvname     = $rel_featureloc->src_cvname;
-      $rel->featurelocs->$src->fmin           = $rel_featureloc->fmin;
-      $rel->featurelocs->$src->fmax           = $rel_featureloc->fmax;
-      $rel->featurelocs->$src->src_name       = $rel_featureloc->src_name;
-
-      // keep track of the individual parts for each relationship
-      $start = $rel->featurelocs->$src->fmin;
-      $end   = $rel->featurelocs->$src->fmax;
-      $type  = $rel->subject_type;
-      $rel_locs[$src]['parts'][$start][$type]['start'] = $start;
-      $rel_locs[$src]['parts'][$start][$type]['end']   = $end;
-      $rel_locs[$src]['parts'][$start][$type]['type']  = $type;
-    }
-  }
-
-  // the featurelocs array provided to the function contains the locations
-  // where this feature is found.   We want to get the sequence for each
-  // location and then annotate it with the parts found from the relationships
-  // locations determiend above.
-  $floc_sequences = array();
-  foreach ($featurelocs as $featureloc) {
-
-    // build the src name so we can keep track of the different parts for each feature
-    $src = $featureloc->srcfeature_id->feature_id . "-" . $featureloc->srcfeature_id->type_id->cvterm_id;
 
-    // orient the parts to the beginning of the feature sequence
-    if (!empty($rel_locs[$src]['parts'])) {
-      $parts = $rel_locs[$src]['parts'];
-      $rparts = array();  // we will fill this up if we're on the reverse strand
-
-      foreach ($parts as $start => $types) {
-        foreach ($types as $type_name => $type) {
-          if ($featureloc->strand >= 0) {
-             // this is on the forward strand.  We need to convert the start on the src feature to the
-             // start on this feature's sequence
-             $parts[$start][$type_name]['start'] = $parts[$start][$type_name]['start'] - $featureloc->fmin;
-             $parts[$start][$type_name]['end']   = $parts[$start][$type_name]['end'] - $featureloc->fmin;
-             $parts[$start][$type_name]['type']  = $type_name;
-          }
-          else {
-             // this is on the reverse strand.  We need to swap the start and stop and calculate from the
-             // begining of the reverse sequence
-             $size = ($featureloc->fmax - $featureloc->fmin);
-             $start_orig = $parts[$start][$type_name]['start'];
-             $end_orig = $parts[$start][$type_name]['end'];
-             $new_start = $size - ($end_orig - $featureloc->fmin);
-             $new_end = $size - ($start_orig - $featureloc->fmin);
-
-             $rparts[$new_start][$type_name]['start'] = $new_start;
-             $rparts[$new_start][$type_name]['end']   = $new_end;
-             $rparts[$new_start][$type_name]['type']  = $type_name;
-          }
-        }
-      }
-
-      // now sort the parts
-      // if we're on the reverse strand we need to resort
-      if ($featureloc->strand >= 0) {
-        usort($parts, 'tripal_feature_sort_rel_parts_by_start');
-      }
-      else {
-        usort($rparts, 'tripal_feature_sort_rel_parts_by_start');
-        $parts = $rparts;
-      }
-
-      $floc_sequences[$src]['src'] = $src;
-      $floc_sequences[$src]['type'] = $featureloc->feature_id->type_id->name;
-      $args = array(':feature_id' => $featureloc->srcfeature_id->feature_id);
-      $start = $featureloc->fmin + 1;
-      $size = $featureloc->fmax - $featureloc->fmin;
-      // TODO: fix the hard coded $start and $size
-      // the $start and $size variables are hard-coded in the SQL statement
-      // because the db_query function places quotes around all placeholders
-      // (e.g. :start & :size) and screws up the substring function
-      $sql = "
-        SELECT substring(residues from $start for $size) as residues
-        FROM {feature}
-        WHERE feature_id = :feature_id
-      ";
-      $sequence = chado_query($sql, $args)->fetchObject();
-      $residues = $sequence->residues;
-      if ($featureloc->strand < 0) {
-         $residues = tripal_feature_reverse_complement($residues);
-      }
-      $strand = '.';
-      if ($featureloc->strand == 1) {
-        $strand = '+';
-      }
-      elseif ($featureloc->strand == -1) {
-        $strand = '-';
-      }
-      $defline = $featureloc->feature_id->name . " " . $featureloc->srcfeature_id->name . ":" . ($featureloc->fmin + 1) . ".." . $featureloc->fmax . " " . $strand;
-      $floc_sequences[$src]['formatted_seq'] =  tripal_feature_color_sequence($residues, $parts, $defline);
-    }
-  }
-  return $floc_sequences;
-}
-
-/**
- * This function is for features that align through an intermediate such
- * as 'EST_match' or 'match'.  This occurs in the case where two sequences
- * align but where one does not align perfectly.  Some ESTs may be in a contig
- * but not all of the EST.  Portions may overhang and not be included in the
- * consensus if quality is bad.
- * For example:
- *    Feature 1: Contig --------------------
- *    Feature 2: EST_match           -------
- *    Feature 3: EST                 ---------
- *
- * The feature provided to the function will always be the feature 1.  The
- * featureloc columns prefixed with 'right' (e.g. right_fmin) belong to the
- * alignment of feature 3 with feature 2
- *
- * Features may align to more than one feature and are not matches. We do
- * not want to include these, so we have to filter on the SO terms:
- * match, or %_match
- *
- * @ingroup tripal_feature
- */
-function tripal_feature_get_matched_alignments($feature) {
-
-   $sql = "
-     SELECT
-       FL1.featureloc_id    as left_featureloc_id,
-       FL1.srcfeature_id    as left_srcfeature_id,
-       FL1.feature_id       as left_feature_id,
-       FL1.fmin             as left_fmin,
-       FL1.is_fmin_partial  as left_is_fmin_partial,
-       FL1.fmax             as left_fmax,
-       FL1.is_fmax_partial  as left_is_fmax_partial,
-       FL1.strand           as left_strand,
-       FL1.phase            as left_phase,
-       FL1.locgroup         as left_locgroup,
-       FL1.rank             as left_rank,
-       FL2.featureloc_id    as right_featureloc_id,
-       FL2.srcfeature_id    as right_srcfeature_id,
-       FL2.feature_id       as right_feature_id,
-       FL2.fmin             as right_fmin,
-       FL2.is_fmin_partial  as right_is_fmin_partial,
-       FL2.fmax             as right_fmax,
-       FL2.is_fmax_partial  as right_is_fmax_partial,
-       FL2.strand           as right_strand,
-       FL2.phase            as right_phase,
-       FL2.locgroup         as right_locgroup,
-       FL2.rank             as right_rank
-     FROM {feature} F1
-       INNER JOIN {featureloc} FL1 on FL1.srcfeature_id = F1.feature_id
-       INNER JOIN {feature} F2 on FL1.feature_id = F2.feature_id
-       INNER JOIN {featureloc} FL2 on FL2.feature_id = F2.feature_id
-       INNER JOIN {cvterm} CVT2 on F2.type_id = CVT2.cvterm_id
-     WHERE
-       F1.feature_id = :feature_id  AND
-       (CVT2.name = 'match' or CVT2.name like '%_match')
-     ORDER BY FL1.fmin
-   ";
-
-   $results = chado_query($sql, array(':feature_id' => $feature->feature_id));
-
-   // iterate through the results and add them to our featurelocs array
-   $featurelocs = array();
-   while ($fl = $results->fetchObject()) {
-     // ignore featurelocs where the left and right srcfeature is the same
-     if (strcmp($fl->left_srcfeature_id, $fl->right_srcfeature_id) == 0) {
-       continue;
-     }
-     $featurelocs[] = $fl ;
-   }
-   return $featurelocs;
-}
-
-/**
- * Load the arguments for the organism feature counts browser
- *
- * @param $organism
- *  The organism of interest
- *
- * @ingroup tripal_feature
- */
-function tripal_feature_load_organism_feature_counts($organism) {
-
-  $args = array();
-  $order = array();
-  $names = array();
-
-  // build the where clause for the SQL statement if we have a custom term list
-  // we'll also keep track of the names the admin provided (if any) and the
-  // order that the terms should appear.
-  $is_custom = 0;
-  $temp = rtrim(variable_get('tripal_feature_summary_report_mapping', ''));
-  $where = '';
-  if ($temp) {
-    $is_custom = 1;
-    $temp = explode("\n", $temp);
-    $i = 0;
-    foreach ($temp as $value) {
-      // separate the key value pairs
-      $temp2 = explode("=", $value);
-      $feature_type = rtrim($temp2[0]);
-      $order[] = $feature_type;  // save the order of the these terms
-      $where .= " OFC.feature_type = :name$i OR ";
-      $args[":name$i"] = rtrim($temp2[0]);
-
-      // if the admin specified a new name then store that otherwise use the
-      // the default sequence ontology term name
-      if(count($temp2) == 2) {
-        $names[] = rtrim($temp2[1]);
-      }
-      else {
-        $names[] = $feature_type;
-      }
-      $i++;
-    }
-    if ($where) {
-      $where = drupal_substr($where, 0, -4);  # remove OR from the end
-      $where = "($where) AND";
-    }
-  }
-
-  // get the feature counts.  This is dependent on a materialized view
-  // installed with the organism module
-  $sql = "
-    SELECT OFC.num_features,OFC.feature_type,CVT.definition
-    FROM {organism_feature_count} OFC
-      INNER JOIN {cvterm} CVT on OFC.cvterm_id = CVT.cvterm_id
-    WHERE $where organism_id = :organism_id
-    ORDER BY num_features desc
-  ";
-  $args[':organism_id'] = $organism->organism_id;
-  $org_features = chado_query($sql, $args);
-
-  // iterate through the types
-  $types = array();
-  while ($type = $org_features->fetchObject()) {
-    $types[$type->feature_type] = $type;
-    // if we don't have an order this means we didn't go through the loop
-    // above to set the names, so do that now
-    if (!$is_custom) {
-      $names[] = $type->feature_type;
-      $order[] = $type->feature_type;
-    }
-  }
-
-  // now reorder the types
-  $ordered_types = array();
-  foreach ($order as $type) {
-    $ordered_types[] = $types[$type];
-  }
-  return array(
-    'types' => $ordered_types,
-    'names' => $names
-  );
-}
-
-/**
- * Used to sort the list of relationship parts by start position
- *
- * @ingroup tripal_feature
- */
-function tripal_feature_sort_rel_parts_by_start($a, $b) {
-  foreach ($a as $type_name => $details) {
-     $astart = $a[$type_name]['start'];
-     break;
-  }
-  foreach ($b as $type_name => $details) {
-     $bstart = $b[$type_name]['start'];
-     break;
-  }
-  return strnatcmp($astart, $bstart);
-}
-
-/**
- * Used to sort the list of relationship parts by start position
- *
- * @ingroup tripal_feature
- */
-function tripal_feature_sort_rel_parts_by_end($a, $b) {
-  $val = strnatcmp($b['end'], $a['end']);
-  if ($val == 0) {
-     return strcmp($a['type'], $b['type']);
-  }
-  return $val;
-}
-
-/**
- * Returns the marked up fasta sequence for the described feature
- *
- * @param $sequence
- * @param $parts
- * @param $defline
- *
- * @ingroup tripal_feature
- */
-function tripal_feature_color_sequence($sequence, $parts, $defline) {
-
-
-  $types = array();
-  // first get the list of types so we can create a color legend
-  foreach ($parts as $index => $t) {
-    foreach ($t as $type_name => $details) {
-       $types[$type_name] = 1;
-    }
-  }
-
-  $newseq = "<div id=\"tripal_feature-featureloc_sequence-legend\">Legend: ";
-  foreach ($types as $type_name => $present) {
-    $newseq .= "<span id=\"tripal_feature-legend-$type_name\" class=\"tripal_feature-legend-item tripal_feature-featureloc_sequence-$type_name\" script=\"\">$type_name</span>";
-  }
-  $newseq .= "</div>Hold the cursor over a type above to highlight its positions in the sequence below. The colors in the sequence below merge when types overlap.";
-
-
-  // set the background color of the rows based on the type
-  $pos = 0;
-  $newseq .= "<pre id=\"tripal_feature-featureloc_sequence\">";
-  $newseq .= ">$defline\n";
-
-  // iterate through the parts. They should be in order.
-  $ends = array();
-  $seqcount = 0;
-  foreach ($parts as $index => $types) {
-
-    // get the start for this part.  All types in this part start at the
-    // same position so we only need the first record
-    foreach ($types as $type => $child) {
-      $start = $child['start'];
-      break;
-    }
-
-    // add in the sequence up to the start of this part
-    for ($i = $pos; $i < $start; $i++) {
-      $newseq .= $sequence{$pos};
-      $seqcount++;
-      if ($seqcount % 50 == 0) {
-        $newseq .= "\n";
-      }
-      if (array_key_exists($pos, $ends)) {
-        foreach ($ends[$pos] as $end) {
-          $newseq .= "</span>";
-        }
-      }
-      $pos++;
-    }
-
-    // we want to sort the parts by their end. We want the span tag to
-    // to be added in the order the parts end.
-    usort($types, 'tripal_feature_sort_rel_parts_by_end');
-
-    // now add the child span for all types that start at this position
-    foreach ($types as $type) {
-      $class = "tripal_feature-featureloc_sequence-" . $type['type'];
-      $newseq .= "<span class=\"$class\">";
-      // add the end position
-      $end = $type['end'];
-      $ends[$end][] = $end;
-    }
-  }
-
-  // add in rest of the sequence
-  for ($i = $pos; $i < strlen($sequence); $i++) {
-    $newseq .= $sequence{$pos};
-    $seqcount++;
-    if ($seqcount % 50 == 0) {
-      $newseq .= "\n";
-    }
-    if (array_key_exists($pos, $ends)) {
-      foreach ($ends[$pos] as $end) {
-        $newseq .= "</span>";
-      }
-    }
-    $pos++;
-  }
-
-  $newseq .= "</pre>";
-  return $newseq;
-}
 
 /**
  * The CV module will create the JSON array necessary for buillding a

+ 2 - 2
tripal_featuremap/theme/templates/tripal_feature_featurepos.tpl.php

@@ -27,7 +27,7 @@ $options = array(
   ),
 );
 
-$feature = tripal_core_expand_chado_vars($feature, 'table', 'featurepos', $options);
+$feature = chado_expand_var($feature, 'table', 'featurepos', $options);
 
 // because the featurepos table has  FK relationships with map_feature_id and feature_id with the feature table 
 // the function call above will try to expand both and will create an array of matches for each FK.
@@ -64,7 +64,7 @@ if(count($map_positions) > 0){ ?>
         'type_id' => 1,            
       ),
     );
-    $position = tripal_core_expand_chado_vars($position, 'table', 'featureposprop', $options);
+    $position = chado_expand_var($position, 'table', 'featureposprop', $options);
     $featureposprop = $position->featureposprop;
     $start = '';
     $stop = '';

+ 1 - 1
tripal_featuremap/theme/templates/tripal_featuremap_base.tpl.php

@@ -3,7 +3,7 @@
 $featuremap  = $variables['node']->featuremap;
 
 // expand the description field
-$featuremap = tripal_core_expand_chado_vars($featuremap, 'field', 'featuremap.description'); ?>
+$featuremap = chado_expand_var($featuremap, 'field', 'featuremap.description'); ?>
 
 <div class="tripal_featuremap-data-block-desc tripal-data-block-desc"></div> <?php 
 

+ 2 - 2
tripal_featuremap/theme/templates/tripal_featuremap_featurepos.tpl.php

@@ -29,7 +29,7 @@ $options = array(
   ),
 );
 
-$featuremap = tripal_core_expand_chado_vars($featuremap, 'table', 'featurepos', $options);
+$featuremap = chado_expand_var($featuremap, 'table', 'featurepos', $options);
 $feature_positions = $featuremap->featurepos;
 
 
@@ -64,7 +64,7 @@ if(count($feature_positions) > 0){ ?>
         'type_id' => 1,            
       ),
     );
-    $position = tripal_core_expand_chado_vars($position, 'table', 'featureposprop', $options);
+    $position = chado_expand_var($position, 'table', 'featureposprop', $options);
     $featureposprop = $position->featureposprop;
     $start = 0;
     $stop = 0;

+ 2 - 2
tripal_featuremap/theme/templates/tripal_featuremap_properties.tpl.php

@@ -2,7 +2,7 @@
 
 $featuremap = $variables['node']->featuremap;
 $options = array('return_array' => 1);
-$featuremap = tripal_core_expand_chado_vars($featuremap, 'table', 'featuremapprop', $options);
+$featuremap = chado_expand_var($featuremap, 'table', 'featuremapprop', $options);
 $properties = $featuremap->featuremapprop;
 
 if(count($properties) > 0){
@@ -18,7 +18,7 @@ if(count($properties) > 0){
   $rows = array();
 
   foreach ($properties as $property){
-    $property = tripal_core_expand_chado_vars($property,'field','featuremapprop.value');
+    $property = chado_expand_var($property,'field','featuremapprop.value');
     $rows[] = array(
       ucfirst(preg_replace('/_/', ' ', $property->type_id->name)),
       urldecode($property->value)

+ 4 - 4
tripal_featuremap/theme/templates/tripal_featuremap_publication.tpl.php

@@ -3,7 +3,7 @@ $featuremap = $variables['node']->featuremap;
 
 // expand featuremap to include pubs 
 $options = array('return_array' => 1);
-$featuremap = tripal_core_expand_chado_vars($featuremap, 'table', 'featuremap_pub', $options);
+$featuremap = chado_expand_var($featuremap, 'table', 'featuremap_pub', $options);
 $featuremap_pubs = $featuremap->featuremap_pub; 
 
 
@@ -23,7 +23,7 @@ if (count($featuremap_pubs) > 0) { ?>
   
   foreach ($featuremap_pubs as $featuremap_pub) {
     $pub = $featuremap_pub->pub_id;
-    $pub = tripal_core_expand_chado_vars($pub, 'field', 'pub.title');
+    $pub = chado_expand_var($pub, 'field', 'pub.title');
     $citation = $pub->title;  // use the title as the default citation
     
     // get the citation for this pub if it exists
@@ -34,9 +34,9 @@ if (count($featuremap_pubs) > 0) { ?>
       ),
     );
     $options = array('return_array' => 1);
-    $citation_prop = tripal_core_generate_chado_var('pubprop', $values, $options); 
+    $citation_prop = chado_generate_var('pubprop', $values, $options); 
     if (count($citation_prop) == 1) {
-      $citation_prop = tripal_core_expand_chado_vars($citation_prop, 'field', 'pubprop.value');
+      $citation_prop = chado_expand_var($citation_prop, 'field', 'pubprop.value');
       $citation = $citation_prop[0]->value;
     }
     

+ 1 - 1
tripal_featuremap/theme/templates/tripal_featuremap_references.tpl.php

@@ -4,7 +4,7 @@ $references = array();
 
 // expand the featuremap object to include the records from the featuremap_dbxref table
 $options = array('return_array' => 1);
-$featuremap = tripal_core_expand_chado_vars($featuremap, 'table', 'featuremap_dbxref', $options);
+$featuremap = chado_expand_var($featuremap, 'table', 'featuremap_dbxref', $options);
 $featuremap_dbxrefs = $featuremap->featuremap_dbxref;
 if (count($featuremap_dbxrefs) > 0 ) {
   foreach ($featuremap_dbxrefs as $featuremap_dbxref) {    

+ 1 - 1
tripal_featuremap/theme/templates/tripal_featuremap_teaser.tpl.php

@@ -1,7 +1,7 @@
 <?php
 $node = $variables['node'];
 $featuremap = $variables['node']->featuremap;
-$featuremap = tripal_core_expand_chado_vars($featuremap,'field','featuremap.description'); ?>
+$featuremap = chado_expand_var($featuremap,'field','featuremap.description'); ?>
 
 <div class="tripal_featuremap-teaser tripal-teaser"> 
   <div class="tripal-featuremap-teaser-title tripal-teaser-title"><?php 

+ 3 - 3
tripal_genetic/theme/templates/tripal_feature_genotypes.tpl.php

@@ -36,7 +36,7 @@ $options = array(
     'element' => $feature_pager_id
   ),
 );
-$feature = tripal_core_expand_chado_vars($feature, 'table', 'feature_genotype', $options); 
+$feature = chado_expand_var($feature, 'table', 'feature_genotype', $options); 
 $feature_genotypes = $feature->feature_genotype->feature_id;
 
 // get the total number of records
@@ -74,7 +74,7 @@ if (count($feature_genotypes) > 0) {?>
     
     // get the genotype properties
     $options = array('return_array' => 1);
-    $genotype = tripal_core_expand_chado_vars($genotype, 'table', 'genotypeprop', $options);
+    $genotype = chado_expand_var($genotype, 'table', 'genotypeprop', $options);
     $properties = $genotype->genotypeprop; 
     $details = '';
     if(count($properties) > 0) {
@@ -93,7 +93,7 @@ if (count($feature_genotypes) > 0) {?>
         )
       ),
     );
-    $genotype = tripal_core_expand_chado_vars($genotype, 'table', 'stock_genotype', $options);
+    $genotype = chado_expand_var($genotype, 'table', 'stock_genotype', $options);
     $stock_genotypes = $genotype->stock_genotype; 
 
     // build the list of germplasm.

+ 3 - 3
tripal_genetic/theme/templates/tripal_stock_genotypes.tpl.php

@@ -29,7 +29,7 @@ $options = array(
     'genotype_id' => 1
   ),
 );
-$stock = tripal_core_expand_chado_vars($stock, 'table', 'stock_genotype', $options); 
+$stock = chado_expand_var($stock, 'table', 'stock_genotype', $options); 
 $stock_genotypes = $stock->stock_genotype;
 
 // get the total number of records
@@ -55,7 +55,7 @@ if (count($stock_genotypes) > 0) {?>
     
     // get the genotype properties
     $options = array('return_array' => 1);
-    $genotype = tripal_core_expand_chado_vars($genotype, 'table', 'genotypeprop', $options);
+    $genotype = chado_expand_var($genotype, 'table', 'genotypeprop', $options);
     $properties = $genotype->genotypeprop; 
     
     // add in markers associated with this genotype if any
@@ -67,7 +67,7 @@ if (count($stock_genotypes) > 0) {?>
         )
       ),
     );
-    $genotype = tripal_core_expand_chado_vars($genotype, 'table', 'feature_genotype', $options);
+    $genotype = chado_expand_var($genotype, 'table', 'feature_genotype', $options);
     $feature_genotypes = $genotype->feature_genotype; 
     
     // show the uniquename for the genotype unless a name exists

+ 1 - 1
tripal_library/theme/templates/tripal_feature_libraries.tpl.php

@@ -4,7 +4,7 @@ $feature = $variables['node']->feature;
 // expand the feature object to include the libraries from the library
 // table in chado.
 $options = array('return_array' => 1);
-$feature = tripal_core_expand_chado_vars($feature, 'table', 'library_feature', $options);
+$feature = chado_expand_var($feature, 'table', 'library_feature', $options);
 $library_features = $feature->library_feature;
 
 

+ 1 - 1
tripal_library/theme/templates/tripal_library_features.tpl.php

@@ -32,7 +32,7 @@ foreach ($results as $library_feature) {
       'type_id' => 1
     )
   );
-  $features[] = tripal_core_generate_chado_var('feature', $values, $options);
+  $features[] = chado_generate_var('feature', $values, $options);
 }
 
 if (count($features) > 0) { ?>

+ 2 - 2
tripal_library/theme/templates/tripal_library_properties.tpl.php

@@ -2,7 +2,7 @@
 
 $library = $variables['node']->library;
 $options = array('return_array' => 1);
-$library = tripal_core_expand_chado_vars($library, 'table', 'libraryprop', $options);
+$library = chado_expand_var($library, 'table', 'libraryprop', $options);
 $props = $library->libraryprop;
 
 // iterate through the properties and remove the 'library_description' as it is
@@ -29,7 +29,7 @@ if(count($properties) > 0){
   $rows = array();
   
   foreach ($properties as $property){
-    $property = tripal_core_expand_chado_vars($property,'field','libraryprop.value');
+    $property = chado_expand_var($property,'field','libraryprop.value');
     $rows[] = array(
       ucfirst(preg_replace('/_/', ' ', $property->type_id->name)),
       urldecode($property->value)

+ 4 - 4
tripal_library/theme/templates/tripal_library_publications.tpl.php

@@ -3,7 +3,7 @@ $library = $variables['node']->library;
 
 // expand library to include pubs 
 $options = array('return_array' => 1);
-$library = tripal_core_expand_chado_vars($library, 'table', 'library_pub', $options);
+$library = chado_expand_var($library, 'table', 'library_pub', $options);
 $library_pubs = $library->library_pub; 
 
 
@@ -23,7 +23,7 @@ if (count($library_pubs) > 0) { ?>
   
   foreach ($library_pubs as $library_pub) {
     $pub = $library_pub->pub_id;
-    $pub = tripal_core_expand_chado_vars($pub, 'field', 'pub.title');
+    $pub = chado_expand_var($pub, 'field', 'pub.title');
     $citation = $pub->title;  // use the title as the default citation
     
     // get the citation for this pub if it exists
@@ -34,9 +34,9 @@ if (count($library_pubs) > 0) { ?>
       ),
     );
     $options = array('return_array' => 1);
-    $citation_prop = tripal_core_generate_chado_var('pubprop', $values, $options); 
+    $citation_prop = chado_generate_var('pubprop', $values, $options); 
     if (count($citation_prop) == 1) {
-      $citation_prop = tripal_core_expand_chado_vars($citation_prop, 'field', 'pubprop.value');
+      $citation_prop = chado_expand_var($citation_prop, 'field', 'pubprop.value');
       $citation = $citation_prop[0]->value;
     }
     

+ 1 - 1
tripal_library/theme/templates/tripal_library_references.tpl.php

@@ -4,7 +4,7 @@ $references = array();
 
 // Second, expand the library object to include the records from the library_dbxref table
 $options = array('return_array' => 1);
-$library = tripal_core_expand_chado_vars($library, 'table', 'library_dbxref', $options);
+$library = chado_expand_var($library, 'table', 'library_dbxref', $options);
 $library_dbxrefs = $library->library_dbxref;
 if (count($library_dbxrefs) > 0 ) {
   foreach ($library_dbxrefs as $library_dbxref) {    

+ 1 - 1
tripal_library/theme/templates/tripal_library_synonyms.tpl.php

@@ -4,7 +4,7 @@ $library = $variables['node']->library;
 // expand the library object to include the synonyms from the library_synonym 
 // table in chado.
 $options = array('return_array' => 1);
-$library = tripal_core_expand_chado_vars($library, 'table', 'library_synonym', $options);
+$library = chado_expand_var($library, 'table', 'library_synonym', $options);
 $synonyms = $library->library_synonym;
 
 if(count($synonyms) > 0){ ?>

+ 1 - 1
tripal_library/theme/templates/tripal_library_terms.tpl.php

@@ -3,7 +3,7 @@
 $library = $variables['node']->library;
 
 $options = array('return_array' => 1);
-$library = tripal_core_expand_chado_vars($library, 'table', 'library_cvterm', $options);
+$library = chado_expand_var($library, 'table', 'library_cvterm', $options);
 $terms = $library->library_cvterm;
 
 // order the terms by CV

+ 1 - 1
tripal_library/theme/templates/tripal_organism_libraries.tpl.php

@@ -4,7 +4,7 @@ $organism = $variables['node']->organism;
 // expand the organism object to include the libraries from the library
 // table in chado.
 $options = array('return_array' => 1);
-$organism = tripal_core_expand_chado_vars($organism, 'table', 'library', $options);
+$organism = chado_expand_var($organism, 'table', 'library', $options);
 $libraries = $organism->library;
 
 

+ 5 - 5
tripal_natural_diversity/theme/templates/tripal_feature_nd_genotypes.tpl.php

@@ -59,7 +59,7 @@ $options = array(
     'element' => $feature_pager_id
   ),
 );
-$feature = tripal_core_expand_chado_vars($feature, 'table', 'feature_genotype', $options);
+$feature = chado_expand_var($feature, 'table', 'feature_genotype', $options);
 $feature_genotypes = $feature->feature_genotype->feature_id;
 
 // get the total number of records
@@ -102,7 +102,7 @@ if (count($feature_genotypes) > 0) { ?>
 
     // build the genotype properties
     $options = array('return_array' => 1);
-    $genotype = tripal_core_expand_chado_vars($genotype, 'table', 'genotypeprop', $options);
+    $genotype = chado_expand_var($genotype, 'table', 'genotypeprop', $options);
     $properties = $genotype->genotypeprop;
     $details = '';
     if(count($properties) > 0) {
@@ -114,7 +114,7 @@ if (count($feature_genotypes) > 0) { ?>
 
     // get the nd_experiment_genotype records and if any
     $values = array('genotype_id' => $genotype->genotype_id);
-    $nd_experiment_genotype = tripal_core_generate_chado_var('nd_experiment_genotype', $values);
+    $nd_experiment_genotype = chado_generate_var('nd_experiment_genotype', $values);
     if ($nd_experiment_genotype) {
       $nd_experiment    = $nd_experiment_genotype->nd_experiment_id;
       $nd_experiment_id = $nd_experiment_genotype->nd_experiment_id->nd_experiment_id;
@@ -129,7 +129,7 @@ if (count($feature_genotypes) > 0) { ?>
           )
         ),
       );
-      $nd_experiment = tripal_core_expand_chado_vars($nd_experiment, 'table', 'nd_experiment_stock', $options);
+      $nd_experiment = chado_expand_var($nd_experiment, 'table', 'nd_experiment_stock', $options);
       $nd_experiment_stocks = $nd_experiment->nd_experiment_stock;
       if (count($nd_experiment_stocks) > 0) {
         $stock_names = '';
@@ -147,7 +147,7 @@ if (count($feature_genotypes) > 0) { ?>
       // expand the nd_experiment object to incldue the nd_experiment_project table
       $values = array('nd_experiment_id' => $nd_experiment_id);
       $options = array('return_array' => 1);
-      $nd_experiment = tripal_core_expand_chado_vars($nd_experiment, 'table', 'nd_experiment_project', $options);
+      $nd_experiment = chado_expand_var($nd_experiment, 'table', 'nd_experiment_project', $options);
       $nd_experiment_projects = $nd_experiment->nd_experiment_project;
       if (count($nd_experiment_projects) > 0) {
         $project_names = '';

+ 3 - 3
tripal_natural_diversity/theme/templates/tripal_stock_nd_genotypes.tpl.php

@@ -138,7 +138,7 @@ if (count($genotypes) > 0) { ?>
 
     // build the genotype properties
     $options = array('return_array' => 1);
-    $genotype = tripal_core_expand_chado_vars($genotype, 'table', 'genotypeprop', $options);
+    $genotype = chado_expand_var($genotype, 'table', 'genotypeprop', $options);
     $properties = $genotype->genotypeprop;
     $details = '';
     if(count($properties) > 0) {
@@ -159,7 +159,7 @@ if (count($genotypes) > 0) { ?>
         )
       ),
     );
-    $genotype = tripal_core_expand_chado_vars($genotype, 'table', 'feature_genotype', $options);
+    $genotype = chado_expand_var($genotype, 'table', 'feature_genotype', $options);
     $feature_genotypes = $genotype->feature_genotype;
     if (count($feature_genotypes) > 0) {
       $feature_names = '';
@@ -177,7 +177,7 @@ if (count($genotypes) > 0) { ?>
     // expand the nd_experiment object to incldue the nd_experiment_project table
     $values = array('nd_experiment_id' => $nd_experiment_id);
     $options = array('return_array' => 1);
-    $nd_experiment = tripal_core_expand_chado_vars($nd_experiment, 'table', 'nd_experiment_project', $options);
+    $nd_experiment = chado_expand_var($nd_experiment, 'table', 'nd_experiment_project', $options);
     $nd_experiment_projects = $nd_experiment->nd_experiment_project;
     if (count($nd_experiment_projects) > 0) {
       $project_names = '';

+ 1 - 1
tripal_natural_diversity/theme/templates/tripal_stock_nd_phenotypes.tpl.php

@@ -137,7 +137,7 @@ if (count($phenotypes) > 0) {?>
     // but the database does not constrain that there only be one project so just in case we get them all
     $projects = array();
     $values = array('nd_experiment_id' => $nd_experiment_stock->nd_experiment_id->nd_experiment_id);
-    $nd_experiment_project = tripal_core_generate_chado_var('nd_experiment_project', $values, $options);
+    $nd_experiment_project = chado_generate_var('nd_experiment_project', $values, $options);
     $nd_experiment_projects = $nd_experiment_project;
     foreach ($nd_experiment_projects as $nd_experiment_project) {
       // we do have a project record, so add it to our $phenotypes array for display below

+ 1 - 1
tripal_organism/theme/templates/tripal_organism_base.tpl.php

@@ -1,7 +1,7 @@
 <?php
 
 $organism  = $variables['node']->organism;
-$organism = tripal_core_expand_chado_vars($organism,'field','organism.comment'); ?>
+$organism = chado_expand_var($organism,'field','organism.comment'); ?>
 
 <div class="tripal_organism-data-block-desc tripal-data-block-desc"></div><?php
 

+ 2 - 2
tripal_organism/theme/templates/tripal_organism_properties.tpl.php

@@ -2,7 +2,7 @@
 
 $organism = $variables['node']->organism;
 $options = array('return_array' => 1);
-$organism = tripal_core_expand_chado_vars($organism, 'table', 'organismprop', $options);
+$organism = chado_expand_var($organism, 'table', 'organismprop', $options);
 $properties = $organism->organismprop;
 
 if(count($properties) > 0){ 
@@ -19,7 +19,7 @@ if(count($properties) > 0){
   $rows = array();
   
   foreach ($properties as $property){
-    $property = tripal_core_expand_chado_vars($property,'field','organismprop.value');
+    $property = chado_expand_var($property,'field','organismprop.value');
     $rows[] = array(
       ucfirst(preg_replace('/_/', ' ', $property->type_id->name)),
       urldecode($property->value)

+ 1 - 1
tripal_organism/theme/templates/tripal_organism_references.tpl.php

@@ -4,7 +4,7 @@ $references = array();
 
 // expand the organism object to include the records from the organism_dbxref table
 $options = array('return_array' => 1);
-$organism = tripal_core_expand_chado_vars($organism, 'table', 'organism_dbxref', $options);
+$organism = chado_expand_var($organism, 'table', 'organism_dbxref', $options);
 $organism_dbxrefs = $organism->organism_dbxref;
 if (count($organism_dbxrefs) > 0 ) {
   foreach ($organism_dbxrefs as $organism_dbxref) {    

+ 4 - 4
tripal_phenotype/theme/templates/tripal_feature_phenotypes.tpl.php

@@ -12,7 +12,7 @@ $options = array(
     )
   )
 );
-$feature = tripal_core_expand_chado_vars($feature, 'table', 'feature_phenotype', $options);
+$feature = chado_expand_var($feature, 'table', 'feature_phenotype', $options);
 $feature_phenotypes = $feature->feature_phenotype;
 
 if(count($feature_phenotypes) > 0){ ?>
@@ -36,9 +36,9 @@ if(count($feature_phenotypes) > 0){ ?>
     
     // expand the text fields
     $options = array('return_array' => 1);
-    $phenotype = tripal_core_expand_chado_vars($phenotype, 'field', 'phenotype.value', $options);
-    $phenotype = tripal_core_expand_chado_vars($phenotype, 'field', 'phenotype.uniquename', $options);
-    $phenotype = tripal_core_expand_chado_vars($phenotype, 'field', 'phenotype.name', $options); 
+    $phenotype = chado_expand_var($phenotype, 'field', 'phenotype.value', $options);
+    $phenotype = chado_expand_var($phenotype, 'field', 'phenotype.uniquename', $options);
+    $phenotype = chado_expand_var($phenotype, 'field', 'phenotype.name', $options); 
     
     // get the phenotype value. If the value is qualitative the cvalue_id will link to a type. 
     // If quantitative we use the value column

+ 3 - 3
tripal_project/theme/templates/tripal_project_contact.tpl.php

@@ -3,7 +3,7 @@ $project = $variables['node']->project;
 
 // expand the project object to include the contacts from the project_contact
 // table in chado.
-$project = tripal_core_expand_chado_vars($project,'table','project_contact', array('return_array' => 1));
+$project = chado_expand_var($project,'table','project_contact', array('return_array' => 1));
 $project_contacts = $project->project_contact;
 
 if (count($project_contacts) > 0) { ?>
@@ -30,10 +30,10 @@ if (count($project_contacts) > 0) { ?>
     // Get some additional details about this contact if they exists.
     $details = '';
     $options = array('return_array' => 1);
-    $contact = tripal_core_expand_chado_vars($contact, 'table', 'contactprop', $options);
+    $contact = chado_expand_var($contact, 'table', 'contactprop', $options);
     $properties = $contact->contactprop;
     $options = array('order_by' => array('rank' => 'ASC'));
-    $properties = tripal_core_expand_chado_vars($properties, 'field', 'contactprop.value', $options);
+    $properties = chado_expand_var($properties, 'field', 'contactprop.value', $options);
     
     if (is_array($properties)) {
       foreach ($properties as $property) {

+ 2 - 2
tripal_project/theme/templates/tripal_project_properties.tpl.php

@@ -2,7 +2,7 @@
 
 // expand the project to include the properties.
 $project = $variables['node']->project;
-$project = tripal_core_expand_chado_vars($project,'table', 'projectprop', array('return_array' => 1));
+$project = chado_expand_var($project,'table', 'projectprop', array('return_array' => 1));
 $projectprops = $project->projectprop;
 
 // put the properties in an array so we can remove the project_description property
@@ -12,7 +12,7 @@ if ($projectprops) {
     // we want to keep all properties but the project_description as that
     // property is shown on the base template page.
     if($property->type_id->name != 'Project Description') {
-      $property = tripal_core_expand_chado_vars($property,'field','projectprop.value');
+      $property = chado_expand_var($property,'field','projectprop.value');
       $properties[] = $property;
     }
   }

+ 4 - 4
tripal_project/theme/templates/tripal_project_publications.tpl.php

@@ -3,7 +3,7 @@ $project = $variables['node']->project;
 
 // expand project to include pubs 
 $options = array('return_array' => 1);
-$project = tripal_core_expand_chado_vars($project, 'table', 'project_pub', $options);
+$project = chado_expand_var($project, 'table', 'project_pub', $options);
 $project_pubs = $project->project_pub; 
 
 
@@ -23,7 +23,7 @@ if (count($project_pubs) > 0) { ?>
   
   foreach ($project_pubs as $project_pub) {
     $pub = $project_pub->pub_id;
-    $pub = tripal_core_expand_chado_vars($pub, 'field', 'pub.title');
+    $pub = chado_expand_var($pub, 'field', 'pub.title');
     $citation = $pub->title;  // use the title as the default citation
     
     // get the citation for this pub if it exists
@@ -34,9 +34,9 @@ if (count($project_pubs) > 0) { ?>
       ),
     );
     $options = array('return_array' => 1);
-    $citation_prop = tripal_core_generate_chado_var('pubprop', $values, $options); 
+    $citation_prop = chado_generate_var('pubprop', $values, $options); 
     if (count($citation_prop) == 1) {
-      $citation_prop = tripal_core_expand_chado_vars($citation_prop, 'field', 'pubprop.value');
+      $citation_prop = chado_expand_var($citation_prop, 'field', 'pubprop.value');
       $citation = $citation_prop[0]->value;
     }
     

+ 3 - 3
tripal_project/theme/templates/tripal_project_relationships.tpl.php

@@ -1,12 +1,12 @@
 <?php
 /* Typically in a Tripal template, the data needed is retrieved using a call to
- * tripal_core_expand_chado_vars function.  For example, to retrieve all 
+ * chado_expand_var function.  For example, to retrieve all 
  * of the project relationships for this node, the following function call would be made:
  * 
- *   $project = tripal_core_expand_chado_vars($project,'table','project_relationship');
+ *   $project = chado_expand_var($project,'table','project_relationship');
  * 
  * However, this function call can be extremely slow when there are numerous relationships.
- * This is because the tripal_core_expand_chado_vars function is recursive and expands 
+ * This is because the chado_expand_var function is recursive and expands 
  * all data following the foreign key relationships tree.  Therefore, to speed retrieval
  * of data, a special variable is provided to this template:
  * 

+ 4 - 4
tripal_pub/theme/templates/tripal_pub_authors.tpl.php

@@ -6,7 +6,7 @@ $options = array(
   'return_array' => 1,
   'order_by' => array('rank' => 'ASC'),
 );
-$pub = tripal_core_expand_chado_vars($pub, 'table', 'pubauthor', $options);
+$pub = chado_expand_var($pub, 'table', 'pubauthor', $options);
 
 // see if we have authors as contacts if so then we'll add this resource
 $authors = $pub->pubauthor;
@@ -22,7 +22,7 @@ if (count($authors) > 0) {
         ),
       ),
     );
-    $author = tripal_core_expand_chado_vars($author, 'table', 'pubauthor_contact', $options);
+    $author = chado_expand_var($author, 'table', 'pubauthor_contact', $options);
     if ($author->pubauthor_contact) {
       $has_contacts = TRUE;
     }
@@ -53,10 +53,10 @@ if ($has_contacts) { ?>
         'type_id' => 1,       
       ),      
     );
-    $contact = tripal_core_expand_chado_vars($contact, 'table', 'contactprop', $options);
+    $contact = chado_expand_var($contact, 'table', 'contactprop', $options);
     $properties = $contact->contactprop;
     $options = array('order_by' => array('rank' => 'ASC'));
-    $properties = tripal_core_expand_chado_vars($properties, 'field', 'contactprop.value', $options); 
+    $properties = chado_expand_var($properties, 'field', 'contactprop.value', $options); 
     
     // link the contact to it's node if one exists
     $contact_name = $author->givennames . " " . $author->surname;

+ 11 - 11
tripal_pub/theme/templates/tripal_pub_base.tpl.php

@@ -15,8 +15,8 @@
 $pub = $variables['node']->pub;
 
 // expand the title
-$pub = tripal_core_expand_chado_vars($pub, 'field', 'pub.title');
-$pub = tripal_core_expand_chado_vars($pub, 'field', 'pub.volumetitle');
+$pub = chado_expand_var($pub, 'field', 'pub.title');
+$pub = chado_expand_var($pub, 'field', 'pub.volumetitle');
 
 // get the citation
 $values = array(
@@ -25,8 +25,8 @@ $values = array(
     'name' => 'Citation',
   ),
 );
-$citation = tripal_core_generate_chado_var('pubprop', $values); 
-$citation = tripal_core_expand_chado_vars($citation, 'field', 'pubprop.value');
+$citation = chado_generate_var('pubprop', $values); 
+$citation = chado_expand_var($citation, 'field', 'pubprop.value');
 
 // get the abstract
 $values = array(
@@ -35,8 +35,8 @@ $values = array(
     'name' => 'Abstract',
   ),
 );
-$abstract = tripal_core_generate_chado_var('pubprop', $values); 
-$abstract = tripal_core_expand_chado_vars($abstract, 'field', 'pubprop.value');
+$abstract = chado_generate_var('pubprop', $values); 
+$abstract = chado_expand_var($abstract, 'field', 'pubprop.value');
 $abstract_text = '';
 if ($abstract) {
   $abstract_text = htmlspecialchars($abstract->value);
@@ -49,8 +49,8 @@ $values = array(
     'name' => 'Authors',
   ),
 );
-$authors = tripal_core_generate_chado_var('pubprop', $values); 
-$authors = tripal_core_expand_chado_vars($authors, 'field', 'pubprop.value');
+$authors = chado_generate_var('pubprop', $values); 
+$authors = chado_expand_var($authors, 'field', 'pubprop.value');
 $authors_list = 'N/A';
 if ($authors) {
   $authors_list = $authors->value;
@@ -58,7 +58,7 @@ if ($authors) {
 
 // get the first database cross-reference with a url
 $options = array('return_array' => 1);
-$pub = tripal_core_expand_chado_vars($pub, 'table', 'pub_dbxref', $options);
+$pub = chado_expand_var($pub, 'table', 'pub_dbxref', $options);
 $dbxref = NULL;
 if ($pub->pub_dbxref) { 
   foreach ($pub->pub_dbxref as $index => $pub_dbxref) {
@@ -77,8 +77,8 @@ $values = array(
   ),
 );
 $options = array('return_array' => 1);
-$urls = tripal_core_generate_chado_var('pubprop', $values, $options); 
-$urls = tripal_core_expand_chado_vars($urls, 'field', 'pubprop.value');
+$urls = chado_generate_var('pubprop', $values, $options); 
+$urls = chado_expand_var($urls, 'field', 'pubprop.value');
 $url = '';
 if (count($urls) > 0) {
   $url = $urls[0]->value; 

+ 1 - 1
tripal_pub/theme/templates/tripal_pub_featuremaps.tpl.php

@@ -20,7 +20,7 @@ $options = array(
   ),
 );
 
-$pub = tripal_core_expand_chado_vars($pub, 'table', 'featuremap_pub', $options);
+$pub = chado_expand_var($pub, 'table', 'featuremap_pub', $options);
 $featuremap_pubs = $pub->featuremap_pub;
 if (count($featuremap_pubs) > 0 ) {
   foreach ($featuremap_pubs as $featuremap_pub) {    

+ 1 - 1
tripal_pub/theme/templates/tripal_pub_features.tpl.php

@@ -20,7 +20,7 @@ $options = array(
   ),
 );
 
-$pub = tripal_core_expand_chado_vars($pub, 'table', 'feature_pub', $options);
+$pub = chado_expand_var($pub, 'table', 'feature_pub', $options);
 $feature_pubs = $pub->feature_pub;
 if (count($feature_pubs) > 0 ) {
   foreach ($feature_pubs as $feature_pub) {    

+ 1 - 1
tripal_pub/theme/templates/tripal_pub_libraries.tpl.php

@@ -20,7 +20,7 @@ $options = array(
   ),
 );
 
-$pub = tripal_core_expand_chado_vars($pub, 'table', 'library_pub', $options);
+$pub = chado_expand_var($pub, 'table', 'library_pub', $options);
 $library_pubs = $pub->library_pub;
 if (count($library_pubs) > 0 ) {
   foreach ($library_pubs as $library_pub) {    

+ 1 - 1
tripal_pub/theme/templates/tripal_pub_projects.tpl.php

@@ -20,7 +20,7 @@ $options = array(
   ),
 );
 
-$pub = tripal_core_expand_chado_vars($pub, 'table', 'project_pub', $options);
+$pub = chado_expand_var($pub, 'table', 'project_pub', $options);
 $project_pubs = $pub->project_pub;
 if (count($project_pubs) > 0 ) {
   foreach ($project_pubs as $project_pub) {    

+ 2 - 2
tripal_pub/theme/templates/tripal_pub_properties.tpl.php

@@ -6,7 +6,7 @@ $options = array(
   'return_array' => 1,
   'order_by' => array('rank' => 'ASC'),
 );
-$pub = tripal_core_expand_chado_vars($pub,'table', 'pubprop', $options);
+$pub = chado_expand_var($pub,'table', 'pubprop', $options);
 $pubprops = $pub->pubprop;
 $properties = array();
 if (is_array($pubprops)) {
@@ -19,7 +19,7 @@ if (is_array($pubprops)) {
         $property->type_id->name == 'Structured Abstract Part')  {
       continue;
     }
-    $property = tripal_core_expand_chado_vars($property,'field','pubprop.value');
+    $property = chado_expand_var($property,'field','pubprop.value');
     $properties[] = $property;
   }
 }

+ 1 - 1
tripal_pub/theme/templates/tripal_pub_references.tpl.php

@@ -4,7 +4,7 @@ $pub = $variables['node']->pub;
 
 // expand the pub object to include the records from the pub_dbxref table
 $options = array('return_array' => 1);
-$pub = tripal_core_expand_chado_vars($pub, 'table', 'pub_dbxref', $options);
+$pub = chado_expand_var($pub, 'table', 'pub_dbxref', $options);
 $pub_dbxrefs = $pub->pub_dbxref;
 
 $references = array();

+ 7 - 7
tripal_pub/theme/templates/tripal_pub_relationships.tpl.php

@@ -1,12 +1,12 @@
 <?php
 /* Typically in a Tripal template, the data needed is retrieved using a call to
- * tripal_core_expand_chado_vars function.  For example, to retrieve all 
+ * chado_expand_var function.  For example, to retrieve all 
  * of the pub relationships for this node, the following function call would be made:
  * 
- *   $pub = tripal_core_expand_chado_vars($pub,'table','pub_relationship');
+ *   $pub = chado_expand_var($pub,'table','pub_relationship');
  * 
  * However, this function call can be extremely slow when there are numerous relationships.
- * This is because the tripal_core_expand_chado_vars function is recursive and expands 
+ * This is because the chado_expand_var function is recursive and expands 
  * all data following the foreign key relationships tree.  Therefore, to speed retrieval
  * of data, a special variable is provided to this template:
  * 
@@ -55,8 +55,8 @@ if (count($object_rels) > 0 or count($subject_rels) > 0) { ?>
             'name' => 'Citation',
           ),
         );
-        $citation = tripal_core_generate_chado_var('pubprop', $values);
-        $citation = tripal_core_expand_chado_vars($citation, 'field', 'pubprop.value');
+        $citation = chado_generate_var('pubprop', $values);
+        $citation = chado_expand_var($citation, 'field', 'pubprop.value');
         
         $rows[] = array(
           $title . '<br>' . htmlspecialchars($citation->value),
@@ -116,8 +116,8 @@ if (count($object_rels) > 0 or count($subject_rels) > 0) { ?>
             'name' => 'Citation',
           ),
         );
-        $citation = tripal_core_generate_chado_var('pubprop', $values);
-        $citation = tripal_core_expand_chado_vars($citation, 'field', 'pubprop.value');
+        $citation = chado_generate_var('pubprop', $values);
+        $citation = chado_expand_var($citation, 'field', 'pubprop.value');
         
         $rows[] = array(
           $title . '<br>' . htmlspecialchars($citation->value),

+ 1 - 1
tripal_pub/theme/templates/tripal_pub_stocks.tpl.php

@@ -20,7 +20,7 @@ $options = array(
   ),
 );
 
-$pub = tripal_core_expand_chado_vars($pub, 'table', 'stock_pub', $options);
+$pub = chado_expand_var($pub, 'table', 'stock_pub', $options);
 $stock_pubs = $pub->stock_pub;
 if (count($stock_pubs) > 0 ) {
   foreach ($stock_pubs as $stock_pub) {    

+ 4 - 4
tripal_pub/theme/templates/tripal_pub_teaser.tpl.php

@@ -9,8 +9,8 @@ $values = array(
     'name' => 'Citation',
   ),
 );
-$citation = tripal_core_generate_chado_var('pubprop', $values); 
-$citation = tripal_core_expand_chado_vars($citation, 'field', 'pubprop.value'); 
+$citation = chado_generate_var('pubprop', $values); 
+$citation = chado_expand_var($citation, 'field', 'pubprop.value'); 
 
 // get the abstract
 $values = array(
@@ -19,8 +19,8 @@ $values = array(
     'name' => 'Abstract',
   ),
 );
-$abstract = tripal_core_generate_chado_var('pubprop', $values); 
-$abstract = tripal_core_expand_chado_vars($abstract, 'field', 'pubprop.value');
+$abstract = chado_generate_var('pubprop', $values); 
+$abstract = chado_expand_var($abstract, 'field', 'pubprop.value');
 $abstract_text = '';
 if ($abstract) {
   $abstract_text = htmlspecialchars($abstract->value);

+ 1 - 1
tripal_stock/theme/templates/tripal_organism_stocks.tpl.php

@@ -19,7 +19,7 @@ $options = array(
   ),
 );
 
-$organism = tripal_core_expand_chado_vars($organism, 'table', 'stock', $options);
+$organism = chado_expand_var($organism, 'table', 'stock', $options);
 $stocks = $organism->stock;
 
 // get the total number of records

+ 2 - 2
tripal_stock/theme/templates/tripal_stock_base.tpl.php

@@ -4,8 +4,8 @@ $organism = $node->stock->organism_id;
 $main_db_reference = $stock->dbxref_id;
 
 // expand the text fields
-$stock = tripal_core_expand_chado_vars($stock, 'field', 'stock.description');
-$stock = tripal_core_expand_chado_vars($stock, 'field', 'stock.uniquename'); ?>
+$stock = chado_expand_var($stock, 'field', 'stock.description');
+$stock = chado_expand_var($stock, 'field', 'stock.uniquename'); ?>
 
 <div class="tripal_stock-data-block-desc tripal-data-block-desc"></div> <?php  
 

+ 1 - 1
tripal_stock/theme/templates/tripal_stock_collections.tpl.php

@@ -3,7 +3,7 @@ $stock = $variables['node']->stock;
 
 // expand the stock object to include the stockcollections associated with this stock
 $options = array('return_array' => 1);
-$stock = tripal_core_expand_chado_vars($stock, 'table', 'stockcollection_stock', $options);
+$stock = chado_expand_var($stock, 'table', 'stockcollection_stock', $options);
 $collections = $stock->stockcollection_stock;
 
 if (count($collections) > 0) {?>

+ 3 - 3
tripal_stock/theme/templates/tripal_stock_properties.tpl.php

@@ -2,7 +2,7 @@
 
 $stock = $variables['node']->stock;
 $options = array('return_array' => 1);
-$stock = tripal_core_expand_chado_vars($stock, 'table', 'stockprop', $options);
+$stock = chado_expand_var($stock, 'table', 'stockprop', $options);
 $stockprops = $stock->stockprop;
 
 // the stock synonyms are stored in the stockprop table because we do not have
@@ -14,7 +14,7 @@ if ($stockprops) {
     // we want to keep all properties but the stock_description as that
     // property is shown on the base template page.
     if($property->type_id->name != 'synonym' and  $property->type_id->name != 'alias') {
-      $property = tripal_core_expand_chado_vars($property,'field','stockprop.value');
+      $property = chado_expand_var($property,'field','stockprop.value');
       $properties[] = $property;
     }
   }
@@ -34,7 +34,7 @@ if(count($properties) > 0){
   $rows = array();
   
   foreach ($properties as $property){
-    $property = tripal_core_expand_chado_vars($property,'field','stockprop.value');
+    $property = chado_expand_var($property,'field','stockprop.value');
     $rows[] = array(
       array('data' => ucfirst(preg_replace('/_/', ' ', $property->type_id->name)), 'width' => '20%'),
       urldecode($property->value)

+ 4 - 4
tripal_stock/theme/templates/tripal_stock_publications.tpl.php

@@ -3,7 +3,7 @@ $stock = $variables['node']->stock;
 
 // expand stock to include pubs 
 $options = array('return_array' => 1);
-$stock = tripal_core_expand_chado_vars($stock, 'table', 'stock_pub', $options);
+$stock = chado_expand_var($stock, 'table', 'stock_pub', $options);
 $stock_pubs = $stock->stock_pub; 
 
 
@@ -23,7 +23,7 @@ if (count($stock_pubs) > 0) { ?>
   
   foreach ($stock_pubs as $stock_pub) {
     $pub = $stock_pub->pub_id;
-    $pub = tripal_core_expand_chado_vars($pub, 'field', 'pub.title');
+    $pub = chado_expand_var($pub, 'field', 'pub.title');
     $citation = $pub->title;  // use the title as the default citation
     
     // get the citation for this pub if it exists
@@ -34,9 +34,9 @@ if (count($stock_pubs) > 0) { ?>
       ),
     );
     $options = array('return_array' => 1);
-    $citation_prop = tripal_core_generate_chado_var('pubprop', $values, $options); 
+    $citation_prop = chado_generate_var('pubprop', $values, $options); 
     if (count($citation_prop) == 1) {
-      $citation_prop = tripal_core_expand_chado_vars($citation_prop, 'field', 'pubprop.value');
+      $citation_prop = chado_expand_var($citation_prop, 'field', 'pubprop.value');
       $citation = $citation_prop[0]->value;
     }
     

+ 1 - 1
tripal_stock/theme/templates/tripal_stock_references.tpl.php

@@ -10,7 +10,7 @@ if ($stock->dbxref_id) {
 
 // Second, expand the stock object to include the records from the stock_dbxref table
 $options = array('return_array' => 1);
-$stock = tripal_core_expand_chado_vars($stock, 'table', 'stock_dbxref', $options);
+$stock = chado_expand_var($stock, 'table', 'stock_dbxref', $options);
 $stock_dbxrefs = $stock->stock_dbxref;
 if (count($stock_dbxrefs) > 0 ) {
   foreach ($stock_dbxrefs as $stock_dbxref) {    

+ 3 - 3
tripal_stock/theme/templates/tripal_stock_relationships.tpl.php

@@ -1,12 +1,12 @@
 <?php
 /* Typically in a Tripal template, the data needed is retrieved using a call to
- * tripal_core_expand_chado_vars function.  For example, to retrieve all 
+ * chado_expand_var function.  For example, to retrieve all 
  * of the stock relationships for this node, the following function call would be made:
  * 
- *   $stock = tripal_core_expand_chado_vars($stock,'table','stock_relationship');
+ *   $stock = chado_expand_var($stock,'table','stock_relationship');
  * 
  * However, this function call can be extremely slow when there are numerous relationships.
- * This is because the tripal_core_expand_chado_vars function is recursive and expands 
+ * This is because the chado_expand_var function is recursive and expands 
  * all data following the foreign key relationships tree.  Therefore, to speed retrieval
  * of data, a special variable is provided to this template:
  * 

+ 1 - 1
tripal_stock/theme/templates/tripal_stock_synonyms.tpl.php

@@ -7,7 +7,7 @@ $synonyms = array();
 
 // expand the stock object to include the stockprop records
 $options = array('return_array' => 1);
-$stock = tripal_core_expand_chado_vars($stock, 'table', 'stockprop', $options);
+$stock = chado_expand_var($stock, 'table', 'stockprop', $options);
 $stockprops = $stock->stockprop;
 
 // iterate through all of the properties and pull out only the synonyms

+ 1 - 1
tripal_stock/theme/templates/tripal_stock_teaser.tpl.php

@@ -1,7 +1,7 @@
 <?php
 $node  = $variables['node'];
 $stock = $variables['node']->stock;
-$stock = tripal_core_expand_chado_vars($stock,'field','stock.description'); ?>
+$stock = chado_expand_var($stock,'field','stock.description'); ?>
 
 <div class="tripal_stock-teaser tripal-teaser"> 
   <div class="tripal-stock-teaser-title tripal-teaser-title"><?php