Browse Source

Genetic module finished (needs testing still) and comments to references API

Stephen Ficklin 11 years ago
parent
commit
ec2869d74d

+ 48 - 11
tripal_core/api/tripal_core.database_references.api.inc

@@ -121,6 +121,7 @@ function tripal_core_additional_dbxrefs_form(&$form, &$form_state, $details) {
   $details['fieldset_title'] = 'Additional Database References';
   $details['additional_instructions'] = '';
 
+  // the fieldset of the dbxref elements
   $form['addtl_dbxrefs'] = array(
     '#type' => 'fieldset',
     '#title' => t($details['fieldset_title']),
@@ -131,7 +132,9 @@ function tripal_core_additional_dbxrefs_form(&$form, &$form_state, $details) {
     '#prefix' => "<div id='addtl-dbxrefs-fieldset'>",
     '#suffix' => '</div>'
   );
-
+  
+  // this form element is a tree, so that we don't puke all of the values into then node variable
+  // it is set as a tree, and keeps them in the $form_state['values']['dbxref_table'] heading.
   $form['addtl_dbxrefs']['dbxref_table'] = array(
     '#type' => 'markup',
     '#tree' => TRUE,
@@ -139,9 +142,17 @@ function tripal_core_additional_dbxrefs_form(&$form, &$form_state, $details) {
     '#suffix' => '</div>',
     '#theme' => 'tripal_core_additional_dbxrefs_form_table'
   );
-
-  // Add dbxrefs already attached to the node
-  //---------------------------------------------
+  
+  /* DBxrefs can come to us in two ways:
+   * 
+   * 1) In the form state in the $form_state['addtl_dbxrefs']. Data is in this field
+   *    when an AJAX call updates the form state or a validation error.
+   *     
+   * 2) Directly from the database if the record already has dbxref's associated.  This
+   *    data is only used the first time the form is loaded. On AJAX calls or validation
+   *    errors the fields on the form are populated from the $form_state['addtl_dbxrefs']
+   *    entry.
+   */ 
   if (isset($form_state['addtl_dbxrefs'])) {
     $existing_dbxrefs = $form_state['addtl_dbxrefs'];
   }
@@ -151,11 +162,27 @@ function tripal_core_additional_dbxrefs_form(&$form, &$form_state, $details) {
         FROM {dbxref} dbxref
         LEFT JOIN {db} db ON db.db_id = dbxref.db_id
         LEFT JOIN {".$details['linking_table']."} linking_table ON linking_table.dbxref_id = dbxref.dbxref_id
-        WHERE linking_table.".$details['base_foreign_key']."= :base_key_value
-        ORDER BY db.name ASC, dbxref.version ASC",
-        array(':base_key_value' => $details['base_key_value'])
+       WHERE linking_table.".$details['base_foreign_key']."= :base_key_value
+       ORDER BY db.name ASC, dbxref.version ASC",
+       array(':base_key_value' => $details['base_key_value'])
     );
   }
+  
+  /* The format of the $existing_dbxref's array is
+   * 
+   * $existing_dbxrefs = array(
+   *   '[db_id]-[version]' => array(
+   *     'db_id' => [the db.db_id value]
+   *     'db_name' => [the db.name value]
+   *     'dbxref_id' => [the dbxref.dbxref_id value, or NULL if it doesn't yet exists],
+   *     'version' => [the dbxref.version value],
+   *     'accession' => [the dbxref.accession value],
+   *   ),
+   * );
+   * 
+   * loop on the array elements of the $existing_dbxrefs array and add
+   * an element to the form for each one.
+   */ 
   foreach ($existing_dbxrefs as $dbxref) {
 
     $version = (!empty($dbxref->version)) ? $dbxref->version : 'NONE';
@@ -199,7 +226,7 @@ function tripal_core_additional_dbxrefs_form(&$form, &$form_state, $details) {
       '#type' => 'markup',
       '#markup' => $dbxref->accession
     );
-
+    // remove button
     $form['addtl_dbxrefs']['dbxref_table'][$dbxref->db_id][$version]['dbxref_action'] = array(
       '#type' => 'submit',
       '#value' => t('Remove'),
@@ -223,9 +250,10 @@ function tripal_core_additional_dbxrefs_form(&$form, &$form_state, $details) {
     '#prefix' => '<span class="addtl-dbxrefs-add-new-dbxref">',
     '#suffix' => '</span>'
   );
-
+ 
+  // add in the existing databases
   $db_options = array(0 => 'Select a Database');
-  $select = tripal_core_chado_select('db',array('db_id','name'),array());
+  $select = tripal_core_chado_select('db', array('db_id','name'), array(), array('order_by' => array('name' => 'ASC')));
   foreach($select as $db) {
     $db_options[$db->db_id] = $db->name;
   }
@@ -242,6 +270,7 @@ function tripal_core_additional_dbxrefs_form(&$form, &$form_state, $details) {
     '#type' => 'textfield',
   );
 
+  // add button
   $form['addtl_dbxrefs']['dbxref_table']['new']['dbxref_action'] = array(
     '#type' => 'submit',
     '#value' => t('Add'),
@@ -253,6 +282,13 @@ function tripal_core_additional_dbxrefs_form(&$form, &$form_state, $details) {
       '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 form submit.  In the validate function we set the form_state
+    // to rebuild the form so the node form submit function never actually gets called,
+    // but we need it or Drupal will run the default validate anyway.
+    // we also set #limit_validation_errors to empty so fields that
+    // are required that don't have values won't generate warnings.
     '#validate' => array('tripal_core_additional_dbxrefs_form_add_button_validate'),
     '#submit' => array('tripal_core_additional_dbxrefs_form_add_button_submit'),
   );
@@ -282,7 +318,6 @@ function tripal_core_additional_dbxrefs_form_add_button_validate($form, &$form_s
   if (empty($form_state['input']['dbxref_table']['new']['dbxref_accession'])) {
     form_set_error('dbxref_accession','You must enter the accession before attempting to add a new database reference.');
   }
-
 }
 
 /**
@@ -355,6 +390,8 @@ function tripal_core_additional_dbxrefs_form_ajax_update($form, $form_state) {
 /**
  * Creates an array in form_state containing the existing addtl_dbxrefs. This array is
  * then modified by the add/remove buttons and used as a source for rebuilding the form.
+ * This function get's called at each button (add and remove) button submits the first
+ * time one of the button's is clicked to instantiates the $form_state['addtl_dbxrefs'] array
  */
 function tripal_core_additional_dbxrefs_form_create_dbxref_formstate_array($form, &$form_state) {
 

+ 2 - 2
tripal_core/api/tripal_core_properties.api.inc

@@ -799,8 +799,8 @@ function tripal_core_properties_form_add_new_props(&$form, &$form_state, &$ranks
 
   // second add in any new properties added during this callback
   if (array_key_exists('triggering_element', $form_state) and
-  $form_state['triggering_element']['#name'] == 'add' and
-  $form_state['input']['new_id'] != 0) {
+    $form_state['triggering_element']['#name'] == 'add' and
+    $form_state['input']['new_id'] != 0) {
     $new_id    = $form_state['input']['new_id'];
     $new_value = $form_state['input']['new_value'];
 

+ 151 - 0
tripal_genetic/theme/tripal_feature/tripal_feature.genotypes.tpl.php

@@ -0,0 +1,151 @@
+<?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.
+ */
+$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;
+
+// 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;
+
+// the total number of records for the paged query is stored in a session variable
+$total_records = $_SESSION['chado_pager'][$element]['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">
+    <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');
+
+    // 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) {
+      $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 
+      $type = 'N/A';
+      if ($genotype->type_id) {
+        $type = ucwords(preg_replace('/_/', ' ', $genotype->type_id->name));
+      }
+      
+      // get the genotype properties
+      $details = '';
+      if(count($properties) > 0) { 
+        foreach ($properties as $property){ 
+          $details .=  '<br>' . ucwords(preg_replace('/_/', ' ', $property->type_id->name)) . ': ' . $property->value;
+        } 
+      }
+      // build the list of germplasm.
+      $germplasm = '';
+      if(count($stock_genotypes) > 0) { 
+        foreach ($stock_genotypes as $stock_genotype){ 
+          $stock = $stock_genotype->stock_id; 
+          $gname = $stock->name; 
+          if(property_exists($stock, 'nid')) {
+            $gname = l($gname, 'node/' . $stock->nid, array('attributes' => array('target' => '_blank')));
+          }
+          $germplasm .= '<br>' . ucwords(preg_replace('/_/', ' ', $stock->type_id->name)) . ': ' . $gname;
+        }
+      } 
+      // add the fields to the table row
+      $rows[] = array(
+        $name,
+        $type,
+        $genotype->description,
+        $details,
+        $germplasm
+      );
+    } 
+        // 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_genetic-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' => 'features'
+      ),
+      'quantity' => $num_results_per_page,
+    );
+    print theme_pager($pager); ?>
+  </div><?php
+} 

+ 0 - 134
tripal_genetic/theme/tripal_feature/tripal_feature_genotypes.tpl.php

@@ -1,134 +0,0 @@
-<?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.
- */
-$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 = 5;
-
-// 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' => 'genotypes'));
-
-
-// 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">
-    <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>
-      </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; 
-        
-        // 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; ?>
-        <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($stock_genotypes) > 0) { ?>                      
-              <table class="tripal-subtable"> <?php
-                foreach ($stock_genotypes as $stock_genotype){ 
-                  $stock = $stock_genotype->stock_id; ?>
-                  <tr> 
-                    <td><?php print ucwords(preg_replace('/_/', ' ', $stock->type_id->name)) ?></td>
-                    <td>:</td>                  
-                    <td><?php 
-                      if($stock->nid) {
-                        print l($stock->name, 'node/' . $stock->nid);
-                      }
-                      else {
-                        print $stock->name;
-                      }?>
-                    </td>
-                  </tr> <?php                 
-                } ?>
-              </table><?php 
-            } ?>
-          </td>
-        </tr> <?php
-        $i++;
-      } ?>  
-    </table> <?php 
-    print $feature_pager ?>
-  </div><?php
-} 

+ 0 - 0
tripal_genetic/theme/tripal_genetic_help.tpl.php → tripal_genetic/theme/tripal_genetic.help.tpl.php


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

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

+ 144 - 0
tripal_genetic/theme/tripal_stock/tripal_stock.genotypes.tpl.php

@@ -0,0 +1,144 @@
+<?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.
+ */
+$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 = 0;
+
+// get the genotypes from the stock_genotype table
+$options = array(
+  'return_array' => 1, 
+  'pager' => array(
+    'limit' => $num_results_per_page, 
+    'element' => $stock_pager_id
+  ),
+);
+$stock = tripal_core_expand_chado_vars($stock, 'table', 'stock_genotype', $options); 
+$stock_genotypes = $stock->stock_genotype;
+
+// the total number of records for the paged query is stored in a session variable
+$total_records = $_SESSION['chado_pager'][$element]['total_records'];
+
+// now iterate through the stock genotypes and print a paged table.
+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
+    
+    // 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');
+    
+    // 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($stock_genotypes as $stock_genotype) {       
+      $genotype = $stock_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 markers associated with this genotype if any
+      $options = array(
+        'return_array' => 1,
+        'inlude_fk' => array(
+          'feature_id' => array(
+            'type_id' => 1
+          )
+        ),
+      );
+      $genotype = tripal_core_expand_chado_vars($genotype, 'table', 'feature_genotype', $options);
+      $feature_genotypes = $genotype->feature_genotype; 
+      
+      // show the uniquename for the genotype unless a name exists
+      $name = $genotype->uniquename;
+      if ($genotype->name){
+        $name = $genotype->name;
+      }
+      // get the genotype type
+      $type = 'N/A';
+      if ($genotype->type_id) {
+        $type = ucwords(preg_replace('/_/', ' ', $genotype->type_id->name));
+      }
+      
+      // get the genotype properties
+      $details = '';
+      if(count($properties) > 0) {
+        foreach ($properties as $property){
+          $details .=  '<br>' . ucwords(preg_replace('/_/', ' ', $property->type_id->name)) . ': ' . $property->value;
+        }
+      }
+      
+      // build the list of features.
+      $germplasm = '';
+      if(count($feature_genotypes) > 0) {
+        foreach ($feature_genotypes as $feature_genotype){
+          $feature = $feature_genotype->feature_id;
+          $fname = $feature->name;
+          if(property_exists($feature, 'nid')) {
+            $fname = l($fname, 'node/' . $feature->nid, array('attributes' => array('target' => '_blank')));
+          }
+          $germplasm .= '<br>' . ucwords(preg_replace('/_/', ' ', $feature->type_id->name)) . ': ' . $fname;
+        }
+      }
+        
+      // add the fields to the table row
+      $rows[] = array(
+        $name,
+        $type,
+        $genotype->description,
+        $details,
+        $germplasm
+      );
+    } 
+    
+    // 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_genetic-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' => 'features'
+      ),
+      'quantity' => $num_results_per_page,
+    );
+    print theme_pager($pager);  ?>
+  </div><?php
+} 

+ 0 - 125
tripal_genetic/theme/tripal_stock/tripal_stock_genotypes.tpl.php

@@ -1,125 +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 is for the simple
- * stock_genotype linker table.
- */
-$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 = 0;
-
-// get the genotypes from the stock_genotype table
-$options = array(
-  'return_array' => 1, 
-  'pager' => array('limit' => $num_results_per_page, 'element' => $stock_pager_id),
-);
-$stock = tripal_core_expand_chado_vars($stock, 'table', 'stock_genotype', $options); 
-$stock_genotypes = $stock->stock_genotype;
-
-// create the pager.  
-$stock_pager = theme('pager', array(), $num_results_per_page, $stock_pager_id, array('block' => 'genotypes'));
-
-
-// now iterate through the stock genotypes and print a paged table.
-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 genotypes have been recorded for this stock.</div>
-    <table id="tripal_stock-table-stock_genotypes_exp" class="tripal_stock-table tripal-table tripal-table-horz">     
-      <tr class="tripal_stock-table-odd-row tripal-table-even-row">
-        <th>Name</th>
-        <th>Type</th>
-        <th>Genotype</th>
-        <th>Details</th>
-        <th>Markers</th>
-      </tr> <?php       
-      $i = 0;   
-      foreach($stock_genotypes as $stock_genotype) {
-        $class = 'tripal_stock-table-odd-row tripal-table-odd-row';
-        if($i % 2 == 0 ){
-          $class = 'tripal_stock-table-odd-row tripal-table-even-row';
-        }         
-        $genotype = $stock_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 markers associated with this genotype if any
-        $options = array(
-          'return_array' => 1,
-          'inlude_fk' => array(
-            'feature_id' => array(
-              'type_id' => 1
-            )
-          ),
-        );
-        $genotype = tripal_core_expand_chado_vars($genotype, 'table', 'feature_genotype', $options);
-        $feature_genotypes = $genotype->feature_genotype; ?>
-        <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($feature_genotypes) > 0) { ?>                      
-              <table class="tripal-subtable"> <?php
-                foreach ($feature_genotypes as $feature_genotype){ 
-                  $feature = $feature_genotype->feature_id; ?>
-                  <tr> 
-                    <td><?php print ucwords(preg_replace('/_/', ' ', $feature->type_id->name)) ?></td>
-                    <td>:</td>                  
-                    <td><?php 
-                      if($feature->nid) {
-                        print l($feature->name, 'node/' . $feature->nid);
-                      }
-                      else {
-                        print $feature->name;
-                      }?>
-                    </td>
-                  </tr> <?php                 
-                } ?>
-              </table><?php 
-            } ?>
-          </td>
-        </tr> <?php
-        $i++;
-      } ?>  
-    </table> <?php 
-    print $stock_pager ?>
-  </div><?php
-} 

+ 12 - 10
tripal_genetic/tripal_genetic.module

@@ -13,6 +13,7 @@
  */
 
 require('api/tripal_genetic.api.inc');
+require('theme/tripal_genetic.theme.inc');
 require('includes/tripal_genetic.schema.inc');
 require('includes/tripal_genetic.admin.inc');
 
@@ -74,23 +75,24 @@ function tripal_genetic_views_api() {
  *
  * @ingroup tripal_genetic
  */
-function tripal_genetic_theme() {
-  $theme_path = drupal_get_path('module', 'tripal_genetic') . '/theme';
+function tripal_genetic_theme($existing, $type, $theme, $path) {
+  $core_path = drupal_get_path('module', 'tripal_core');
+    
   $items = array(
     'tripal_feature_genotypes' => array(
-      'arguments' => array('node' => NULL),
-      'template' => 'tripal_feature_genotypes',
-      'path' => "$theme_path/tripal_feature",
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_feature.genotypes',
+      'path' => "$path/theme/tripal_feature",
     ),
     'tripal_stock_genotypes' => array(
-      'arguments' => array('node' => NULL),
-      'template' => 'tripal_stock_genotypes',
-      'path' => "$theme_path/tripal_stock",
+      'variables' => array('node' => NULL),
+      'template' => 'tripal_stock.genotypes',
+      'path' => "$path/theme/tripal_stock",
     ),
     'tripal_genetic_help' => array(
-      'template' => 'tripal_genetic_help',
+      'template' => 'tripal_genetic.help',
       'variables' =>  array(NULL),
-      'path' => "$theme_path",
+      'path' => "$path/theme/",
     ),
   );
   return $items;