Browse Source

Added functionality to the Feature Summary Report on the organism page so that site admins can customize which terms appear in the list and rename the terms to make them more legible. By default the report behaves the same

Stephen Ficklin 13 years ago
parent
commit
21f247f98e
3 changed files with 113 additions and 24 deletions
  1. 1 1
      tripal_core/mviews.php
  2. 31 7
      tripal_feature/tripal_feature.admin.inc
  3. 81 16
      tripal_feature/tripal_feature.module

+ 1 - 1
tripal_core/mviews.php

@@ -644,7 +644,7 @@ function tripal_mviews_form_validate($form, &$form_state){
             'traditional method but not both.'));
    }
    if(!$schema){
-      if(!$mv_speces){
+      if(!$mv_specs){
          form_set_error($form_state['values']['mv_specs'], 
             t('The Table Definition field is required.'));
       }

+ 31 - 7
tripal_feature/tripal_feature.admin.inc

@@ -125,7 +125,7 @@ function tripal_feature_module_description_page() {
                visitors.    This browser can be toggled on or off using the 
                <a href="'.url('admin/tripal/tripal_feature/configuration').'">Feature Configuration page</a></p></li>
  
-              <li><p><b>Feature Summary:</b>  The feature summary is a pie chart that indicates the types and quantities
+              <li><p><b>Feature Summary Report:</b>  The feature summary report is a pie chart that indicates the types and quantities
               of feature types (Sequence Ontology terms) that are loaded in the database. It appears on the organism 
               page.  The summary can be toggled on or off using the 
               <a href="'.url('admin/tripal/tripal_feature/configuration').'">Feature Configuration page</a></p></li>             
@@ -225,7 +225,9 @@ function tripal_feature_admin () {
 
       $form['browser'] = array(
          '#type' => 'fieldset',
-         '#title' => t('Feature Browser')
+         '#title' => t('Feature Browser'),
+         '#collapsible' => 1,
+         '#collapsed' => 1 ,
       );
       $allowedoptions1  = array (
         'show_feature_browser' => "Show the feature browser on the organism page. The browser loads when page loads. This may be slow for large sites.",
@@ -286,7 +288,9 @@ function tripal_feature_admin () {
 
       $form['feature_edit'] = array(
          '#type' => 'fieldset',
-         '#title' => t('Feature Editing')
+         '#title' => t('Feature Editing'),
+         '#collapsible' => 1,
+         '#collapsed' => 1 ,
       );
 
       $form['feature_edit']['browser_desc'] = array(
@@ -311,7 +315,9 @@ function tripal_feature_admin () {
 
       $form['summary'] = array(
          '#type' => 'fieldset',
-         '#title' => t('Feature Summary')
+         '#title' => t('Feature Summary Report'),
+         '#collapsible' => 1,
+         '#collapsed' => 1 ,
       );
       $allowedoptions2 ['show_feature_summary'] = "Show the feature summary on the organism page. The summary loads when page loads.";
       $allowedoptions2 ['hide_feature_summary'] = "Hide the feature summary on the organism page. Disables the feature summary.";
@@ -324,6 +330,17 @@ function tripal_feature_admin () {
          '#options' => $allowedoptions2,
          '#default_value'=>variable_get('tripal_feature_summary_setting', 'show_feature_summary'),
       );
+      $form['summary']['feature_mapping'] = array(
+         '#title' => 'Map feature types',
+         '#description' => t('You may specify which Sequence Ontology (SO) terms to show in the '.
+            'feature summary report by listing them in the following text area.   Enter one per line. '.
+            'If left blank, all SO terms for all features will be shown in the report. Only those terms '.
+            'listed below will be shown in the report. Terms will appear in the report in the same order listed. To rename a '.
+            'SO term to be more human readable form, use an \'=\' sign after the SO term (e.g. \'polypeptide = Protein\')'),
+         '#type' => 'textarea',
+         '#rows' => 15,
+         '#default_value'=>variable_get('tripal_feature_summary_report_mapping', ''),
+      );
       $form['summary']['set_summary_button'] = array(
          '#type' => 'submit',
          '#value' => t('Set Summary'),
@@ -396,6 +413,7 @@ function tripal_feature_admin_validate($form, &$form_state) {
 
       case t('Set Summary') :
          variable_set('tripal_feature_summary_setting',$form_state['values']['feature_summary']);
+         variable_set('tripal_feature_summary_report_mapping',$form_state['values']['feature_mapping']);
          break;
 
       case t('Set Feature URLs') :
@@ -413,7 +431,9 @@ function tripal_feature_admin_validate($form, &$form_state) {
 function get_tripal_feature_admin_form_cleanup_set(&$form) {
    $form['cleanup'] = array(
       '#type' => 'fieldset',
-      '#title' => t('Clean Up')
+      '#title' => t('Clean Up'),
+      '#collapsible' => 1,
+      '#collapsed' => 1 ,
    );
    $form['cleanup']['description'] = array(
        '#type' => 'item',
@@ -443,7 +463,9 @@ function get_tripal_feature_admin_form_cleanup_set(&$form) {
 function get_tripal_feature_admin_form_reindex_set(&$form) {
    $form['reindex'] = array(
       '#type' => 'fieldset',
-      '#title' => t('Index/Reindex')
+      '#title' => t('Index/Reindex'),
+      '#collapsible' => 1,
+      '#collapsed' => 1 ,
    );
    $form['reindex']['description'] = array(
        '#type' => 'item',
@@ -471,7 +493,9 @@ function get_tripal_feature_admin_form_taxonomy_set (&$form) {
 
    $form['taxonomy'] = array(
       '#type' => 'fieldset',
-      '#title' => t('Set Taxonomy')
+      '#title' => t('Set Taxonomy'),
+      '#collapsible' => 1,
+      '#collapsed' => 1 ,
    );
 
    $form['taxonomy']['description'] = array(

+ 81 - 16
tripal_feature/tripal_feature.module

@@ -1342,6 +1342,41 @@ function tripal_feature_load_organism_feature_counts($organism){
    if(strcmp($show_counts,'show_feature_summary')!=0){
       return array ('enabled' => false );
    }
+   
+
+   $args = array();
+   $names = array();
+   $order = array();
+   
+   // build the where clause for the SQL statement if we have a custom term list
+   // we'll also keep track of the names the admin provided (if any) and the 
+   // order that the terms should appear.
+   $is_custom = 0;
+   $temp = rtrim(variable_get('tripal_feature_summary_report_mapping', ''));
+   $where = '';
+   if($temp){
+      $is_custom = 1;
+      $temp = explode("\n",$temp);
+      foreach ($temp as $key => $value){
+         // separate the key value pairs
+         $temp2 = explode("=",$value);
+         $feature_type = rtrim($temp2[0]);
+         $args[] = $feature_type;
+         $order[] = $feature_type;
+         // if a new name is provided then use that otherwise just
+         // use the feature type
+         if(count($temp2) == 2){
+            $names[] = rtrim($temp2[1]);
+         } else {
+            $names[] = $feature_type;
+         }
+         $where .= "OFC.feature_type = '%s' OR \n";
+      }
+      if($where){
+         $where = substr($where,0,-5);  # remove OR from the end
+         $where = "($where) AND";
+      }
+   }
 
    // get the feature counts.  This is dependent on a materialized view
    // installed with the organism module
@@ -1349,19 +1384,32 @@ function tripal_feature_load_organism_feature_counts($organism){
       SELECT OFC.num_features,OFC.feature_type,CVT.definition
       FROM {organism_feature_count} OFC
         INNER JOIN {cvterm} CVT on OFC.cvterm_id = CVT.cvterm_id
-      WHERE organism_id = %d 
+      WHERE $where organism_id = %d
       ORDER BY num_features desc
    ";
+   $args[] = $organism->organism_id;
    $previous_db = tripal_db_set_active('chado');  // use chado database
-   $org_features = db_query($sql,$organism->organism_id);
+   $org_features = db_query($sql,$args);
    tripal_db_set_active($previous_db);  // now use drupal database
-
-   $i=0;
+   
+   // iterate through the types 
    $types = array();
    while($type = db_fetch_object($org_features)){
-      $types[$i++] = $type;
+      $types[$type->feature_type] = $type;      
+      // if we don't have an order this means we didn't go through the loop
+      // above to set the names, so do that now
+      if(!$is_custom){
+         $names[] = $type->feature_type;
+         $order[] = $type->feature_type;
+      }
    }
-   return array ( 'types' => $types, 'enabled' => true );
+
+   # now reorder the types
+   $ordered_types = array();
+   foreach ($order as $type){
+      $ordered_types[] = $types[$type];
+   }
+   return array ( 'types' => $ordered_types, 'names' => $names, 'enabled' => true );
 }
 /**
  * 
@@ -1822,20 +1870,37 @@ function tripal_feature_preprocess_tripal_analysis_feature_browser(&$variables){
  */
 function tripal_feature_cv_chart($chart_id){
 
-  // The CV module will create the JSON array necessary for buillding a
-  // pie chart using jgChart and Google Charts.  We have to pass to it
-  // a table that contains count information, tell it which column 
-  // contains the cvterm_id and provide a filter for getting the
-  // results we want from the table.
-  $organism_id = preg_replace("/^tripal_feature_cv_chart_(\d+)$/","$1",$chart_id);
-  $options = array(
+   // we only want the chart to show feature types setup by the admin
+   $temp = rtrim(variable_get('tripal_feature_summary_report_mapping', ''));
+   $where = '';
+   if($temp){
+      $temp = explode("\n",$temp);
+      foreach ($temp as $key => $value){
+         $temp2 = explode("=",$value);
+         $feature_type = rtrim($temp2[0]);
+         $where .= "CNT.feature_type = '$feature_type' OR \n";
+      }
+      if($where){
+         $where = substr($where,0,-5);  # remove OR from the end
+         $where = "($where) AND";
+      }
+   }
+
+   $organism_id = preg_replace("/^tripal_feature_cv_chart_(\d+)$/","$1",$chart_id);
+  
+   // The CV module will create the JSON array necessary for buillding a
+   // pie chart using jgChart and Google Charts.  We have to pass to it
+   // a table that contains count information, tell it which column 
+   // contains the cvterm_id and provide a filter for getting the
+   // results we want from the table.   
+   $options = array(
      count_mview      => 'organism_feature_count',
      cvterm_id_column => 'cvterm_id',
      count_column     => 'num_features',
      size             => '550x200',
-     filter           => "CNT.organism_id = $organism_id",
-  );
-  return $options;
+     filter           => "$where CNT.organism_id = $organism_id",
+   );
+   return $options;
 }
 
 /**