Browse Source

Fixed type in .install file for all modules. Updated tripal_genetic templates. Working on ND module

Stephen Ficklin 11 years ago
parent
commit
49527af90a
29 changed files with 768 additions and 497 deletions
  1. 1 1
      tripal_analysis/tripal_analysis.install
  2. 1 1
      tripal_bulk_loader/tripal_bulk_loader.install
  3. 1 1
      tripal_contact/tripal_contact.install
  4. 1 1
      tripal_cv/tripal_cv.install
  5. 1 1
      tripal_db/tripal_db.install
  6. 0 1
      tripal_feature/includes/tripal_feature.gff_loader.inc
  7. 1 1
      tripal_feature/tripal_feature.install
  8. 59 51
      tripal_genetic/theme/tripal_feature/tripal_feature.genotypes.tpl.php
  9. 19 14
      tripal_genetic/theme/tripal_stock/tripal_stock.genotypes.tpl.php
  10. 2 2
      tripal_genetic/tripal_genetic.module
  11. 1 1
      tripal_library/includes/tripal_library.chado_node.inc
  12. 1 1
      tripal_library/tripal_library.install
  13. 212 0
      tripal_natural_diversity/theme/tripal_feature/tripal_feature.nd_genotypes.tpl.php
  14. 0 151
      tripal_natural_diversity/theme/tripal_feature/tripal_feature_nd_genotypes.tpl.php
  15. 1 0
      tripal_natural_diversity/theme/tripal_natural_diversity.help.tpl.php
  16. 1 0
      tripal_natural_diversity/theme/tripal_natural_diversity.theme.inc
  17. 243 0
      tripal_natural_diversity/theme/tripal_stock/tripal_stock.nd_genotypes.tpl.php
  18. 160 0
      tripal_natural_diversity/theme/tripal_stock/tripal_stock.nd_phenotypes.tpl.php
  19. 0 100
      tripal_natural_diversity/theme/tripal_stock/tripal_stock_nd_genotypes.tpl.php
  20. 0 110
      tripal_natural_diversity/theme/tripal_stock/tripal_stock_nd_phenotypes.tpl.php
  21. 1 1
      tripal_natural_diversity/tripal_natural_diversity.install
  22. 28 26
      tripal_natural_diversity/tripal_natural_diversity.module
  23. 2 2
      tripal_organism/theme/tripal_organism/tripal_organism_base.tpl.php
  24. 1 1
      tripal_organism/tripal_organism.install
  25. 8 8
      tripal_organism/tripal_organism.module
  26. 1 1
      tripal_project/tripal_project.install
  27. 1 1
      tripal_pub/tripal_pub.install
  28. 1 1
      tripal_stock/tripal_stock.install
  29. 20 19
      tripal_views/tripal_views.install

+ 1 - 1
tripal_analysis/tripal_analysis.install

@@ -28,7 +28,7 @@ function tripal_analysis_requirements($phase) {
     if (!$GLOBALS["chado_is_installed"]) {
       $requirements ['tripal_analysis'] = array(
             'title' => "tripal_analysis",
-            'value' => "ERROR: Chado most be installed before this module can be enabled",
+            'value' => "ERROR: Chado must be installed before this module can be enabled",
             'severity' => REQUIREMENT_ERROR,
       );
     }

+ 1 - 1
tripal_bulk_loader/tripal_bulk_loader.install

@@ -273,7 +273,7 @@ function tripal_bulk_loader_requirements($phase) {
     if (!$GLOBALS["chado_is_installed"]) {
       $requirements ['tripal_bulk_loader'] = array(
             'title' => "tripal_bulk_loader",
-            'value' => "ERROR: Chado most be installed before this module can be enabled",
+            'value' => "ERROR: Chado must be installed before this module can be enabled",
             'severity' => REQUIREMENT_ERROR,
       );
     }

+ 1 - 1
tripal_contact/tripal_contact.install

@@ -35,7 +35,7 @@ function tripal_contact_requirements($phase) {
     if (!$GLOBALS["chado_is_installed"]) {
       $requirements ['tripal_contact'] = array(
         'title' => "tripal_contact",
-        'value' => "ERROR: Chado most be installed before this module can be enabled",
+        'value' => "ERROR: Chado must be installed before this module can be enabled",
         'severity' => REQUIREMENT_ERROR,
       );
     }

+ 1 - 1
tripal_cv/tripal_cv.install

@@ -29,7 +29,7 @@ function tripal_cv_requirements($phase) {
     if (!$GLOBALS["chado_is_installed"]) {
       $requirements ['tripal_cv'] = array(
         'title' => "tripal_cv",
-        'value' => "ERROR: Chado most be installed before this module can be enabled",
+        'value' => "ERROR: Chado must be installed before this module can be enabled",
         'severity' => REQUIREMENT_ERROR,
       );
     }

+ 1 - 1
tripal_db/tripal_db.install

@@ -29,7 +29,7 @@ function tripal_db_requirements($phase) {
     if (!$GLOBALS["chado_is_installed"]) {
       $requirements ['tripal_db'] = array(
           'title' => "tripal_db",
-          'value' => "ERROR: Chado most be installed before this module can be enabled",
+          'value' => "ERROR: Chado must be installed before this module can be enabled",
           'severity' => REQUIREMENT_ERROR,
       );
     }

+ 0 - 1
tripal_feature/includes/tripal_feature.gff_loader.inc

@@ -1288,7 +1288,6 @@ function tripal_feature_load_gff3_alias($feature, $aliases) {
     $select = array('uniquename' => 'null');
     $result = tripal_core_chado_select('pub', array('*'), $select);    
     if (count($result) == 0) {
-      // prepare the statement
       $pub_sql = "
         INSERT INTO {pub} (uniquename,type_id) 
         VALUES (:uname,

+ 1 - 1
tripal_feature/tripal_feature.install

@@ -28,7 +28,7 @@ function tripal_feature_requirements($phase) {
     if (!$GLOBALS["chado_is_installed"]) {
       $requirements ['tripal_feature'] = array(
           'title' => "t ripal_feature",
-          'value' => "ERROR: Chado most be installed before this module can be enabled",
+          'value' => "ERROR: Chado must be installed before this module can be enabled",
           'severity' => REQUIREMENT_ERROR,
       );
     }

+ 59 - 51
tripal_genetic/theme/tripal_feature/tripal_feature.genotypes.tpl.php

@@ -1,41 +1,48 @@
 <?php
 /*
- * NOTE: if the tripal_natural_diversity module is enabled this template will be
- * ignored and the tripal_feature_nd_genotypes.tpl.php template will be used instead
- *
- * There are two ways that feature genotypes can be housed in Chado.  The first, more simple
- * method, is via the feature_genotype table.  This is simply a linker table between the
- * feature and genotype tables of Chado.  A more complex method is via the Natural Diversity
- * tables.  In these tables, the genotypes are in the nd_experiment_genotype table 
- * and there may be an associated project, contact info, etc. This template is for the simple
- * feature_genotype linker table.
+ * Details about genotypes associated with features can be found in the following way:
+ * 
+ * feature => feature_genotype => genotype
+ *   
+ * There are two ways that features with genotypes can be associated with stocks.  The first, 
+ * more simple method, is by traversion the FK relationships in this manner:
+ * 
+ *   Simple Method: feature => feature_genotype => genotype => stock_genotype => stock
+ *   
+ * The second method involves use of the natural diversity tables which allows for association
+ * or more ancilliary information. Within the Natural Diversity tables, if a feature has genotypes then 
+ * you can find the corresponding stock by traversing the FK relationships 
+ * in this manner: 
+ * 
+ *   ND Method:     feature => feature_genotype => nd_experiment_genotype => nd_experiment => nd_experiment_stock => stock
+ * 
+ * The tripal_natural_diversity module handles association of stocks using the ND method.  
+ * This template handles association of stocks when stored using the simple method.
+ * If the tripal_natural_diversity module is enabled then this template will not show.
+ * You should instead see the tripal_feature.nd_genotypes.tpl.php template
+ * 
  */
 $feature = $variables['node']->feature;
 
 // specify the number of genotypes to show by default and the unique pager ID
 $num_results_per_page = 25; 
-$feature_pager_id = 7;
+$feature_pager_id = 15;
 
 // get the genotypes from the feature_genotype table
-$options = array(  
+$options = array(
   'return_array' => 1,
   'pager' => array(
-    'limit' => $num_results_per_page, 
+    'limit' => $num_results_per_page,
     'element' => $feature_pager_id
   ),
 );
 $feature = tripal_core_expand_chado_vars($feature, 'table', 'feature_genotype', $options); 
-
-// because this table has two FK constraints for the feature table, the expand function call
-// above doesn't know which one we're interested in, so it expands both the feature_id and the
-// chromosome_id and makes both available to us.  This feature can only have a genotype if
-// it matches the feature_genotype through the 'feature_id' FK (not the chromosome_id) so, we
-// retrieve our results from the 'feature_id' key.
 $feature_genotypes = $feature->feature_genotype->feature_id;
 
 // the total number of records for the paged query is stored in a session variable
 $total_records = $_SESSION['chado_pager'][$feature_pager_id]['total_records'];
 
+
 // now iterate through the feature genotypes and print a paged table.
 if (count($feature_genotypes) > 0) {?>
   <div id="tripal_feature-genotypes-box" class="tripal_feature-info-box tripal-info-box">
@@ -56,56 +63,54 @@ if (count($feature_genotypes) > 0) {?>
     foreach($feature_genotypes as $feature_genotype) {
       $genotype = $feature_genotype->genotype_id;
       
-      // get the genotype properties
-      $options = array('return_array' => 1);
-      $genotype = tripal_core_expand_chado_vars($genotype, 'table', 'genotypeprop', $options);
-      $properties = $genotype->genotypeprop; 
-      
-      // add in stocks associated with this genotype if any
-      $options = array(
-        'return_array' => 1,
-        'inlude_fk' => array(
-          'stock_id' => array(
-            'type_id' => 1
-          )
-        ),
-      );
-      $genotype = tripal_core_expand_chado_vars($genotype, 'table', 'stock_genotype', $options);
-      $stock_genotypes = $genotype->stock_genotype; 
-      
       // show the uniquename for the genotype unless a name exists
       $name = $genotype->uniquename;
       if ($genotype->name){
         $name = $genotype->name;
       }
       
-      // get the genotype type 
+      // get the genotype type
       $type = 'N/A';
       if ($genotype->type_id) {
         $type = ucwords(preg_replace('/_/', ' ', $genotype->type_id->name));
       }
       
       // get the genotype properties
+      $options = array('return_array' => 1);
+      $genotype = tripal_core_expand_chado_vars($genotype, 'table', 'genotypeprop', $options);
+      $properties = $genotype->genotypeprop; 
       $details = '';
-      if(count($properties) > 0) { 
-        foreach ($properties as $property){ 
+      if(count($properties) > 0) {
+        foreach ($properties as $property){
           $details .=  ucwords(preg_replace('/_/', ' ', $property->type_id->name)) . ': ' . $property->value . '<br>';
-        } 
+        }
         $details = substr($details, 0, -4); // remove trailing <br>
       }
+      
+      // add in stocks associated with this genotype if any
+      $options = array(
+        'return_array' => 1,
+        'inlude_fk' => array(
+          'stock_id' => array(
+            'type_id' => 1
+          )
+        ),
+      );
+      $genotype = tripal_core_expand_chado_vars($genotype, 'table', 'stock_genotype', $options);
+      $stock_genotypes = $genotype->stock_genotype; 
+
       // build the list of germplasm.
-      $germplasm = '';
+      $stock_names = '';
       if(count($stock_genotypes) > 0) { 
         foreach ($stock_genotypes as $stock_genotype){ 
           $stock = $stock_genotype->stock_id; 
-          $gname = $stock->name; 
+          $stock_name = $stock->name; 
           if(property_exists($stock, 'nid')) {
-            $gname = l($gname, 'node/' . $stock->nid, array('attributes' => array('target' => '_blank')));
-            dpm($gname);
+            $stock_name = l($stock_name, 'node/' . $stock->nid, array('attributes' => array('target' => '_blank')));
           }
-          $germplasm .= ucwords(preg_replace('/_/', ' ', $stock->type_id->name)) . ': ' . $gname . '<br>';
+          $stock_names .= ucwords(preg_replace('/_/', ' ', $stock->type_id->name)) . ': ' . $stock_name . '<br>';
         }
-        $germplasm = substr($germplasm, 0, -4); // remove trailing <br>
+        $stock_names = substr($stock_names, 0, -4); // remove trailing <br>
       } 
       // add the fields to the table row
       $rows[] = array(
@@ -113,10 +118,11 @@ if (count($feature_genotypes) > 0) {?>
         $type,
         $genotype->description,
         $details,
-        $germplasm
+        $stock_names
       );
-    } 
-        // the $table array contains the headers and rows array as well as other
+    }
+     
+    // the $table array contains the headers and rows array as well as other
     // options for controlling the display of the table.  Additional
     // documentation can be found here:
     // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
@@ -131,9 +137,10 @@ if (count($feature_genotypes) > 0) {?>
       'colgroups' => array(),
       'empty' => '',
     );
+    
     // once we have our table array structure defined, we call Drupal's theme_table()
     // function to generate the table.
-    print theme_table($table);
+    print theme_table($table); 
     
     // the $pager array values that control the behavior of the pager.  For
     // documentation on the values allows in this array see:
@@ -145,10 +152,11 @@ if (count($feature_genotypes) > 0) {?>
       'tags' => array(),
       'element' => $feature_pager_id,
       'parameters' => array(
-        'block' => 'features'
+        'block' => 'genotypes'
       ),
       'quantity' => $num_results_per_page,
     );
     print theme_pager($pager); ?>
-  </div><?php
+    
+  </div> <?php
 } 

+ 19 - 14
tripal_genetic/theme/tripal_stock/tripal_stock.genotypes.tpl.php

@@ -1,11 +1,16 @@
 <?php
 /*
- * There are two ways that stock genotypes can be housed in Chado.  The first, more simple
- * method, is via the stock_genotype table.  This is simply a linker table between the
- * stock and genotype tables of Chado.  A more complex method is via the Natural Diversity
- * tables.  In these tables, the genotypes are in the nd_experiment_genotype table 
- * and there may be an associated project, contact info, etc. This template is for the simple
- * stock_genotype linker table.
+ * Details about genotypes associated with stocks can be found in two ways by 
+ * traversing the the foreign key (FK) relationships in these ways:
+ * 
+ *   Simple Method: stock => stock_genotype => genotype
+ *   ND Method:     stock => nd_experiment_stock => nd_experiment => nd_experiment_genotype => genotype
+ *   
+ * The tripal_natural_diversity module handles display of genotypes when stored using the 
+ * ND method.  This template handles display of genotype when stored using
+ * the Simple Method.  If the tripal_natural_diversity module is enabled then this template
+ * will not show.  You should instead see the tripal_stock.nd_genotypes.tpl.php template
+ *  
  */
 $stock = $variables['node']->stock;
 
@@ -31,7 +36,7 @@ $total_records = $_SESSION['chado_pager'][$stock_pager_id]['total_records'];
 if (count($stock_genotypes) > 0) {?>
   <div id="tripal_stock-genotypes-box" class="tripal_stock-info-box tripal-info-box">
     <div class="tripal_stock-info-box-title tripal-info-box-title">Genotypes</div>
-    <div class="tripal_stock-info-box-desc tripal-info-box-desc">This following <?php print number_format($total_records) ?> genotype(s) have been recorded for this stock.</div> <?php
+    <div class="tripal_stock-info-box-desc tripal-info-box-desc">The following <?php print number_format($total_records) ?> genotype(s) have been recorded for this stock.</div> <?php
     
     // the $headers array is an array of fields to use as the colum headers.
     // additional documentation can be found here
@@ -84,8 +89,8 @@ if (count($stock_genotypes) > 0) {?>
         $details = substr($details, 0, -4); // remove trailing <br>
       }
       
-      // build the list of features.
-      $germplasm = '';
+      // build the list of marker features.
+      $markers = '';
       if(count($feature_genotypes) > 0) {
         foreach ($feature_genotypes as $feature_genotype){
           $feature = $feature_genotype->feature_id;
@@ -93,9 +98,9 @@ if (count($stock_genotypes) > 0) {?>
           if(property_exists($feature, 'nid')) {
             $fname = l($fname, 'node/' . $feature->nid, array('attributes' => array('target' => '_blank')));
           }
-          $germplasm .= ucwords(preg_replace('/_/', ' ', $feature->type_id->name)) . ': ' . $fname . '<br>';
+          $markers .= ucwords(preg_replace('/_/', ' ', $feature->type_id->name)) . ': ' . $fname . '<br>';
         }
-        $germplasm = substr($germplasm, 0, -4); // remove trailing <br>
+        $markers = substr($markers, 0, -4); // remove trailing <br>
       }
         
       // add the fields to the table row
@@ -104,7 +109,7 @@ if (count($stock_genotypes) > 0) {?>
         $type,
         $genotype->description,
         $details,
-        $germplasm
+        $markers
       );
     } 
     
@@ -135,9 +140,9 @@ if (count($stock_genotypes) > 0) {?>
     // page number we want the browser to re-appear with the page is loaded.
     $pager = array(
       'tags' => array(),
-      'element' => $feature_pager_id,
+      'element' => $stock_pager_id,
       'parameters' => array(
-        'block' => 'features'
+        'block' => 'genotypes'
       ),
       'quantity' => $num_results_per_page,
     );

+ 2 - 2
tripal_genetic/tripal_genetic.module

@@ -108,7 +108,7 @@ function tripal_genetic_node_view($node, $view_mode, $langcode) {
   if ($node->type == 'chado_feature') {
     // the tripal_natural_diversity module provides a tripal_feature_nd_genotype
     // template.  The only difference between them is the addition of
-    // project information by this ND module's template.  Therefore,
+    // project information by the ND module's template.  Therefore,
     // if the tripal_natural_diversity content is present then don't add the
     // template from this module as the ND module would superceed this.
     if ($view_mode == 'full') {
@@ -122,7 +122,7 @@ function tripal_genetic_node_view($node, $view_mode, $langcode) {
   if ($node->type == 'chado_stock') {
     // the tripal_natural_diversity module provides a tripal_stock_nd_genotype
     // template.  The only difference between them is the addition of
-    // project information by this ND module's template.  Therefore,
+    // project information by the ND module's template.  Therefore,
     // if the tripal_natural_diversity content is present then don't add the
     // template from this module as the ND module would superceed this.
     if ($view_mode == 'full') {

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

@@ -13,7 +13,7 @@ function chado_library_form($node, &$form_state) {
   // 1) as elements of the $node object.  This occurs when editing an existing library
   // 2) in the $form_state['values'] array which occurs on a failed validation or
   //    ajax callbacks from non submit form elements
-  // 3) in the $form_state['input'[ array which occurs on ajax callbacks from submit
+  // 3) in the $form_state['input'] array which occurs on ajax callbacks from submit
   //    form elements and the form is being rebuilt
   //
   // set form field defaults

+ 1 - 1
tripal_library/tripal_library.install

@@ -28,7 +28,7 @@ function tripal_library_requirements($phase) {
     if (!$GLOBALS["chado_is_installed"]) {
       $requirements ['tripal_library'] = array(
         'title' => "tripal_library",
-        'value' => "ERROR: Chado most be installed before this module can be enabled",
+        'value' => "ERROR: Chado must be installed before this module can be enabled",
         'severity' => REQUIREMENT_ERROR,
       );
     }

+ 212 - 0
tripal_natural_diversity/theme/tripal_feature/tripal_feature.nd_genotypes.tpl.php

@@ -0,0 +1,212 @@
+<?php
+/*
+ * Deatils about genotypes associated features can be found by traversing the foreign key (FK)
+ * relationships in this way
+ * 
+ * feature => feature_genotype => genotype
+ *
+ * There are two ways that features with genotypes can be associated with stocks.  The first, 
+ * more simple method, is by traversion the FK relationships in this manner:
+ * 
+ *   Simple Method: feature => feature_genotype => genotype => stock_genotype => stock
+ *   
+ * The second method involves use of the natural diversity (ND) tables which allows for association
+ * or more ancilliary information. Within the ND tables, If a feature has genotypes then 
+ * you can find the corresponding stock by traversing the FK relationships 
+ * in this manner: 
+ * 
+ *   ND MEthod: feature => feature_genotype => nd_experiment_genotype => nd_experiment => nd_experiment_stock => stock
+ * 
+ * You can find ancilliary information about data associated with a genotype in the ND tables such as
+ * a contact, pub, protocol, project, genotype, dbxref by using the 
+ * nd_experiment.nd_experiment_id value and traversing the other FK relationships
+ * 
+ * feature => feature_genotype => nd_experiment_genotype => nd_experiment => nd_experiment_stock => stock
+ *                                                                        => nd_experiment_project => project
+ *                                                                        => nd_experiment_pub => pub
+ *                                                                        => nd_experiment_contact => contact
+ *                                                                        => nd_experiment_dbxref => dbxref
+ *                                                                        => nd_experiment_protocol => protocol
+ *                                                                        => nd_experiment_stockprop
+ *                                                                        => nd_experiment_stock_dbxref
+ * 
+ * In the FK relationships shown above, the nd_experiment_id value represents a single 
+ * experimental value that may have all of the ancilliary data associated with it.  
+ * If the genotype record shares an nd_experiment_id with a genotype, pub, contact,
+ * protocol, etc then all of that data is associated with the genotype and vice-versa.
+ * 
+ * Techincally, we can skip including the 'nd_experiment' table when traversing the FK's 
+ * because we have the nd_experiment_id value when we get the nd_experiment_genotype record. 
+ * 
+ * NOTE: if the tripal_natural_diversity module is enabled this template will supercede 
+ * the tripal_feature_genotypes.tpl.php template (provided by the tripal_genetic module).
+ * Therefore, this template must handle both cases for linking to stocks as described above
+ */
+
+// get the current feature
+$feature = $variables['node']->feature;
+
+// we can have any number of genotypes for a given feature, so we want a pager.
+// specify the number of genotypes to show by default and the unique pager ID
+$num_results_per_page = 25;
+$feature_pager_id = 15;
+
+// get the genotypes from the feature_genotype table
+$options = array(
+  'return_array' => 1,
+  'pager' => array(
+    'limit' => $num_results_per_page,
+    'element' => $feature_pager_id
+  ),
+);
+$feature = tripal_core_expand_chado_vars($feature, 'table', 'feature_genotype', $options);
+$feature_genotypes = $feature->feature_genotype->feature_id;
+
+// the total number of records for the paged query is stored in a session variable
+$total_records = $_SESSION['chado_pager'][$feature_pager_id]['total_records'];
+
+// now iterate through the feature genotypes and print a paged table.
+if (count($feature_genotypes) > 0) { ?>
+  <div id="tripal_feature-nd_genotypes-box" class="tripal_feature-info-box tripal-info-box">
+    <div class="tripal_feature-info-box-title tripal-info-box-title">Genotypes</div>
+    <div class="tripal_feature-info-box-desc tripal-info-box-desc">This following <?php print number_format($total_records) ?> genotype(s) have been recorded for this feature.</div> <?php 
+
+    // the $headers array is an array of fields to use as the colum headers.
+    // additional documentation can be found here
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $headers = array('Name', 'Type', 'Genotype', 'Details', 'Germplasm', 'Project');
+
+    // the $rows array contains an array of rows where each row is an array
+    // of values for each column of the table in that row.  Additional documentation
+    // can be found here:
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $rows = array();
+    
+    foreach ($feature_genotypes as $feature_genotype) {
+      $project_names = 'N/A';
+      $stock_names   = 'N/A';
+      
+      // get the genotype from the feature_genotype record
+      $genotype = $feature_genotype->genotype_id;
+
+      // build the name for displaying the genotype. Use the uniquename by default
+      // unless a name exists
+      $name = $genotype->uniquename;
+      if ($genotype->name){
+        $name = $genotype->name;
+      }
+      
+      // build the genotype type for display
+      $type = 'N/A';
+      if ($genotype->type_id) {
+        $type = ucwords(preg_replace('/_/', ' ', $genotype->type_id->name));
+      }
+
+      // build the genotype properties
+      $options = array('return_array' => 1);
+      $genotype = tripal_core_expand_chado_vars($genotype, 'table', 'genotypeprop', $options);
+      $properties = $genotype->genotypeprop;
+      $details = '';
+      if(count($properties) > 0) {
+        foreach ($properties as $property){
+          $details .=  ucwords(preg_replace('/_/', ' ', $property->type_id->name)) . ': ' . $property->value . '<br>';
+        }
+        $details = substr($details, 0, -4); // remove trailing <br>
+      }
+
+      // 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);
+      if ($nd_experiment_genotype) {
+        $nd_experiment    = $nd_experiment_genotype->nd_experiment_id;
+        $nd_experiment_id = $nd_experiment_genotype->nd_experiment_id->nd_experiment_id;
+
+        // expand the nd_experiment object to incldue the nd_experiment_stock table
+        $values = array('nd_experiment_id' => $nd_experiment_id);
+        $options = array(
+          'return_array' => 1,
+          'include_fk' => array(
+            'stock_id' => array(
+              'type_id' => 1
+            )
+          ),
+        );
+        $nd_experiment = tripal_core_expand_chado_vars($nd_experiment, 'table', 'nd_experiment_stock', $options);
+        $nd_experiment_stocks = $nd_experiment->nd_experiment_stock;
+        if (count($nd_experiment_stocks) > 0) {
+          $stock_names = '';
+          foreach ($nd_experiment_stocks as $nd_experiment_stock) {
+            $stock = $nd_experiment_stock->stock_id;
+            $stock_name = $stock->name . ' (' . $stock->uniquename . ')';
+            if (property_exists($stock, 'nid')) {
+              $stock_name = l($stock_names, 'node/' . $stock->nid);
+            }
+            $stock_names .= $stock_name . '<br>';
+          }
+          $stock_names = substr($stock_names, 0, -4); // remove trailing <br>
+        }
+        
+        // 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_projects = $nd_experiment->nd_experiment_project;
+        if (count($nd_experiment_projects) > 0) {
+          foreach ($nd_experiment_projects as $nd_experiment_project) {
+            $project = $nd_experiment_project->project_id;
+            $name = $project->name;
+            if (property_exists($project, 'nid')) {
+              $name = l($name, "node/" . $project->nid, array('attributes' => array('target' => '_blank')));
+            }
+            $project_name .= $name . '<br>';
+          }
+          $project_name = substr($project_name, 0, -4); // remove trailing <br>
+        }
+      }
+
+      $rows[] = array(
+        $name,
+        $type,
+        $genotype->description,
+        $details,
+        $stock_names,
+        $project_name,
+      );
+    } 
+    
+    // the $table array contains the headers and rows array as well as other
+    // options for controlling the display of the table.  Additional
+    // documentation can be found here:
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $table = array(
+      'header' => $headers,
+      'rows' => $rows,
+      'attributes' => array(
+        'id' => 'tripal_natural_diversity-table-genotypes',
+      ),
+      'sticky' => FALSE,
+      'caption' => '',
+      'colgroups' => array(),
+      'empty' => '',
+    );
+    // once we have our table array structure defined, we call Drupal's theme_table()
+    // function to generate the table.
+    print theme_table($table); 
+    
+    // the $pager array values that control the behavior of the pager.  For
+    // documentation on the values allows in this array see:
+    // https://api.drupal.org/api/drupal/includes!pager.inc/function/theme_pager/7
+    // here we add the paramter 'block' => 'features'. This is because
+    // the pager is not on the default block that appears. When the user clicks a
+    // page number we want the browser to re-appear with the page is loaded.
+    $pager = array(
+      'tags' => array(),
+      'element' => $feature_pager_id,
+      'parameters' => array(
+        'block' => 'genotypes'
+      ),
+      'quantity' => $num_results_per_page,
+    );
+    print theme_pager($pager); ?>
+  </div> <?php
+}

+ 0 - 151
tripal_natural_diversity/theme/tripal_feature/tripal_feature_nd_genotypes.tpl.php

@@ -1,151 +0,0 @@
-<?php
-/*
- * NOTE: if the tripal_natural_diversity module is enabled this template will be
- * used and the tripal_feature_genotypes.tpl.php template will be ignored
- *
- * There are two ways that feature genotypes can be housed in Chado.  The first, more simple
- * method, is via the feature_genotype table.  This is simply a linker table between the
- * feature and genotype tables of Chado.  A more complex method is via the Natural Diversity
- * tables.  In these tables, the genotypes are in the nd_experiment_genotype table
- * and there may be an associated project, contact info, etc. This template is for Natural 
- * Diversity tables.
- */
-$feature = $variables['node']->feature;
-
-// specify the number of genotypes to show by default and the unique pager ID
-$num_results_per_page = 25;
-$feature_pager_id = 6;
-
-// get the genotypes from the feature_genotype table
-$options = array(
-  'return_array' => 1,
-  'pager' => array('limit' => $num_results_per_page, 'element' => $feature_pager_id),
-);
-$feature = tripal_core_expand_chado_vars($feature, 'table', 'feature_genotype', $options);
-
-// because this table has two FK constraints for the feature table, the expand function call
-// above doesn't know which one we're interested in, so it expands both the feature_id and the
-// chromosome_id and makes both available to us.  This feature can only have a genotype if
-// it matches the feature_genotype through the 'feature_id' FK (not the chromosome_id) so, we
-// retrieve our results from the 'feature_id' key.
-$feature_genotypes = $feature->feature_genotype->feature_id;
-
-// create the pager.
-$feature_pager = theme('pager', array(), $num_results_per_page, $feature_pager_id, array('block' => 'nd_genotypes'));
-
-
-// now iterate through the feature genotypes and print a paged table.
-if (count($feature_genotypes) > 0) {?>
-  <div id="tripal_feature-nd_genotypes-box" class="tripal_feature-info-box tripal-info-box">
-    <div class="tripal_feature-info-box-title tripal-info-box-title">Genotypes</div>
-    <div class="tripal_feature-info-box-desc tripal-info-box-desc">This following genotypes have been recorded for this feature.</div>
-    <table id="tripal_feature-table-feature_genotypes_exp" class="tripal_feature-table tripal-table tripal-table-horz">
-      <tr class="tripal_feature-table-odd-row tripal-table-even-row">
-        <th>Name</th>
-        <th>Type</th>
-        <th>Genotype</th>
-        <th>Details</th>
-        <th>Germplasm</th>
-        <th>Project</th>
-      </tr> <?php
-      $i = 0;
-      foreach($feature_genotypes as $feature_genotype) {
-        $class = 'tripal_feature-table-odd-row tripal-table-odd-row';
-        if($i % 2 == 0 ){
-          $class = 'tripal_feature-table-odd-row tripal-table-even-row';
-        }
-        $genotype = $feature_genotype->genotype_id;
-
-        // get the genotype properties
-        $options = array('return_array' => 1);
-        $genotype = tripal_core_expand_chado_vars($genotype, 'table', 'genotypeprop', $options);
-        $properties = $genotype->genotypeprop;
-
-        // get the experiment via the genotype:
-        $options = array(
-          'return_array' => 1,
-          'inlude_fk' => array(
-            'nd_experiment_id' => 1
-          ),
-        );
-        $values = array('genotype_id' => $genotype->genotype_id);
-        $nd_experiment_genotype = tripal_core_generate_chado_var('nd_experiment_genotype', $values);
-        $nd_experiment_genotype = tripal_core_expand_chado_vars($nd_experiment_genotype, 'table', 'nd_experiment_stock', $options);
-        $nd_experiment = $nd_experiment_genotype->nd_experiment_id;
-
-        // get the project via the experiment
-        $options = array(
-          'return_array' => 1,
-          'inlude_fk' => array(
-            'project_id' => 1
-          ),
-        );
-        $values = array('nd_experiment_id' => $nd_experiment->nd_experiment_id);
-        $nd_experiment_project = tripal_core_generate_chado_var('nd_experiment_project', $values, $options);
-
-        $nd_experiment_stock = $nd_experiment->nd_experiment_stock;
-        $nd_experiment_stock = tripal_core_expand_chado_vars($nd_experiment_stock, 'node', 'stock', $options);
-        ?>
-        <tr class="<?php print $class ?>">
-          <td><?php
-          if($genotype->name){
-             print $genotype->name;
-          }
-          else {
-             print $genotype->uniquename;
-          } ?>
-          </td>
-          <td><?php
-            // Chado versions < v1.2 did not have a type_id field
-            if ($genotype->type_id) {
-              print ucwords(preg_replace('/_/', ' ', $genotype->type_id->name));
-            }
-            else {
-              print 'N/A';
-            } ?>
-          </td>
-          <td><?php print $genotype->description ?></td>
-          <td><?php
-            if(count($properties) > 0) { ?>
-              <table class="tripal-subtable"> <?php
-                foreach ($properties as $property){ ?>
-                  <tr>
-                    <td><?php print ucwords(preg_replace('/_/', ' ', $property->type_id->name)) ?></td>
-                    <td>:</td>
-                    <td><?php print $property->value ?>
-                    </td>
-                  </tr> <?php
-                } ?>
-              </table><?php
-            } ?>
-          </td>
-          <td><?php
-            if(count($nd_experiment_stock) > 0) {
-              $name = $nd_experiment_stock->stock_id->stock->name . ' (' . $nd_experiment_stock->stock_id->stock->uniquename . ')';
-              print l($name, 'node/' . $nd_experiment_stock->stock_id->nid);
-            } ?>
-          </td>
-          <td><?php
-            if(count($nd_experiment_project) == 0) {
-              print $project->name;
-            }
-            elseif(count($nd_experiment_project) == 1) {
-              $project = $nd_experiment_project[0]->project_id;
-              if($project->nid){
-                print  l($project->name, "node/$project->nid");
-              }
-              else {
-                print $project->name;
-              }
-            }
-            elseif(count($nd_experiment_project) > 1) {
-              drupal_set_message("A feature genotype has multiple projects for the same experiment. Data warning.", 'warning');
-            } ?>
-          </td>
-        </tr> <?php
-        $i++;
-      } ?>
-    </table> <?php
-    print $feature_pager ?>
-  </div><?php
-}

+ 1 - 0
tripal_natural_diversity/theme/tripal_natural_diversity.help.tpl.php

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

+ 1 - 0
tripal_natural_diversity/theme/tripal_natural_diversity.theme.inc

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

+ 243 - 0
tripal_natural_diversity/theme/tripal_stock/tripal_stock.nd_genotypes.tpl.php

@@ -0,0 +1,243 @@
+<?php
+/*
+ * Details about genotypes associated with stocks can be found in two ways by 
+ * traversing the the foreign key (FK) relationships in these ways:
+ * 
+ *   Simple Method: stock => stock_genotype => genotype
+ *   ND Method:     stock => nd_experiment_stock => nd_experiment => nd_experiment_genotype => genotype
+ *
+ * The tripal_genetic module handles display of genotypes when stored using the 
+ * simple method.  This template handles display of genotype when stored using
+ * the ND Method.  The ND method uses the natural diversity tables and allows for 
+ * association or more ancilliary information. 
+ * 
+ * 
+ * Within the ND tables, If a stock has genotypes then you can find the corresponding 
+ * features by traversing the FK relationships in this manner: 
+ * 
+ * stock => nd_experiment_stock => nd_experiment => nd_experiment_genotype => genotype => feature_genotype => feature
+ * 
+ * You can find ancilliary information about data associated with a genotype in the ND tables such as
+ * a contact, pub, protocol, project, genotype, dbxref by using the 
+ * nd_experiment.nd_experiment_id value and traversing the other FK relationships
+ * 
+ * stock => nd_experiment_stock => nd_experiment => nd_experiment_project => project
+ *                                               => nd_experiment_pub => pub
+ *                                               => nd_experiment_contact => contact
+ *                                               => nd_experiment_dbxref => dbxref
+ *                                               => nd_experiment_protocol => protocol
+ *                                               => nd_experiment_stockprop
+ *                                               => nd_experiment_stock_dbxref
+ * 
+ * In the FK relationships shown above, the nd_experiment_id value represents a single 
+ * experimental unit that may have all of the ancilliary data associated with it or none.  
+ * If the genotype record shares an nd_experiment_id with a genotype, pub, contact,
+ * protocol, etc then all of that data is associated with the genotype and vice-versa.
+ * 
+ * Techincally, we can skip including the 'nd_experiment' table when traversing the FK's 
+ * because we have the nd_experiment_id value when we get the nd_experiment_stock record.
+ * 
+ * 
+ * NOTE: if the tripal_natural_diversity module is enabled this template will supercede 
+ * the tripal_stock_genotypes.tpl.php template (provided by the tripal_genetic module).
+ * Therefore, this template must handle both cases for linking to features as described above
+ */
+
+// get the current stock
+$stock = $variables['node']->stock;
+
+// specify the number of genotypes to show by default and the unique pager ID
+$num_results_per_page = 25;
+$stock_pager_id = 15;
+
+// get all of the nd_experiment_stock records for this stock.
+$genotypes = array();
+$values = array('stock_id' => $stock->stock_id);
+$options = array(
+  'return_array' = 1;
+  'include_fk' => array(
+    'nd_experiment_id' => 1
+  ),
+);
+$stock = tripal_core_expand_chado_vars($stock, 'table', 'nd_experiment_stock', $values, $options);
+$nd_experiment_stocks = $stock->nd_experiment_stock;
+if ($nd_experiment_stocks) {
+  
+  // iterate through the nd_experiment_stock records and look to see if there is
+  // an nd_experiment_genotype record. If so, then add it out $genotypes array
+  foreach ($nd_experiment_stock as $nd_experiment_stock) {
+    $nd_experiment_id = $nd_experiment_stock->nd_experiment_id->nd_experiment_id
+    $nd_experiment    = $nd_experiment_stock->nd_experiment_id;
+      
+    // expand the nd_experiment record to include the nd_experiment_genotype table
+    // there many be many genotypes for a stock so we want to use a pager to limit 
+    // the results returned
+    $options = array(
+      'return_array' => 1,
+      'include_fk' => array(
+        'genotype_id' => array(
+          'type_id' => 1,
+        )
+      ),
+      'pager' => array(
+        'limit' => $num_results_per_page,
+        'element' => $stock_pager_id
+      ),
+    );
+    $nd_experiment = tripal_core_expand_chado_vars($nd_experiment, 'table', 'nd_experiment_genotype', $options);
+    nd_experiment_genotypes = $nd_experiment->nd_experiment_genotype;
+    if ($nd_experiment_genotypes) {
+      // for each of the genotypes, add them to our $genotypes array so we can 
+      // display each one
+      foreach ($nd_experiment_genotypes as $nd_experiment_genotype) {
+        $genotype = $nd_experiment_genotype->genotype_id;
+        $genotypes[$genotype->genotype_id]['genotype'] = $genotype;
+        $genotypes[$genotype->genotype_id]['nd_experiment_id'] = $nd_experiment_id;
+      }
+    }
+  }
+}
+
+// the total number of records for the paged query is stored in a session variable
+$total_records = $_SESSION['chado_pager'][$stock_pager_id]['total_records'];
+
+// now iterate through the feature genotypes and print a paged table.
+if (count($genotypes) > 0) { ?>
+  <div id="tripal_feature-nd_genotypes-box" class="tripal_feature-info-box tripal-info-box">
+    <div class="tripal_feature-info-box-title tripal-info-box-title">Genotypes</div>
+    <div class="tripal_feature-info-box-desc tripal-info-box-desc">The following <?php print number_format($total_records) ?> genotype(s) have been recorded for this feature.</div> <?php 
+
+    // the $headers array is an array of fields to use as the colum headers.
+    // additional documentation can be found here
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $headers = array('Name', 'Type', 'Genotype', 'Details', 'Markers', 'Project');
+
+    // the $rows array contains an array of rows where each row is an array
+    // of values for each column of the table in that row.  Additional documentation
+    // can be found here:
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $rows = array();
+    
+    // iterate through the genotypes and build each row of the resulting table
+    foreach ($genotypes as $info) {
+      $genotype         = $info['genotype'];
+      $nd_experiment_id = $info['nd_experiment_id'];
+      
+      // set some defaults for project and feature names
+      $project_names = 'N/A';
+      $feature_names = 'N/A';
+      
+      // build the name for displaying the genotype. Use the uniquename by default
+      // unless a name exists
+      $name = $genotype->uniquename;
+      if ($genotype->name){
+        $name = $genotype->name;
+      }
+      
+      // build the genotype type for display
+      $type = 'N/A';
+      if ($genotype->type_id) {
+        $type = ucwords(preg_replace('/_/', ' ', $genotype->type_id->name));
+      }
+
+      // build the genotype properties
+      $options = array('return_array' => 1);
+      $genotype = tripal_core_expand_chado_vars($genotype, 'table', 'genotypeprop', $options);
+      $properties = $genotype->genotypeprop;
+      $details = '';
+      if(count($properties) > 0) {
+        foreach ($properties as $property){
+          $details .=  ucwords(preg_replace('/_/', ' ', $property->type_id->name)) . ': ' . $property->value . '<br>';
+        }
+        $details = substr($details, 0, -4); // remove trailing <br>
+      }
+      
+      // get the features as found in the feature_genotype table and if any, add them to the $features array
+      // we will later add in the features list for display
+      $features = array();
+      $options = array(
+        'return_array' => 1,
+        'include_fk' => array(
+          'feature_id' => array(
+            'type_id' => 1
+          )
+        ),
+      );
+      $genotype = tripal_core_expand_chado_vars($genotype, 'table', 'feature_genotype', $options);
+      $feature_genotypes = $genotype->feature_genotype;
+      if (count($feature_genotypes) > 0) {
+        foreach ($feature_genotypes as $feature_genotype) {
+          $feature = $feature_genotype->feature_id;
+          $features[$feature->feature_id] = $feature;
+          $feature_name = $feature->name . ' (' . $feature->uniquename . ')';
+          if (property_exists($feature, 'nid')) {
+            $feature_name = l($feature_names, 'node/' . $feature->nid);
+          }
+          $feature_names .= $feature_name . '<br>';
+        }
+        $feature_names = substr($feature_names, 0, -4); // remove trailing <br>
+      }
+        
+      // 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_projects = $nd_experiment->nd_experiment_project;
+      if (count($nd_experiment_projects) > 0) {
+        foreach ($nd_experiment_projects as $nd_experiment_project) {
+          $project = $nd_experiment_project->project_id;
+          $name = $project->name;
+          if (property_exists($project, 'nid')) {
+            $name = l($name, "node/" . $project->nid, array('attributes' => array('target' => '_blank')));
+          }
+          $project_name .= $name . '<br>';
+        }
+        $project_name = substr($project_name, 0, -4); // remove trailing <br>
+      }
+
+      $rows[] = array(
+        $name,
+        $type,
+        $genotype->description,
+        $details,
+        $feature_names,
+        $project_name,
+      );
+    } 
+    
+    // the $table array contains the headers and rows array as well as other
+    // options for controlling the display of the table.  Additional
+    // documentation can be found here:
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $table = array(
+      'header' => $headers,
+      'rows' => $rows,
+      'attributes' => array(
+        'id' => 'tripal_natural_diversity-table-genotypes',
+      ),
+      'sticky' => FALSE,
+      'caption' => '',
+      'colgroups' => array(),
+      'empty' => '',
+    );
+    // once we have our table array structure defined, we call Drupal's theme_table()
+    // function to generate the table.
+    print theme_table($table); 
+    
+    // the $pager array values that control the behavior of the pager.  For
+    // documentation on the values allows in this array see:
+    // https://api.drupal.org/api/drupal/includes!pager.inc/function/theme_pager/7
+    // here we add the paramter 'block' => 'features'. This is because
+    // the pager is not on the default block that appears. When the user clicks a
+    // page number we want the browser to re-appear with the page is loaded.
+    $pager = array(
+      'tags' => array(),
+      'element' => $stock_pager_id,
+      'parameters' => array(
+        'block' => 'genotypes'
+      ),
+      'quantity' => $num_results_per_page,
+    );
+    print theme_pager($pager); ?>
+  </div> <?php
+}

+ 160 - 0
tripal_natural_diversity/theme/tripal_stock/tripal_stock.nd_phenotypes.tpl.php

@@ -0,0 +1,160 @@
+<?php
+/*
+ * Phenotype relationships with stocks are stored in the natural diversity tables.
+ * If a stock has phenotypes associated then you can find the data by traversing
+ * the foreign key (FK) relationships in this manner: 
+ * 
+ * stock => nd_experiment_stock => nd_experiment => nd_experiment_phenotype => phenotype.
+ * 
+ * You can find ancillary information about data associated with a phenotype such as
+ * a contact, pub, protocol, project, genotype, dbxref by using the 
+ * nd_experiment.nd_experiment_id value and traversing the other FK relationships
+ * 
+ * stock => nd_experiment_stock => nd_experiment => nd_experiment_phenotype => phenotype
+ *                                               => nd_experiment_genotype => genotype
+ *                                               => nd_experiment_project => project
+ *                                               => nd_experiment_pub => pub
+ *                                               => nd_experiment_contact => contact
+ *                                               => nd_experiment_dbxref => dbxref
+ *                                               => nd_experiment_protocol => protocol
+ *                                               => nd_experiment_stockprop
+ *                                               => nd_experiment_stock_dbxref
+ * 
+ * In the FK relationships shown above, the nd_experiment_id value represents a single 
+ * experimental value that may have all of the ancilliary data associated with it.  
+ * If the phenotype record shares an nd_experiment_id with a genotype, pub, contact,
+ * protocol, etc then all of that data is associated with the phenotype and vice-versa.
+ * 
+ * Techincally, we can skip including the 'nd_experiment' table when traversing the FK's 
+ * because we have the nd_experiment_id value when we get the nd_experiment_stock record.
+ * 
+ */
+
+// get the current stock
+$stock = $variables['node']->stock;
+
+// expand the stock object to include the nd_experiment_stock table
+$options = array('return_array' => 1);
+$stock = tripal_core_expand_chado_vars($stock, 'table', 'nd_experiment_stock', $options);
+$nd_experiment_stocks = $stock->nd_experiment_stock;
+
+// Get the experiments to which this stock belongs that have a phenotype
+// associated.  Store those in the $phenotypes array indexed by the nd_experiment_id
+$phenotypes = array();
+if (count($nd_experiment_stocks) > 0) {
+  
+  // iterate through the nd_experiment_stock records.  there could be multiple experimetnal
+  // units (e.g. nd_experiment_id's) for this stock and we want to use only those that have
+  // phenotypes associated with them.
+  foreach ($nd_experiment_stocks as $nd_experiment_stock){
+    
+    // get the nd_experiment_id
+    $nd_experiment_id = $nd_experiment_stock->nd_experiment_id->nd_experiment_id;
+    
+    // get the nd_experiment_phenotype records for this nd_experiment_id
+    $values = array('nd_experiment_id' => $nd_experiment_id);
+    $nd_experiment_phenotypes = tripal_core_generate_chado_var('nd_experiment_phenotype', $values, $options);
+    
+    // iterate through any nd_experiment_phenotype records and add them to our array
+    if ($nd_experiment_phenotypes) {
+      foreach ($nd_experiment_phenotypes as $nd_experiment_phenotype){
+        $phenotype = $nd_experiment_phenotype->phenotype_id;
+        $phenotypes[$nd_experiment_id]['phenotype'] = $phenotype;
+      }
+    }
+  }
+}
+
+if (count($phenotypes) > 0) {?>
+  <div id="tripal_stock-phenotypes-box" class="tripal_stock-info-box tripal-info-box">
+    <div class="tripal_stock-info-box-title tripal-info-box-title">Phenotypes</div>
+    <div class="tripal_stock-info-box-desc tripal-info-box-desc">This following phenotypes have been recorded for this stock.</div><?php 
+
+    // the $headers array is an array of fields to use as the colum headers.
+    // additional documentation can be found here
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $headers = array('Phenotypes', 'Project');
+
+    // the $rows array contains an array of rows where each row is an array
+    // of values for each column of the table in that row.  Additional documentation
+    // can be found here:
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $rows = array();
+    
+    // iterate through the nd_experiment_stock records and get 
+    // each experiment and the associated phenotypes
+    foreach ($phenotypes as $nd_experiment_id => $phenotype){
+
+      $details = '';
+
+      if ($phenotype->name) { 
+        $details .= "Name: $phenotype->name<br>";
+      }
+      
+      // add in the attribute type pheonotypes values are stored qualitatively or quantitatively. 
+      // If qualitatively the cvalue_id will link to a type. If quantitative we
+      // use the value column
+      $details . = ucwords(preg_replace('/_/', ' ', $phenotype->attr_id->name)) . ': ';
+      if ($phenotype->cvalue_id) { 
+        $details .= ucwords(preg_replace('/_/', ' ', $phenotype->cvalue_id->name)) . '<br>';
+      }
+      else { 
+        $details .= $phenotype->value . '<br>';
+      }  
+      
+      // get the observable unit and add it to the details
+      if ($phenotype->observable_id) { 
+        $details .= "Observable Unit: " . ucwords(preg_replace('/_/', ' ', $phenotype->observable_id->name)) . '<br>';
+      }
+      
+      // get the evidence unit and add it to the details
+      if ($phenotype->assay_id) { 
+        $details .= "Evidence: " .  ucwords(preg_replace('/_/', ' ', $phenotype->assay_id->name)) . '<br>';
+      }
+      
+      // Get the project for this experiment. For each nd_experiment_id there should only be one project
+      // 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_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
+        $projects = $nd_experiment_project->project_id;
+      }
+      $pnames = 'N/A';
+      foreach ($projects as $project) {
+        $project = $project->project_id;
+        $name = $project->name;
+        if (property_exists($project, 'nid')) {
+          $name = l($name, "node/" . $project->nid, array('attributes' => array('target' => '_blank')));
+        }
+        $pnames .= $name . '<br>';
+      }
+      $pnames = substr($pnames, 0, -4); // remove trailing <br>
+      
+      $rows[] = array(
+         $details,
+         $pnames,
+      );
+    }
+    // the $table array contains the headers and rows array as well as other
+    // options for controlling the display of the table.  Additional
+    // documentation can be found here:
+    // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
+    $table = array(
+      'header' => $headers,
+      'rows' => $rows,
+      'attributes' => array(
+        'id' => 'tripal_natural_diversity-table-phenotypes',
+      ),
+      'sticky' => FALSE,
+      'caption' => '',
+      'colgroups' => array(),
+      'empty' => '',
+    );
+    // once we have our table array structure defined, we call Drupal's theme_table()
+    // function to generate the table.
+    print theme_table($table); ?> 
+  </div><?php
+}

+ 0 - 100
tripal_natural_diversity/theme/tripal_stock/tripal_stock_nd_genotypes.tpl.php

@@ -1,100 +0,0 @@
-<?php
-/*
- * There are two ways that stock genotypes can be housed in Chado.  The first, more simple
- * method, is via the stock_genotype table.  This is simply a linker table between the
- * stock and genotype tables of Chado.  A more complex method is via the Natural Diversity
- * tables.  In these tables, the genotypes are in the nd_experiment_genotype table
- * and there may be an associated project, contact info, etc.  This template handles
- * stocks that are stored via the ND method.
- */
-$stock = $variables['node']->stock;
-
-// specify the number of genotypes to show by default and the unique pager ID
-$num_results_per_page = 25;
-$pager_id = 500;
-
-// expand the stock object to include the nd_experiment_stock table
-$options = array(
-  'return_array' => 1,
-  'pager' => array (
-    'limit' => $num_results_per_page,
-    'element' => $pager_id,
-  ),
-);
-$stock = tripal_core_expand_chado_vars($stock, 'table', 'nd_experiment_stock', $options);
-$nd_experiment_stocks = $stock->nd_experiment_stock;
-
-// create the pager.  
-global $pager_total_items;
-$pager = theme('pager', array(), $num_results_per_page, $pager_id, array('block' => 'nd_genotypes'));
-$total_features = $pager_total_items[$pager_id];
-
-
-// now iterate through the experiments and create a paged table for each experiment
-if (count($nd_experiment_stocks) > 0) {?>
-  <div id="tripal_stock-nd_genotypes-box" class="tripal_stock-info-box tripal-info-box">
-    <div class="tripal_stock-info-box-title tripal-info-box-title">Genotypes</div>
-    <div class="tripal_stock-info-box-desc tripal-info-box-desc">This <?php print $stock->type_id->name ?> has <?php print number_format($total_features) ?> associated genotypes: </div>
-
-    <table id="tripal_stock-table-nd_stock_genotypes" class="tripal_stock-table tripal-table tripal-table-horz">
-        <tr class="tripal_stock-table-odd-row tripal-table-even-row">
-          <th>Project</th>
-          <th>Marker (Type)</th>
-          <th>Details</th>
-        </tr>
-
-    <?php
-    foreach ($nd_experiment_stocks as $nd_experiment_stock) {
-
-      // get the nd experiment
-      $values = array('nd_experiment_id' => $nd_experiment_stock->nd_experiment_id->nd_experiment_id);
-      $options = array('include_fk' => array('nd_geolocation_id' => 1)); 
-      $nd_experiment = tripal_core_generate_chado_var('nd_experiment', $values, $options);
- 
-      // add in the project
-      $options = array('include_fk' => array('project_id' => 1)); 
-      $nd_experiment = tripal_core_expand_chado_vars($nd_experiment, 'table', 'nd_experiment_project', $options);
-      $project = $nd_experiment->nd_experiment_project->project_id;
-
-      // add in the nd_experiment_genotype table
-      $options = array('include_fk' => array('genotype_id' => 1)); 
-      $nd_experiment = tripal_core_expand_chado_vars($nd_experiment, 'table', 'nd_experiment_genotype', $options);
-
-      // add in the feature_genotype table
-      $genotype = $nd_experiment->nd_experiment_genotype->genotype_id;
-      $options = array('include_fk' => array('feature_id' => array('type_id' => 1))); 
-      $genotype = tripal_core_expand_chado_vars($genotype, 'table', 'feature_genotype', $options);
-
-      // add in the node for the feature
-      $marker = $genotype->feature_genotype->feature_id;
-      $marker = tripal_core_expand_chado_vars($marker, 'node', 'feature'); ?>
-      <tr class="tripal_stock-table-odd-row tripal-table-even-row">
-        <td><?php 
-          if ($project->nid) {
-            print l($project->name, 'node/' . $project->nid);
-          }
-          else {
-            print $project->name; 
-          } ?>
-        </td>
-        <td><?php
-          if ($marker->name != $marker->uniquename) {
-            $name = $marker->name . ', ' . $marker->uniquename . ' (' . $marker->type_id->name . ')';
-          } 
-          else {
-            $name = $marker->name . ' (' . $marker->type_id->name . ')';
-          }
-          if ($marker->nid) {
-            print l($name, 'node/' . $marker->nid);
-          }
-          else {         
-            print $name;
-          } ?>
-        </td>
-        <td><?php print $genotype->description; ?></td>
-      </tr> <?php
-    }?>
-  </table> <?php
-  print $pager; ?>
-  </div><?php
-}

+ 0 - 110
tripal_natural_diversity/theme/tripal_stock/tripal_stock_nd_phenotypes.tpl.php

@@ -1,110 +0,0 @@
-<?php
-$stock = $variables['node']->stock;
-
-// expand the stock object to include the nd_experiment_stock table
-$options = array('return_array' => 1);
-$stock = tripal_core_expand_chado_vars($stock, 'table', 'nd_experiment_stock', $options);
-$nd_experiment_stocks = $stock->nd_experiment_stock;
-
-// Get the experiments to which this stock belongs that have a phenotype
-// associated.  Store those in the phenotypes array indexed by the experiment_id
-$all_phenotypes = array();
-if (count($nd_experiment_stocks) > 0) {
-  foreach ($nd_experiment_stocks as $nd_experiment_stock){      
-    $values = array('nd_experiment_id' => $nd_experiment_stock->nd_experiment_id->nd_experiment_id);
-    $nd_experiment_phenotypes = tripal_core_generate_chado_var('nd_experiment_phenotype', $values, $options);
-    if ($nd_experiment_phenotypes) {
-    	foreach ($nd_experiment_phenotypes as $nd_exp_phenotype){
-        $phenotype = $nd_exp_phenotype->phenotype_id;
-        $all_phenotypes[$nd_experiment_stock->nd_experiment_id->nd_experiment_id][] = $phenotype;
-    	}
-    }
-  }
-}
-if (count($all_phenotypes) > 0) {?>
-  <div id="tripal_stock-phenotypes-box" class="tripal_stock-info-box tripal-info-box">
-    <div class="tripal_stock-info-box-title tripal-info-box-title">Phenotypes</div>
-    <div class="tripal_stock-info-box-desc tripal-info-box-desc">This following phenotypes have been recorded for this stock.</div>
- 
-    <table id="tripal_stock-table-phenotypes_exp" class="tripal_stock-table tripal-table tripal-table-horz">     
-      <tr class="tripal_stock-table-odd-row tripal-table-even-row">
-        <th>Phenotypes</th>
-        <th>Project</th>
-      </tr> <?php
-      
-      // iterate through the nd_experiment_stock records and get 
-      // each experiment and the associated phenotypes
-      foreach ($nd_experiment_stocks as $nd_experiment_stock){      
-        // Get the project for this experiment. For each nd_experiment_id there can only be one project
-        $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);
-        $project = $nd_experiment_project[0]->project_id;
-
-        // get the phenotypes
-        $phenotypes = $all_phenotypes[$nd_experiment_stock->nd_experiment_id->nd_experiment_id];
-        if(!$phenotypes){
-          $phenotypes = array();
-        }
-                
-        $class = 'tripal_stock-table-odd-row tripal-table-odd-row';
-        if($i % 2 == 0 ){
-          $class = 'tripal_stock-table-odd-row tripal-table-even-row';
-        } ?>
-        <tr class="<?php print $class ?>">
-          <td>           
-            <table class="tripal-subtable"> <?php
-              foreach ($phenotypes as $phenotype){
-                if ($phenotype->name) { ?>
-	                <tr> 
-	                  <td>Name</td>
-	                  <td>:</td>
-	                  <td><?php print $phenotype->name ?></td>
-	                </tr> <?php 
-                }?>
-                <tr> 
-                  <td><?php print ucwords(preg_replace('/_/', ' ', $phenotype->attr_id->name)) ?></td>
-                  <td>:</td>                  
-                  <td><?php 
-	                  // pheonotypes values are stored qualitatively or quantitatively.  If
-	                  // qualitatively the cvalue_id will link to a type. If quantitative we
-	                  // us ethe value column                  
-	                  if ($phenotype->cvalue_id) { 
-	                  	print ucwords(preg_replace('/_/', ' ', $phenotype->cvalue_id->name));
-	                  }
-	                  else { 
-	                    print $phenotype->value;
-	                  } ?>
-                  </td>
-                </tr> <?php 
-                if ($phenotype->observable_id) { ?>
-	                <tr>
-	                  <td>Observable Unit</td>
-	                  <td>:</td>
-	                  <td><?php print ucwords(preg_replace('/_/', ' ', $phenotype->observable_id->name)) ?></td>
-	                </tr> <?php 
-                }
-                if ($phenotype->assay_id) { ?>
-	                <tr>
-	                  <td>Evidence</td>
-	                  <td>:</td>
-	                  <td><?php print ucwords(preg_replace('/_/', ' ', $phenotype->assay_id->name)) ?></td>
-	                </tr><?php
-                }
-              } ?>
-            </table>
-          </td>
-          <td><?php 
-            if($project->nid){    
-              $link =  url("node/$project->name");        
-              print "<a href=\"$link\">$project->name</a>";
-            } 
-            else {
-              print $project->name;
-            } ?>
-          </td>
-        </tr> <?php
-        $i++; 
-      }?>  
-    </table> 
-  </div><?php
-}

+ 1 - 1
tripal_natural_diversity/tripal_natural_diversity.install

@@ -28,7 +28,7 @@ function tripal_natural_diversity_requirements($phase) {
     if (!$GLOBALS["chado_is_installed"]) {
       $requirements ['tripal_natural_diversity'] = array(
         'title' => "tripal_natural_diversity",
-        'value' => "ERROR: Chado most be installed before this module can be enabled",
+        'value' => "ERROR: Chado must be installed before this module can be enabled",
         'severity' => REQUIREMENT_ERROR,
       );
     }

+ 28 - 26
tripal_natural_diversity/tripal_natural_diversity.module

@@ -1,6 +1,7 @@
 <?php
 
 require_once('api/tripal_natural_diversity.api.inc');
+require_once('theme/tripal_natural_diversity.theme.inc');
 require_once('includes/tripal_natural_diversity.schema.inc');
 require_once('includes/tripal_natural_diversity.admin.inc');
 /**
@@ -35,13 +36,13 @@ function tripal_natural_diversity_menu() {
   );
 
   $items['admin/tripal/chado/tripal_natdiv/help'] = array(
-   'title' => 'Help',
-   'description' => "A description of the Tripal natural_diversity module including a short description of it's usage.",
-   'page callback' => 'theme',
-   'page arguments' => array('tripal_natdiv_help'),
-   'access arguments' => array('adminster tripal natural_diversity'),
-   'type' => MENU_LOCAL_TASK,
-   'weight' => 10
+    'title' => 'Help',
+    'description' => ('Help for the Tripal natural diversity module.'),
+    'page callback' => 'theme',
+    'page arguments' => array('tripal_natural_diversity_help'),
+    'access arguments' => array('administer tripal natual_diversity'),
+    'type' => MENU_LOCAL_TASK,
+    'weight' => 10
   );
 
   $items['admin/tripal/chado/tripal_natdiv/views/natdiv_exp/enable'] = array(
@@ -74,30 +75,31 @@ function tripal_natural_diversity_views_api() {
  *
  * @ingroup tripal_natural_diversity
  */
-function tripal_natural_diversity_theme() {
-  $theme_path = drupal_get_path('module', 'tripal_natural_diversity') . '/theme';
+function tripal_natural_diversity_theme($existing, $type, $theme, $path) {
+  $core_path = drupal_get_path('module', 'tripal_core');
+  
   $items = array(
     // tripal_feature templates
     'tripal_feature_nd_genotypes' => array(
-      'arguments' => array('node' => NULL),
-      'template' => 'tripal_feature_nd_genotypes',
-      'path' => "$theme_path/tripal_feature",
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_feature.nd_genotypes',
+      'path' => "$path/theme/tripal_feature",
     ),
     // tripal_stock templates
     'tripal_stock_nd_genotypes' => array(
-      'arguments' => array('node' => NULL),
-      'template' => 'tripal_stock_nd_genotypes',
-      'path' => "$theme_path/tripal_stock",
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_stock.nd_genotypes',
+      'path' => "$path/theme/tripal_stock",
     ),
     'tripal_stock_nd_phenotypes' => array(
-      'arguments' => array('node' => NULL),
-      'template' => 'tripal_stock_nd_phenotypes',
-      'path' => "$theme_path/tripal_stock",
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_stock.nd_phenotypes',
+      'path' => "$path/theme/tripal_stock",
     ),
-    'tripal_natdiv_help' => array(
-      'template' => 'tripal_natdiv_help',
+    'tripal_natural_diversity_help' => array(
+      'template' => 'tripal_natural_diversity.help',
       'variables' =>  array(NULL),
-      'path' => "$theme_path",
+      'path' => "$path/theme",
     ),
   );
   return $items;
@@ -151,29 +153,29 @@ function tripal_natural_diversity_block_view($delta = '') {
  *
  * @ingroup tripal_natural_diversity
  */
-function tripal_natural_diversity_node_view(&$node, $view_mode, $langcode) {
+function tripal_natural_diversity_node_view($node, $view_mode, $langcode) {
     if ($node->type == 'chado_feature') {
       // the tripal_genetic module provides a tripal_feature_genotype
       // template.  The only difference between them is the addition of
       // project information by this module's template.  Therefore,
-      // if the tripal_genetic content is present get rid of as this
+      // if the tripal_genetic content is present get rid of it as this
       // module superceeds it.
       if ($view_mode == 'full') {
         if (array_key_exists('tripal_feature_genotypes', $node->content)) {
           unset($node->content['tripal_feature_genotypes']);
         }
         $node->content['tripal_feature_nd_genotypes'] = array(
-           '#value' => theme('tripal_feature_nd_genotypes', $node),
+           '#value' => theme('tripal_feature_nd_genotypes', array('node' => $node)),
         );
       }
     }
     if ($node->type == 'chado_stock') {
       if ($view_mode == 'full') {
         $node->content['tripal_stock_nd_genotypes'] = array(
-           '#value' => theme('tripal_stock_nd_genotypes', $node),
+           '#value' => theme('tripal_stock_nd_genotypes', array('node' => $node)),
         );
         $node->content['tripal_stock_nd_phenotypes'] = array(
-           '#value' => theme('tripal_stock_nd_phenotypes', $node),
+           '#value' => theme('tripal_stock_nd_phenotypes', array('node' => $node)),
         );
       }
     }

+ 2 - 2
tripal_organism/theme/tripal_organism/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 = tripal_core_expand_chado_vars($organism,'field','organism.comment'); ?>
+
 <div id="tripal_organism-base-box" class="tripal_organism-info-box tripal-info-box">
   <div class="tripal_organism-info-box-title tripal-info-box-title">Details</div>
   <!--  <div class="tripal_organism-info-box-desc tripal-info-box-desc"></div> --><?php      

+ 1 - 1
tripal_organism/tripal_organism.install

@@ -91,7 +91,7 @@ function tripal_organism_requirements($phase) {
     if (!$GLOBALS["chado_is_installed"]) {
       $requirements ['tripal_organism'] = array(
             'title' => "tripal_organism",
-            'value' => "ERROR: Chado most be installed before this module can be enabled",
+            'value' => "ERROR: Chado must be installed before this module can be enabled",
             'severity' => REQUIREMENT_ERROR,
       );
     }

+ 8 - 8
tripal_organism/tripal_organism.module

@@ -221,14 +221,14 @@ function tripal_organism_node_presave($node) {
  */
 function tripal_organism_node_view($node, $view_mode, $langcode) {
   switch ($node->type) {
-  	case 'chado_organism':
-  	  // Show feature browser and counts
-  	  if ($view_mode == 'full') {
-  	    $node->content['tripal_organism_base'] = array(
-  	      '#value' => theme('tripal_organism_base', array('node' => $node)),
-  	    );
-  	  }
-  	  if ($view_mode == 'teaser') {
+    case 'chado_organism':
+      // Show feature browser and counts
+      if ($view_mode == 'full') {
+        $node->content['tripal_organism_base'] = array(
+          '#value' => theme('tripal_organism_base', array('node' => $node)),
+        );
+      }
+      if ($view_mode == 'teaser') {
         $node->content['tripal_organism_teaser'] = array(
           '#value' => theme('tripal_organism_teaser', array('node' => $node)),
         );

+ 1 - 1
tripal_project/tripal_project.install

@@ -35,7 +35,7 @@ function tripal_project_requirements($phase) {
     if (!$GLOBALS["chado_is_installed"]) {
       $requirements ['tripal_project'] = array(
         'title' => "tripal_project",
-        'value' => "ERROR: Chado most be installed before this module can be enabled",
+        'value' => "ERROR: Chado must be installed before this module can be enabled",
         'severity' => REQUIREMENT_ERROR,
       );
     }

+ 1 - 1
tripal_pub/tripal_pub.install

@@ -34,7 +34,7 @@ function tripal_pub_requirements($phase) {
     if (!$GLOBALS["chado_is_installed"]) {
       $requirements ['tripal_pub'] = array(
         'title' => "tripal_pub",
-        'value' => "ERROR: Chado most be installed before this module can be enabled",
+        'value' => "ERROR: Chado must be installed before this module can be enabled",
         'severity' => REQUIREMENT_ERROR,
       );
     }

+ 1 - 1
tripal_stock/tripal_stock.install

@@ -31,7 +31,7 @@ function tripal_stock_requirements($phase) {
     if (!$GLOBALS["chado_is_installed"]) {
       $requirements ['tripal_stock'] = array(
         'title' => "tripal_stock",
-        'value' => "ERROR: Chado most be installed before this module can be enabled",
+        'value' => "ERROR: Chado must be installed before this module can be enabled",
         'severity' => REQUIREMENT_ERROR,
       );
     }

+ 20 - 19
tripal_views/tripal_views.install

@@ -5,6 +5,26 @@
  * Functions related to installing/uninstalling this module
  */
 
+
+/**
+ * Implementation of hook_requirements().
+ *
+ */
+function tripal_views_requirements($phase) {
+  $requirements = array();
+  if ($phase == 'install') {
+    // make sure chado is installed
+    if (!$GLOBALS["chado_is_installed"]) {
+      $requirements ['tripal_views'] = array(
+        'title' => "tripal_views",
+        'value' => "ERROR: Chado must be installed before this module can be enabled",
+        'severity' => REQUIREMENT_ERROR,
+      );
+    }
+  }
+  return $requirements;
+}
+
 /**
  * Implementation of hook_install().
  *
@@ -372,22 +392,3 @@ function tripal_views_views_schema() {
 
   return $schema;
 }
-/**
- * Implementation of hook_requirements().
- *
- */
-function tripal_views_requirements($phase) {
-  $requirements = array();
-  if ($phase == 'install') {
-    // make sure chado is installed
-    $version = tripal_get_set_chado_version(TRUE);
-    if ($version == 'not installed') {
-      $requirements ['tripal_views'] = array(
-            'title' => "tripal_views",
-            'value' => "ERROR: Chado most be installed before this module can be enabled",
-            'severity' => REQUIREMENT_ERROR,
-      );
-    }
-  }
-  return $requirements;
-}