Browse Source

More work on theming for analysis go, organism and feature

spficklin 14 years ago
parent
commit
eff151490d

+ 81 - 131
tripal_analysis_go/tripal_analysis_go.module

@@ -1,16 +1,10 @@
 <?php
 
-//
-// Copyright 2009 Clemson University
-//
-
 function tripal_analysis_go_init(){
    // Add style sheet
-   drupal_add_css(drupal_get_path('theme', 'tripal').
-                                  '/css/tripal_analysis_go.css');
+   drupal_add_css(drupal_get_path('theme', 'tripal').'/css/tripal_analysis_go.css');
 
-   drupal_add_js(drupal_get_path('theme', 'tripal').
-       '/js/tripal_analysis_go.js');
+   drupal_add_js(drupal_get_path('theme', 'tripal').'/js/tripal_analysis_go.js');
 }
 
 /*******************************************************************************
@@ -21,14 +15,6 @@ function tripal_analysis_go_init(){
 function tripal_analysis_go_menu() {
    $items = array();
 
-   $items['node/%/goterms'] = array(
-     'title' => t('GO Analysis'),
-     'page callback' => 'tripal_analysis_go_organism_goterms',
-     'page arguments' => array(1),
-     'access callback' => 'tripal_analysis_go_node_has_menu',
-     'access arguments' => array('access chado_analysis_go content',1),
-     'type' => MENU_LOCAL_TASK | MENU_NORMAL_ITEM
-   );
    $items['download_goterm_features'] = array(
       'path' => 'download_goterm_features',
       'title' => t('Get GO Term Features'),
@@ -89,25 +75,34 @@ function chado_analysis_go_access($op, $node, $account){
    return FALSE;
 }
 /*******************************************************************************
- * Dynamic addition/removal of menu item
+ *
  */
-function tripal_analysis_go_node_has_menu($type,$vid){
+function tripal_analysis_go_block($op = 'list', $delta = 0, $edit=array()){
+   switch($op) {
+      case 'list':
+         $blocks['tago_org_sum']['info'] = t('Tripal Organism GO Analysis Report');
+         $blocks['tago_org_sum']['cache'] = BLOCK_NO_CACHE;
 
-   // check to see if this node is an organism node
-   $sql = 'SELECT organism_id FROM {chado_organism} WHERE vid = %d';
-   $result = db_query($sql, $vid);
+         return $blocks;
 
-   // menu status
-   $box_status =variable_get("tripal_analysis_go-box-goterms","menu_off");
 
-   // if this node is not an organism or a feature node then return false
-   // we don't want the menu item to be shown, otherwise get the normal perms
-   if($org_id = db_fetch_object($result)){
-      if(strcmp($box_status,"menu_on")==0){
-         return user_access($type);
-      }
-   } else {
-      return FALSE;
+      case 'view':
+         if(user_access('access chado_analysis_go content') and arg(0) == 'node' and is_numeric(arg(1))) {
+            $nid = arg(1);
+            $node = node_load($nid);
+ 
+            $block = array();
+            switch($delta){
+                 case 'tago_org_sum':
+                  $block['subject'] = t('GO Summary');
+                  $block['content'] = theme('tripal_analysis_go_org_summary',$node);
+                  break;
+
+               default :
+            }
+            return $block;
+         }
+
    }
 }
 /*******************************************************************************
@@ -118,45 +113,40 @@ function tripal_analysis_go_node_has_menu($type,$vid){
 function tripal_analysis_go_nodeapi(&$node, $op, $teaser, $page) {
 
    switch ($op) {
-      // Note that this function only adds library view to an organism/feature
-      // node. The view of a library node is controled by the theme *.tpl file
       case 'view':
-      
-         // Set the node types for showing library information
-         $types_to_show = variable_get('tripal_analysis_go_setting',
-            array('chado_feature','chado_organism'));
-
-         // Abort if this node is not one of the types we should show.
-         if (!in_array($node->type, $types_to_show, TRUE)) {
-            // Turn the menu off if it's on
-            $box_status = variable_get("tripal_analysis_go-box-goterms","menu_off");
-            if (strcmp($box_status,"menu_on")==0 && $node->type =='chado_organism'){
-               variable_set("tripal_analysis_go-box-goterms","menu_off");
-            }
-            break;
+     
+         if ($teaser) {
+            return;
          }
-
-         // Add library to the content item if it's not a teaser
-         if (!$teaser) {
-            // add the library to the organism/feature search indexing
-            if($node->build_mode == NODE_BUILD_SEARCH_INDEX){
-               $node->content['tripal_analysis_go_search_index'] = array(
-						'#value' => theme('tripal_analysis_go_search_index',$node),
-						'#weight' => 5,
-               );
-            } else if ($node->build_mode == NODE_BUILD_SEARCH_RESULT) {
-               $node->content['tripal_analysis_go_search_result'] = array(
-						'#value' => theme('tripal_analysis_go_search_result',$node),
-						'#weight' => 5,
-               );
-            } else {
-               // Show go terms if the organism/feature is not at teaser view               
-               $node->content['tripal_analysis_go_node_add'] = array(
-						'#value' => theme('tripal_analysis_go_node_add', $node),
-					   '#weight' => 5
-               );
+         // add the library to the organism/feature search indexing
+         if($node->build_mode == NODE_BUILD_SEARCH_INDEX){
+            $node->content['tripal_analysis_go_search_index'] = array(
+					'#value' => theme('tripal_analysis_go_search_index',$node),
+					'#weight' => 5,
+            );
+         } else if ($node->build_mode == NODE_BUILD_SEARCH_RESULT) {
+            $node->content['tripal_analysis_go_search_result'] = array(
+					'#value' => theme('tripal_analysis_go_search_result',$node),
+					'#weight' => 5,
+            );
+         } else {
+            // Show go terms if the organism/feature is not at teaser view
+            switch($node->type){
+               case 'chado_organism':    
+                  $node->content['tripal_organism_go_summary'] = array(
+   				      '#value' => theme('tripal_organism_go_summary',$node),
+		      			'#weight' => 5,
+                  );
+                  break;
+               case 'chado_feature':
+                  $node->content['tripal_feature_go_terms'] = array(
+				         '#value' => theme('tripal_feature_go_terms',$node),
+      					'#weight' => 5,
+                  );
+                  break;
             }
          }
+         break;
    }
 }
 
@@ -174,8 +164,13 @@ function tripal_analysis_go_theme () {
       'tripal_analysis_go_search_result' => array (
          'arguments' => array('node'),
       ),
-      'tripal_analysis_go_node_add' => array (
-         'arguments' => array('node'),
+      'tripal_organism_go_summary' => array (
+         'arguments' => array('node'=> null),
+         'template' => 'tripal_organism_go_summary',
+      ),
+      'tripal_feature_go_terms' => array (
+         'arguments' => array('node'=> null),
+         'template' => 'tripal_feature_go_terms',
       )
    );
 }
@@ -192,24 +187,15 @@ function theme_tripal_analysis_go_search_result($node){
 }
 /************************************************************************
 */
-function theme_tripal_analysis_go_node_add($node){
-   $content = '';
-   if(strcmp($node->type,'chado_feature')==0){
-      $content = tripal_analysis_go_feature_add($node);
-   }
-   if(strcmp($node->type,'chado_organism')==0){
-      $box_status = variable_get("tripal_analysis_go-box-goterms","menu_off");
-      if (strcmp($box_status,"menu_off")==0){
-         $content = tripal_analysis_go_organism_add($node);
-      }
-   }
-   return $content;
+function tripal_analysis_go_preprocess_tripal_feature_go_terms(&$variables){
+   $node = $variables['node'];
+   $variables['tripal_analysis_go']['go_terms'] = tripal_analysis_go_feature_add($node);
 }
 /************************************************************************
 */
-function tripal_analysis_go_organism_goterms($node) {
-   $node = node_load($node);
-   return tripal_analysis_go_organism_add($node);
+function tripal_analysis_go_preprocess_tripal_organism_go_summary(&$variables){
+   $node = $variables['node'];
+   $variables['tripal_analysis_go']['form'] = tripal_analysis_go_organism_add($node);
 }
 /************************************************************************
 */
@@ -280,66 +266,30 @@ function tripal_analysis_go_org_charts ($element) {
 /************************************************************************
 */
 function tripal_analysis_go_organism_add($node) {
-   // Show GO information in a expandable box for a organism page.
-   // Make sure we have $node->organism_id. In the case of creating a new
-   // organism, the organism_id is not created until we save. This will cause
-   // an error when users preview the creation without a $node->organism_id
-   $box_status = variable_get("tripal_analysis_go-box-goterms","menu_off");
-      
-   if(strcmp($box_status,"menu_off")==0){
-      $content .= "
-      <div class=\"tripal_go_summary-info-box\">
-        <div class=\"tripal_expandableBox\">
-	       <h3>Gene Ontology Summary</h3>
-	     </div>
-        <div class=\"tripal_expandableBoxContent\">
-      ";
-   } 
+   $organism = $node->organism;
 
    // check to see if we have any analyses
    $sql = "
-     SELECT DISTINCT A.analysis_id, A.name, GCA.organism_id
+     SELECT count(*) as cnt
      FROM {go_count_analysis} GCA
        INNER JOIN Analysis A on GCA.analysis_id = A.analysis_id
      WHERE organism_id = %d
-     ORDER BY analysis_id DESC
    ";
    $previous_db = tripal_db_set_active('chado');
-   $results = db_fetch_object(db_query($sql,$node->organism_id));
+   $num_analyses = db_fetch_object(db_query($sql,$organism->organism_id));
    tripal_db_set_active($previous_db);
 
-   if($results){
-      $select_analysis = drupal_get_form('tripal_analysis_go_select_form',$node);
-
-      $url = url("sites/all/themes/theme_tripal/images/ajax-loader.gif");
-      $content .= "
-        $select_analysis
-        <div id=\"tripal_cv_cvterm_info_box\">
-           <a href=\"#\" onclick=\"$('#tripal_cv_cvterm_info_box').hide()\" style=\"float: right\">Close [X]</a>
-           <h3>Term Information</h3>
-           <div id=\"tripal_cv_cvterm_info\"></div>
-        </div>
-        <div id=\"tripal_ajaxLoading\" style=\"display:none\">
-        <div id=\"loadingText\">Loading...</div>
-        <img src=\"$url\"></div><div id=\"tripal_analysis_go_org_charts\"></div>
-      ";
+   if($num_analyses->cnt > 0){
+      return array (
+         'status' => 1,
+         'value' => drupal_get_form('tripal_analysis_go_select_form',$node),
+      );
    } else {
-      $content .= "There are currently no Gene Ontology (GO) reports for this organism\n";
+      return array(
+         'status' => 0,
+         'value' => t('There are no GO analysis reports'),
+      );
    }
-
-   if(user_access('access administrative pages')){
-      $link = url("tripal_toggle_box_menu/tripal_analysis_go/goterms/$node->nid");
-   	if(strcmp($box_status,"menu_off")==0){
-         $content .= "<br><a href=\"$link\">Show on menu</a>";
-      } else {
-         $content .= "<br><a href=\"$link\">Remove from menu</a>";
-      }
-   }
-   if(strcmp($box_status,"menu_off")==0){
-      $content .= "</div></div>";
-   }
-
-   return $content;
 }
 /************************************************************************
  *

+ 79 - 83
tripal_feature/tripal_feature.module

@@ -1214,6 +1214,64 @@ function tripal_feature_load_featureloc_sequences($feature_id,$featurelocs){
    }
    return $floc_sequences;
 }
+/************************************************************************
+ *  used to sort the list of relationship objects by start position
+ */
+function tripal_feature_load_organism_feature_browser($organism){
+
+   // don't show the browser if the settings in the admin page is turned off
+   $show_browser = variable_get('tripal_feature_browse_setting',array('show_feature_browser'));
+   if(strcmp($show_browser[0],'show_feature_browser')!=0){
+      return false;
+   }
+   if ($organism->organism_id) {
+      # get the list of available sequence ontology terms for which
+      # we will build drupal pages from features in chado.  If a feature
+      # is not one of the specified typse we won't build a node for it.
+      $allowed_types = variable_get('chado_feature_types','EST contig');
+      $allowed_types = preg_replace("/[\s\n\r]+/"," ",$allowed_types);
+      $so_terms = split(' ',$allowed_types);
+      $where_cvt = "";
+      foreach ($so_terms as $term){
+         $where_cvt .= "CVT.name = '$term' OR ";
+      }
+      $where_cvt = substr($where_cvt,0,strlen($where_cvt)-3);  # strip trailing 'OR'
+
+      // get the features for this organism
+      $sql  = "SELECT F.name,F.feature_id,F.uniquename,CVT.name as cvname ".
+              "FROM {feature} F ".
+                 "  INNER JOIN {cvterm} CVT on F.type_id = CVT.cvterm_id ".
+               "WHERE organism_id = %s and ($where_cvt) ".
+               "ORDER BY feature_id ASC";
+
+      // the counting SQL
+      $csql  = "SELECT count(*) ".
+               "FROM {feature} F".
+               "  INNER JOIN {cvterm} CVT on F.type_id = CVT.cvterm_id ".
+               "WHERE organism_id = %s and ($where_cvt) ".
+               "GROUP BY organism_id ";
+
+      $previous_db = tripal_db_set_active('chado');  // use chado database
+      $org_features = pager_query($sql,10,0,$csql,$organism->organism_id);
+      tripal_db_set_active($previous_db);  // now use drupal database
+      $pager = theme('pager');
+
+      // prepare the query that will lookup node ids
+      $sql = "SELECT nid FROM {chado_feature} ".
+              "WHERE feature_id = %d";
+      $i=0;
+      $features = array();
+      while($feature = db_fetch_object($org_features)){
+         $node = db_fetch_object(db_query($sql,$feature->feature_id));
+         $feature->nid = $node->nid;
+         $features[$i++] = $feature;
+      }
+drupal_set_message("Pager $pager");
+
+      return array ( 'features' => $features, 'pager' => $pager );
+   }
+   return false;
+}
 /************************************************************************
  *  used to sort the list of relationship objects by start position
  */
@@ -1333,13 +1391,8 @@ function tripal_feature_nodeapi(&$node, $op, $teaser, $page) {
                // Show feature browser
                $types_to_show = array('chado_organism', 'chado_library');
                if (in_array($node->type, $types_to_show, TRUE)) {
-                  $node->content['tripal_feature_browser'] = array(
-                     '#value' => theme('tripal_feature_browser', $node),
-                     '#weight' => 5
-                  );
                   $node->content['tripal_feature_org_counts'] = array(
-                     '#value' => theme('tripal_feature_org_counts', $node),
-                     '#weight' => 4
+                    '#value' => theme('tripal_feature_org_counts', $node),
                   );
                }
                break;
@@ -1350,6 +1403,16 @@ function tripal_feature_nodeapi(&$node, $op, $teaser, $page) {
          break;
       // we're loading the data for the node
       case 'load':
+         switch($node->type){
+            case 'chado_organism':
+               // Show feature browser
+               $types_to_show = array('chado_organism', 'chado_library');
+               if (in_array($node->type, $types_to_show, TRUE)) {
+                  $variables['tripal_feature']['browser'] = tripal_feature_load_organism_feature_browser($node->organism);
+                  return $variables;
+               }
+            break;
+         }
       break;
    }
 }
@@ -1366,8 +1429,9 @@ function tripal_feature_theme () {
       'tripal_feature_search_results' => array (
          'arguments' => array('node'),
       ),
-      'tripal_feature_browser' => array (
-         'arguments' => array('node'),
+      'tripal_organism_feature_browser' => array (
+         'arguments' => array('node'=> null),
+         'template' => 'tripal_organism_feature_browser',
       ),
       'tripal_feature_org_counts' => array (
          'arguments' => array('node'),
@@ -1433,6 +1497,13 @@ function tripal_feature_preprocess(&$variables){
       $variables['tripal_feature']['featureloc_sequences'] = tripal_feature_load_featureloc_sequences ($feature->feature_id,$featurelocs);   
    }
 }
+/*******************************************************************************
+ *  
+ */
+function tripal_feature_preprocess_tripal_organism_feature_browser(&$variables){
+   $organism = $variables['node']->organism;
+   $variables['tripal_feature']['browser'] = tripal_feature_load_organism_feature_browser($organism);
+}
 /*******************************************************************************
  *  
  */
@@ -1583,82 +1654,7 @@ function tripal_feature_cv_tree($tree_id){
   );
   return $options;
 }
-/*******************************************************************************
- *  create a simple paged feature browser
- */
-function theme_tripal_feature_browser($node){
-   $organism = $node->organism;
-
-   // don't show the browser if the settings in the admin page is turned off
-   $show_browser = variable_get('tripal_feature_browse_setting',array('show_feature_browser'));
-
-   if(strcmp($show_browser[0],'show_feature_browser')!=0){
-      return;
-   }
-   if ($organism->organism_id && $node->type == 'chado_organism') {
-      # get the list of available sequence ontology terms for which
-      # we will build drupal pages from features in chado.  If a feature
-      # is not one of the specified typse we won't build a node for it.
-      $allowed_types = variable_get('chado_feature_types','EST contig');
-      $allowed_types = preg_replace("/[\s\n\r]+/"," ",$allowed_types);
-      $so_terms = split(' ',$allowed_types);
-      $where_cvt = "";
-      foreach ($so_terms as $term){
-         $where_cvt .= "CVT.name = '$term' OR ";
-      }
-      $where_cvt = substr($where_cvt,0,strlen($where_cvt)-3);  # strip trailing 'OR'
 
-      // get the features for this organism
-      $sql  = "SELECT F.name,F.feature_id,F.uniquename,CVT.name as cvname ".
-              "FROM {feature} F ".
-                 "  INNER JOIN {cvterm} CVT on F.type_id = CVT.cvterm_id ".
-               "WHERE organism_id = $organism->organism_id and ($where_cvt) ".
-               "ORDER BY feature_id ASC";
-
-      // the counting SQL
-      $csql  = "SELECT count(*) ".
-               "FROM {feature} F".
-               "  INNER JOIN {cvterm} CVT on F.type_id = CVT.cvterm_id ".
-               "WHERE organism_id = $organism->organism_id and ($where_cvt) ".
-               "GROUP BY organism_id ";
-
-      $previous_db = tripal_db_set_active('chado');  // use chado database
-      $features = pager_query($sql,10,0,$csql);
-      tripal_db_set_active($previous_db);  // now use drupal database
-
-      $content = "<br><div id=\"tripal_feature_box\" class=\"feature-info-box\">";
-      $content .= "<div class=\"tripal_expandableBox\">".
-                  "<h3>Browse Features</h3>".
-                  "</div>";
-      $content .= "<div class=\"tripal_expandableBoxContent\">";
-      $content .= "Below are the features associated with this organism.\n";
-      $content .= "<table class=\"tripal_table_horz\">";
-      $content .= "  <tr>";
-      $content .= "    <th>Feature Name</th>";
-      $content .= "    <th>Type</th>";
-      $content .= "  </tr>";
-
-      // prepare the query that will lookup node ids
-      $sql = "SELECT nid FROM {chado_feature} ".
-              "WHERE feature_id = %d";
-      while($feature = db_fetch_object($features)){
-         $node = db_fetch_object(db_query($sql,$feature->feature_id));
-         if($node){
-            $name= "<a href=\"" . url("node/$node->nid") . "\">$feature->name</a>";
-         } else {
-            $name= "$feature->name";
-         }
-         $content .= "  <tr>";
-         $content .= "    <td>$name</td>";
-         $content .= "    <td>$feature->cvname</td>";
-         $content .= "  </tr>";
-      }
-      $content .= "</table>";
-      $content .= theme('pager');
-      $content .= "</div></div>";
-      return $content;
-   }
-}
 /************************************************************************
  *  This function is an extension of the chado_feature_view by providing
  *  the markup for the feature object THAT WILL BE INDEXED.

+ 4 - 17
tripal_organism/tripal_organism.module

@@ -537,22 +537,7 @@ function tripal_organism_nodeapi(&$node, $op, $teaser, $page) {
 
    switch ($op) {
       case 'view':
-         switch($node->type){
-            case 'chado_organism':
-               $node->content['tripal_organism_image'] = array(
-                  '#value' => theme('tripal_organism_image', $node),
-                  '#weight' => 0
-               );
-               $node->content['tripal_organism_base'] = array(
-                  '#value' => theme('tripal_organism_base', $node),
-                  '#weight' => 1
-               );
-               $node->content['tripal_organism_description'] = array(
-                  '#value' => theme('tripal_organism_description', $node),
-                  '#weight' => 2
-               );
-               break;
-            default:          
+         switch($node->type){                   
            
          }
    }
@@ -901,7 +886,9 @@ function tripal_organism_show_organisms (){
                "synchronize organisms.");
    }
 }
-
+/*******************************************************************************
+*
+*/
 function theme_tripal_organism_organism_page($organisms) {
 
 	$output = "<br><a id=\"tripal_expandableBox_toggle_button\" onClick=\"toggleExpandableBoxes()\">[-] Collapse All</a>";