Browse Source

Theming corrections

spficklin 14 years ago
parent
commit
19b39807e6

+ 88 - 84
tripal_analysis_blast/tripal_analysis_blast.module

@@ -1,16 +1,12 @@
 <?php
-// $Id:
-// Copyright 2009 Clemson University
 /*******************************************************************************
  * Tripal Blast Result lets users show/hide blast results associated
  * with a tripal feature
  ******************************************************************************/
 function tripal_analysis_blast_init(){
 	// Add javascript and style sheet
-	drupal_add_css(drupal_get_path('theme', 'tripal').
-                                  '/css/tripal_analysis_blast.css');
-	drupal_add_js(drupal_get_path('theme', 'tripal').
-                                 '/js/tripal_analysis_blast.js');
+	drupal_add_css(drupal_get_path('theme', 'tripal').'/css/tripal_analysis_blast.css');
+	drupal_add_js(drupal_get_path('theme', 'tripal').'/js/tripal_analysis_blast.js');
 }
 
 /*******************************************************************************
@@ -19,12 +15,12 @@ function tripal_analysis_blast_init(){
  * Entry points and paths of the module
  */
 function tripal_analysis_blast_menu() {
-	//Show top 10/25/all blast results for ajax calls
+	// Show top 10/25/all blast results for ajax calls
 	$items['tripal_top_blast'] = array(
       'path' => 'top_blast',
       'title' => t('Blast Hits'),
-      'page callback' => 'tripal_get_blast_results',
-      'page arguments' => array(1,2,3,'1'),
+      'page callback' => 'tripal_get_feature_blast_results_ajax',
+      'page arguments' => array(1,2,3),
       'access arguments' => array('access content'),
       'type' => MENU_CALLBACK
 	);
@@ -65,12 +61,13 @@ function tripal_analysis_blast_nodeapi(&$node, $op, $teaser, $page) {
                   '#weight' => 8,
 					);
 				} else {
-
-					// Show blast result if not at teaser view
-					$node->content['tripal_analysis_blast_form'] = array(
-                  '#value' => theme('tripal_analysis_blast_results', $node),
-                  '#weight' => 8
-					);
+               if(strcmp($node->type,'chado_feature')==0){
+					   // Show blast result if not at teaser view
+					   $node->content['tripal_feature_blast_results'] = array(
+                     '#value' => theme('tripal_feature_blast_results', $node),
+                     '#weight' => 8
+					   );
+               }
 				}
 			}
 	}
@@ -85,21 +82,40 @@ function tripal_analysis_blast_theme () {
       'tripal_analysis_blast_results_index_version' => array (
          'arguments' => array('node'),
 		),
-		'tripal_analysis_blast_results' => array(
+		'tripal_feature_blast_results' => array(
 			'arguments' =>  array('node'=> null),
-		   'template' => 'tripal_analysis_blast_results',
+		   'template' => 'tripal_feature_blast_results',
 		)
 	);
 }
 /*******************************************************************************
  *  
  */
-function tripal_analysis_blast_preprocess_tripal_analysis_blast_results(&$variables){
+function tripal_get_feature_blast_results_ajax($feature_id, $db_id, $max){
+   $sql = "SELECT nid FROM {chado_feature} WHERE feature_id = %d";
+   $nid = db_fetch_object(db_query($sql,$feature_id));
+   $node = node_load($nid->nid);
+
+   // add the additional variables that the theme needs to generate the output
+   $node->db_id = $db_id;
+   $node->max = $max;
+   // call the theme to rebuild the blast results
+   drupal_json(array('update' => theme('tripal_feature_blast_results',$node)));
+}
+/*******************************************************************************
+ *  
+ */
+function tripal_analysis_blast_preprocess_tripal_feature_blast_results(&$variables){
    $feature = $variables['node']->feature;
-   $blast_object = tripal_get_blast_results($feature->feature_id, 0, 10, 0);
-   $variables['blast_object'] = $blast_object;
+   $db_id = $variables['node']->db_id;
+  
+   $max = 10;
+   if(isset($variables['node']->max)){
+      $max = $variables['node']->max;
+   }
+   $blast_results = tripal_get_feature_blast_results($feature->feature_id, $db_id, $max);
+   $variables['tripal_analysis_blast']['blast_results_list'] = $blast_results;
 }
-
 /*******************************************************************************
  * Prepare blast result for the feature shown on the page
  */
@@ -110,30 +126,24 @@ function theme_tripal_analysis_blast_results_index_version ($node) {
 }
 
 /*******************************************************************************
- * tripal_get_blast_results()
+ * tripal_get_feature_blast_results()
  * Get blast result from featureprop table for the feature
  */
-function tripal_get_blast_results($feature_id, $db_id, $max,$ajax){
+function tripal_get_feature_blast_results($feature_id, $db_id, $max){
 
-	// Get cvterm_id for 'analysis_blast_output_iteration_hits' which is required
-	// for inserting into the analysisfeatureprop table
-	$previous_db = tripal_db_set_active('chado');
-	$sql = "SELECT CVT.cvterm_id FROM {cvterm} CVT ".
-          "INNER JOIN cv ON cv.cv_id = CVT.cv_id ".
-          "WHERE CVT.name = 'analysis_blast_output_iteration_hits' ".
-          "AND CV.name = 'tripal'";
-	$type_id = db_result(db_query($sql));
-
-	// Get xml string from analysisfeatureprop value column, get db_id from analysisprop value column
-	// , and get analysis_id from analysisfeature table
+	// Get the blast results stored as XML from the analysisfeatureprop table
+   // the type for the property is named 'analysis_blast_output_iteration_hits'
+   // and is found in the 'tripal' controlled vocabulary.  This CV term was
+   // added by this module.
 	$sql = "SELECT AP.value AS apvalue, AFP.value AS afpvalue, AF.analysis_id AS aid
 	        FROM {analysisfeatureprop} AFP
-	        INNER JOIN analysisfeature AF ON AF.analysisfeature_id = AFP.analysisfeature_id
-	        INNER JOIN analysisprop AP ON AP.analysis_id = AF.analysis_id
-	        WHERE feature_id = %d
-	        AND AFP.type_id = %d 
-	        AND AP.value like '%|%' ";
-	$result = db_query($sql, $feature_id, $type_id);
+	          INNER JOIN {analysisfeature} AF ON AF.analysisfeature_id = AFP.analysisfeature_id
+	          INNER JOIN {analysisprop} AP ON AP.analysis_id = AF.analysis_id
+             INNER JOIN {cvterm} CVT on AFP.type_id = CVT.cvterm_id
+             INNER JOIN {cv} CV on CVT.cv_id = CV.cv_id
+	        WHERE AF.feature_id = %d AND CV.name = '%s' AND
+                 CVT.name = '%s' AND AP.value like '%|%' ";
+	$result = db_query($sql, $feature_id,'tripal','analysis_blast_output_iteration_hits');
 	tripal_db_set_active($previous_db);
 
 	// get the HTML content for viewing each of the XML file
@@ -141,52 +151,46 @@ function tripal_get_blast_results($feature_id, $db_id, $max,$ajax){
 	$blast_obj_counter = 0;
 	while ($analysisfeatureprop = db_fetch_object($result)) {
 
-		// get db_id
+      // the database db_id is stored in the value field of the table
+      // along with the XML.  The two are separated by a bar.  We
+      // will separate these two:
 		$blastsettings = explode("|", $analysisfeatureprop->apvalue);
-		$att_db_id = $blastsettings [0];
+
+      // if we don't have the proper number of fields in the value column then
+      // skip this entry
+      if(count($blastsettings) != 3){
+        continue;
+      }
+      if(!$blastsettings[0]){
+        continue;
+      }
+		$att_db_id = $blastsettings[0];
 
 		// get analysis name and date
 		$previous_db = tripal_db_set_active('chado');
 		$sql = "SELECT analysis_id AS aid, name, to_char(timeexecuted, 'MM-DD-YYYY') AS time
-		        FROM {analysis} 		        WHERE analysis_id = %d";
+		        FROM {analysis}
+ 		        WHERE analysis_id = %d";
 		$analysis = db_fetch_object(db_query($sql, $analysisfeatureprop->aid));
 		tripal_db_set_active($previous_db);
 
-		// If not called by ajax, go through all blast hits
-		if ($ajax == 0) {
-			// Get db object using the db_id
-			$previous_db = tripal_db_set_active('chado');
-			$sql = "SELECT * FROM {db} WHERE db_id=%d";
-			$db = db_fetch_object(db_query($sql, $att_db_id));
-			tripal_db_set_active($previous_db);
+		// Get db object using the db_id
+		$previous_db = tripal_db_set_active('chado');
+		$sql = "SELECT * FROM {db} WHERE db_id=%d";
+		$db = db_fetch_object(db_query($sql, $att_db_id));
+		tripal_db_set_active($previous_db);
+
+      // we want to add this blast result to our list if a database id has
+      // not been specified or if it has been specified and the database id
+      // for this analysis matches that of the one requested
+      if(!$db_id or ($db_id and $att_db_id == $db_id)) {
 			$blast_obj = tripal_analysis_blast_get_result_object($analysisfeatureprop->afpvalue,$db,$max,$feature_id, $analysis);
+         $blast_obj->analysis = $analysis;
 			$blast_obj_array [$blast_obj_counter] = $blast_obj;
 			$blast_obj_counter ++;
-			// Otherwise, only update expandable box the user has clicked on
-		} else {
-			if ($att_db_id == $db_id) {
-				// Get db object using the db_id
-				$previous_db = tripal_db_set_active('chado');
-				$sql = "SELECT * FROM {db} WHERE db_id=%d";
-				$db = db_fetch_object(db_query($sql, $att_db_id));
-				tripal_db_set_active($previous_db);
-				$blast_obj = tripal_analysis_blast_get_result_object($analysisfeatureprop->afpvalue,$db,$max,$feature_id, $analysis);
-				$blast_obj_array [$blast_obj_counter] = $blast_obj;
-				$blast_obj_counter ++;
-			}
-		}
-	}
-
-	// since this function provides output for addition into
-	// a feature page, as well as an AJAX refresh of content
-	// within the blast hits we need to setup the return
-	// different depending on the request type
-	if($ajax){
-		$content =  theme('tripal_analysis_blast_results', $node);drupal_set_message("CONTENT:".$content);
-		drupal_json(array('update' => $content));
-	} else {
-		return $blast_obj_array;
+      }
 	}
+   return $blast_obj_array;
 }
 /*******************************************************************************
  * Scanning the file folder for blast results and prepare content for indexing
@@ -1524,16 +1528,16 @@ function tripal_analysis_blast_get_result_object($xml_string,$db,$max,$feature_i
 					}
 
 					$hsp_content = array();
-					$hsp_content ['hsp_num'] = $hsp_num;
-					$hsp_content ['bit_score'] = $hsp_bit_score;
-					$hsp_content ['score'] = $hsp_score;
-					$hsp_content ['evalue'] = $hsp_evalue;
-					$hsp_content ['query_frame'] = $hsp_query_frame;
-					$hsp_content ['qseq'] = $hsp_qseq;
-					$hsp_content ['midline'] = $hsp_midline;
-					$hsp_content ['hseq'] = $hsp_hseq;
-					$hsp_content ['hit_from'] = $hsp_hit_from;
-					$hsp_content ['hit_to'] = $hsp_hit_to;
+					$hsp_content['hsp_num'] = $hsp_num;
+					$hsp_content['bit_score'] = $hsp_bit_score;
+					$hsp_content['score'] = $hsp_score;
+					$hsp_content['evalue'] = $hsp_evalue;
+					$hsp_content['query_frame'] = $hsp_query_frame;
+					$hsp_content['qseq'] = $hsp_qseq;
+					$hsp_content['midline'] = $hsp_midline;
+					$hsp_content['hseq'] = $hsp_hseq;
+					$hsp_content['hit_from'] = $hsp_hit_from;
+					$hsp_content['hit_to'] = $hsp_hit_to;
 					$hsp_content['identity'] = $hsp_identity;
 					$hsp_content['align_len'] = $hsp_align_len;
 					$hsp_content['positive'] = $hsp_positive;

+ 23 - 44
tripal_analysis_go/tripal_analysis_go.module

@@ -188,14 +188,14 @@ function theme_tripal_analysis_go_search_result($node){
 /************************************************************************
 */
 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);
+   $feature = $variables['node']->feature;
+   $variables['tripal_analysis_go']['terms'] = tripal_analysis_go_load_feature_terms($feature);
 }
 /************************************************************************
 */
 function tripal_analysis_go_preprocess_tripal_organism_go_summary(&$variables){
    $node = $variables['node'];
-   $variables['tripal_analysis_go']['form'] = tripal_analysis_go_organism_add($node);
+   $variables['tripal_analysis_go']['select_form'] = tripal_analysis_go_load_organism_go_summary($node);
 }
 /************************************************************************
 */
@@ -211,7 +211,7 @@ function tripal_analysis_go_select_form(&$form_state = NULL,$node){
      ORDER BY analysis_id DESC
    ";
    $previous_db = tripal_db_set_active('chado');
-   $results = db_query($sql,$node->organism_id);
+   $results = db_query($sql,$node->organism->organism_id);
    tripal_db_set_active($previous_db);
 
    $analyses = array();
@@ -265,7 +265,7 @@ function tripal_analysis_go_org_charts ($element) {
 }
 /************************************************************************
 */
-function tripal_analysis_go_organism_add($node) {
+function tripal_analysis_go_load_organism_go_summary($node) {
    $organism = $node->organism;
 
    // check to see if we have any analyses
@@ -276,20 +276,17 @@ function tripal_analysis_go_organism_add($node) {
      WHERE organism_id = %d
    ";
    $previous_db = tripal_db_set_active('chado');
-   $num_analyses = db_fetch_object(db_query($sql,$organism->organism_id));
+   $results = db_fetch_object(db_query($sql,$organism->organism_id));
    tripal_db_set_active($previous_db);
 
-   if($num_analyses->cnt > 0){
-      return array (
-         'status' => 1,
-         'value' => drupal_get_form('tripal_analysis_go_select_form',$node),
-      );
-   } else {
-      return array(
-         'status' => 0,
-         'value' => t('There are no GO analysis reports'),
-      );
+   $has_results = 0;
+   if($results){
+      $has_results = 1;
    }
+   return array (
+      'has_results' => $has_results,
+      'form' => drupal_get_form('tripal_analysis_go_select_form',$node),
+   );
 }
 /************************************************************************
  *
@@ -339,7 +336,7 @@ function tripal_analysis_go_cv_chart($chart_id){
         )
      ",
      type             => 'p',
-     size             => '680x230',
+     size             => '550x175',
      title            => $title,
   );
   return $options;
@@ -455,11 +452,10 @@ function tripal_analysis_go_get_goterm_features($cvterm_id,$tree_id){
 }
 /************************************************************************
 */
-function tripal_analysis_go_feature_add($node) {
-   $content = "";
+function tripal_analysis_go_load_feature_terms($feature) {
    $sql = "
        SELECT DISTINCT FCVT.feature_id,DBX.accession,CVT.name as goterm, 
-          CVT.cvterm_id as go_id, CV.name as cvname
+          CVT.cvterm_id as go_id, CV.name as cvname, CVT.definition
        FROM {Feature_Cvterm} FCVT  
           INNER JOIN Cvterm CVT           ON CVT.cvterm_ID = FCVT.cvterm_ID
           INNER JOIN CV                   ON CV.cv_id = CVT.cv_id  
@@ -473,32 +469,15 @@ function tripal_analysis_go_feature_add($node) {
    ";
 
    $previous_db = tripal_db_set_active('chado');
-   $results = db_query($sql,$node->feature->feature_id);
+   $results = db_query($sql,$feature->feature_id);
    tripal_db_set_active($previous_db);
-   $term = db_fetch_object($results); // retrive the first result
-   if ($term) {
-      $content .= "<div id=\"tripal_go_box\" class=\"tripal_go-info-box\">";
-      $content .= "<div class=\"tripal_expandableBox\">".
-            	   "<h3>GO terms assigned to this feature</h3>".
-                  "</div>";
-      $content .= "<div class=\"tripal_expandableBoxContent\">";
-      $content .= "<table class=\"feature-go-terms\">";
-      $content .= "  <tr>";
-      $content .= "    <th class=\"dbfieldname\">Accession</th>";
-      $content .= "    <th class=\"dbfieldname\">Category</th>";
-      $content .= "    <th class=\"dbfieldname\">Term</th>";
-      $content .= "  </tr>";
-      do {
-         $content .= "<tr>";
-         $content .= "  <td>GO:$term->accession</td>";
-         $content .= "  <td>$term->cvname</td>";
-         $content .= "  <td>$term->goterm</td>";
-         $content .= "</tr>";      
-      } while($term = db_fetch_object($results));
-      $content .= "</table>";
-      $content .= "</div></div>";
+   $i=0;
+   $terms = array();
+   while($term = db_fetch_object($results)){
+
+      $terms[$i++] = $term;
    }
-   return $content;
+   return $terms;
 }
 
 /*******************************************************************************

+ 84 - 165
tripal_analysis_kegg/tripal_analysis_kegg.module

@@ -1,8 +1,5 @@
 <?php
 
-//
-// Copyright 2009 Clemson University
-//
 
 /*******************************************************************************
  *
@@ -49,14 +46,6 @@ function tripal_analysis_kegg_menu() {
      'access arguments' => array('access content'),
      'type' => MENU_CALLBACK
    );
-   $items['node/%/kegg'] = array(
-     'title' => t('KEGG'),
-     'page callback' => 'tripal_analysis_kegg_organism_results',
-     'page arguments' => array(1),
-     'access callback' => 'tripal_analysis_kegg_node_has_menu',
-     'access arguments' => array('access chado_analysis_kegg content',1),
-     'type' => MENU_LOCAL_TASK | MENU_NORMAL_ITEM
-   );
    $items['tripal_analysis_kegg_org_report'] = array(
       'path' => 'tripal_analysis_kegg_org_report',
       'title' => t('Analysis KEGG report'),
@@ -108,57 +97,26 @@ function chado_analysis_kegg_access($op, $node, $account){
    return FALSE;
 }
 
-/*******************************************************************************
- * Dynamic addition/removal of menu item
- */
-function tripal_analysis_kegg_node_has_menu($type,$vid){
-
-   // 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);
-
-   // menu status
-   $box_status =variable_get("tripal_analysis_kegg-box-results","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;
-   }
-}
 /*******************************************************************************
  */
 function tripal_analysis_kegg_brite($analysis_id, $type_id, $ajax){
    // If not called by ajax
    if (!$ajax) {
-      // Add ajax loading box
-      $url_ajax = url("sites/all/themes/theme_tripal/images/ajax-loader.gif");
-      $content .= "<div id=\"tripal_ajaxLoading\" style=\"display:none\">".
-                   "<div id=\"loadingText\">Loading...</div>".
-                   "<img src=\"$url_ajax\"></div>";
-      // Generate tripal_expandable box for the content
-      $content .=  "<div id=\"tripal_kegg_brite_results\" class=\"tripal_kegg_brite-info-box\">
-                      <div class=\"tripal_expandableBox\">
-                        <h3>Analysis Results</h3>
-                      </div>
-                      <div class=\"tripal_expandableBoxContent\">
-                        <table>
-                          <tr>
-                            <th>KEGG BRITE</th>
-                            <th id=\"tripal_kegg_brite_header\">Hierarchy:</th>
-                          </tr>
-                          <tr>
-                            <td nowrap valign=\"top\">";
+      $content .=  
+        "<div id=\"tripal_kegg_brite_results\" class=\"tripal_kegg_brite-info-box\">
+          <table>
+            <tr>
+              <th>KEGG BRITE</th>
+              <th id=\"tripal_kegg_brite_header\">Hierarchy:</th>
+            </tr>
+            <tr>
+              <td nowrap valign=\"top\">
+      ";
       // List all BRITE terms on the left
       $sql = "SELECT CVT.name, CVT.cvterm_id
               FROM {cvterm} CVT 
-              INNER JOIN analysisprop AP ON CVT.cvterm_id = AP.type_id
-              WHERE AP.analysis_id = %d
-              AND CVT.definition LIKE 'KEGG BRITE term: %'
+                INNER JOIN analysisprop AP ON CVT.cvterm_id = AP.type_id
+              WHERE AP.analysis_id = %d AND CVT.definition LIKE 'KEGG BRITE term: %'
               ORDER BY CVT.cvterm_id";
       $previous_db = tripal_db_set_active('chado');
       $result = db_query($sql, $analysis_id);
@@ -185,8 +143,8 @@ function tripal_analysis_kegg_brite($analysis_id, $type_id, $ajax){
       // Get BRITE hierarchy tree
       $sql = "SELECT value
            FROM {analysisprop} AP
-           INNER JOIN CVterm CVT on AP.type_id = CVT.cvterm_id
-           INNER JOIN CV on CVT.cv_id = CV.cv_id
+             INNER JOIN CVterm CVT on AP.type_id = CVT.cvterm_id
+             INNER JOIN CV on CVT.cv_id = CV.cv_id
            WHERE CV.name = 'tripal' and CVT.name = '%s' 
            AND AP.analysis_id = %d";
 
@@ -199,7 +157,6 @@ function tripal_analysis_kegg_brite($analysis_id, $type_id, $ajax){
             $content .= "     </td>
                             </tr>
                           </table>
-                        </div>
                       </div>";
    }
    // since this function provides output for addition into
@@ -656,8 +613,8 @@ function tripal_analysis_kegg_parseHierFile ($analysis_id, $hierfile, $base_path
          }
          $no_file ++;
          
-         # $type variable will be set in tripal_analysis_kegg_parse_keg_file()
-         $content = tripal_analysis_kegg_parse_keg_file("$hierdir/$file",$type,$analysis_id, $base_path);
+         # $type variable will be set in tripal_analysis_kegg_parse_kegg_file()
+         $content = tripal_analysis_kegg_parse_kegg_file("$hierdir/$file",$type,$analysis_id, $base_path);
 
          # add the item to the database
          if($content){
@@ -719,7 +676,7 @@ function tripal_analysis_kegg_parseHierFile ($analysis_id, $hierfile, $base_path
  * and added to chado as a cvterm. Tree structure for this cvterm is then 
  * generated and saved to analysisfeature and analysisfeatureprop tables.
  */
-function tripal_analysis_kegg_parse_keg_file ($file,&$type,$analysis_id, $base_path){
+function tripal_analysis_kegg_parse_kegg_file ($file,&$type,$analysis_id, $base_path){
    $handle = fopen($file,'r');
    $depth = array();
    $current = '@';  # this is one character below 'A' in the ASCII table
@@ -861,45 +818,32 @@ function tripal_analysis_kegg_parse_keg_file ($file,&$type,$analysis_id, $base_p
  */
 function tripal_analysis_kegg_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_kegg_setting',
-            array('chado_feature','chado_analysis_kegg','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_kegg-box-results","menu_off");
-            if (strcmp($box_status,"menu_on")==0 && $node->type =='chado_organism'){
-               variable_set("tripal_analysis_kegg-box-results","menu_off");
-            }
-            break;
-         }
-         
-         // 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_kegg_search_index'] = array(
-                  '#value' => theme('tripal_analysis_kegg_search_index',$node),
-                  '#weight' => 6,
-               );
-            } else if ($node->build_mode == NODE_BUILD_SEARCH_RESULT) {
-               $node->content['tripal_analysis_kegg_search_result'] = array(
-                  '#value' => theme('tripal_analysis_kegg_search_result',$node),
-                  '#weight' => 6,
-               );
-            } else {
-               // Show KEGG BRITE on an analysis page OR KEGG info box on a feature page
-               $node->content['tripal_analysis_kegg_node_add'] = array(
-                  '#value' => theme('tripal_analysis_kegg_node_add', $node),
-                  '#weight' => 6
-               );
+              
+         // add the library to the organism/feature search indexing
+         if($node->build_mode == NODE_BUILD_SEARCH_INDEX){
+            $node->content['tripal_analysis_kegg_search_index'] = array(
+               '#value' => theme('tripal_analysis_kegg_search_index',$node),
+               '#weight' => 6,
+            );
+         } else if ($node->build_mode == NODE_BUILD_SEARCH_RESULT) {
+            $node->content['tripal_analysis_kegg_search_result'] = array(
+               '#value' => theme('tripal_analysis_kegg_search_result',$node),
+               '#weight' => 6,
+            );
+         } else {
+            switch($node->type){
+               case 'chado_organism':
+                  // Show KEGG BRITE on an analysis page OR KEGG info box on a feature page
+                  $node->content['tripal_organism_kegg_summary'] = array(
+                     '#value' => theme('tripal_organism_kegg_summary', $node),
+                     '#weight' => 6
+                  );
+                  break;
             }
+
          }
+         break;
    }
 }
 
@@ -910,18 +854,25 @@ function tripal_analysis_kegg_nodeapi(&$node, $op, $teaser, $page) {
  */
 function tripal_analysis_kegg_theme () {
    return array(
-
       'tripal_analysis_kegg_search_index' => array (
          'arguments' => array('node'),
-   ),
+      ),
       'tripal_analysis_kegg_search_result' => array (
          'arguments' => array('node'),
-   ),
-      'tripal_analysis_kegg_node_add' => array (
-         'arguments' => array('node'),
-   )
+      ),
+      'tripal_organism_kegg_summary' => array (
+         'arguments' => array('node'=> null),
+         'template' => 'tripal_organism_kegg_summary',
+      ),
    );
 }
+/*******************************************************************************
+ *  
+ */
+function tripal_analysis_kegg_preprocess_tripal_organism_kegg_summary(&$variables){
+   $node = $variables['node'];
+   $variables['tripal_analysis_kegg']['select_form'] = tripal_analysis_kegg_load_organism_kegg_summary($node);
+}
 /************************************************************************
  */
 function theme_tripal_analysis_kegg_search_index($node){
@@ -993,7 +944,32 @@ function theme_tripal_analysis_kegg_search_result($node){
 
 /************************************************************************
  */
-function theme_tripal_analysis_kegg_node_add($node) {
+function tripal_analysis_kegg_load_organism_kegg_summary($node) {
+   $organism = $node->organism;
+
+   // find analyses that have KEGG terms
+   $sql = "
+     SELECT *
+     FROM {kegg_by_organism} KBO
+     WHERE organism_id = %d
+     ORDER BY analysis_id DESC
+   ";
+   $previous_db = tripal_db_set_active('chado');
+   $results = db_fetch_object(db_query($sql,$organism->organism_id));
+   tripal_db_set_active($previous_db);
+
+   $has_results = 0;
+   if($results){
+      $has_results = 1;
+   }
+   return array (
+      'has_results' => $has_results,
+      'form' => drupal_get_form('tripal_analysis_kegg_select_form',$node),
+   );
+}
+/************************************************************************
+ 
+
    // Show Kegg additional information on a KEGG Analysis page
    if ($node->type == 'chado_analysis_kegg') {
       return tripal_analysis_kegg_full_report($node->analysis_id);
@@ -1004,16 +980,8 @@ function theme_tripal_analysis_kegg_node_add($node) {
        return tripal_analysis_kegg_feature_add($node);
    } 
    
-   // Show Kegg full reports on the organism page
-   else if ($node->type == 'chado_organism') {
-      $box_status = variable_get("tripal_analysis_kegg-box-results","menu_off");
-      if (strcmp($box_status,"menu_off")==0){
-         $content .= tripal_analysis_kegg_organism_add($node);
-      }
-   }
    return $content;
 }
-/************************************************************************
  */
 
 function tripal_analysis_kegg_org_report($analysis_id){
@@ -1104,13 +1072,8 @@ function tripal_analysis_kegg_feature_add($node) {
       // Show kegg result ORDER BY time
       if ($hasResult) { // If there is any result, show expandable box
          $content .= "<div id=\"tripal_kegg-hits\" class=\"tripal_kegg-info-box\">
-                        <div class=\"tripal_expandableBox\">
-                          <h3>KEGG Analysis</h3>
-                        </div>
-                        <div class=\"tripal_expandableBoxContent\">
-                          <span>
-                            <table class=\"tripal_kegg_results_table\">
-                            <tr><td>";
+                        <table class=\"tripal_kegg_results_table\">
+                          <tr><td>";
 
          while ($ana = db_fetch_object($result)) {
             // Show analysis date
@@ -1141,61 +1104,17 @@ function tripal_analysis_kegg_feature_add($node) {
             }
             $content .= "<br>";
          }
-         $content .= '</td></tr></table></span></div></div>';
+         $content .= '</td></tr></table></div>';
       }
       tripal_db_set_active($previous_db);
    return $content;
 }
 /************************************************************************
 */
-function tripal_analysis_kegg_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_kegg-box-results","menu_off");
-      
-   if(strcmp($box_status,"menu_off")==0){
-      $content .= "
-      <div class=\"tripal_kegg_summary-info-box\">
-        <div class=\"tripal_expandableBox\">
-          <h3>KEGG Analysis Results</h3>
-        </div>
-        <div class=\"tripal_expandableBoxContent\">
-      ";
-   } 
-
-   $select_analysis = drupal_get_form('tripal_analysis_kegg_select_form',$node);
-
-   $url = url("sites/all/themes/theme_tripal/images/ajax-loader.gif");
-   $content .= "
-     $select_analysis
-     <div id=\"tripal_ajaxLoading\" style=\"display:none\">
-     <div id=\"loadingText\">Loading...</div>
-     <img src=\"$url\"></div>
-     <div id=\"tripal_analysis_kegg_org_report\"></div>
-   ";
-
-   if(user_access('access administrative pages')){
-      $link = url("tripal_toggle_box_menu/tripal_analysis_kegg/results/$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;
-}
-/************************************************************************
-*/
 function tripal_analysis_kegg_select_form(&$form_state = NULL,$node){
 
    $form = array();
-   // find analyses that have GO terms
+   // find analyses that have KEGG terms
    $sql = "
      SELECT *
      FROM {kegg_by_organism} KBO
@@ -1203,7 +1122,7 @@ function tripal_analysis_kegg_select_form(&$form_state = NULL,$node){
      ORDER BY analysis_id DESC
    ";
    $previous_db = tripal_db_set_active('chado');
-   $results = db_query($sql,$node->organism_id);
+   $results = db_query($sql,$node->organism->organism_id);
    tripal_db_set_active($previous_db);
 
    $analyses = array();

+ 0 - 10
tripal_analysis_unigene/tripal_analysis_unigene.module

@@ -82,13 +82,6 @@ function tripal_analysis_unigene_nodeapi(&$node, $op, $teaser, $page) {
 						'#weight' => 4,
                );
             } else {
-               if(strcmp($node->type,'chado_feature')==0){
-                  // Show unigene content if not at teaser view
-                  $node->content['tripal_analysis_unigene_node_addition'] = array(
-					   	'#value' => theme('tripal_analysis_unigene_feature_alignments', $node),
-						   '#weight' => 4
-                  );
-               }
 
                if(strcmp($node->type,'chado_organism')==0){
                   // Show unigene content if not at teaser view
@@ -114,9 +107,6 @@ function tripal_analysis_unigene_theme () {
       'tripal_analysis_unigene_search_result' => array (
          'arguments' => array('node'),
       ),
-      'tripal_analysis_unigene_feature_alignments' => array (
-         'arguments' => array('node'),
-      ),
       'tripal_analysis_unigene_node_add' => array (
          'arguments' => array('node'),
       ),

+ 0 - 3
tripal_cv/charts.php

@@ -1,8 +1,5 @@
 <?php
 
-//
-// Copyright 2009 Clemson University
-//
 
 /*************************************************************************
 *

+ 36 - 19
tripal_cv/trees.php

@@ -122,9 +122,9 @@ function tripal_cv_init_tree($cv_id,$cnt_table = null, $fk_column = null,
          if($count > 0){
             $name .= " ($count $label(s))";
          }
-      }
+      } 
       $content[] = array(
-        'attributes' => array (
+           'attributes' => array (
            'id' => $term->cvterm_id,
         ),
         state => 'closed',
@@ -188,25 +188,42 @@ function tripal_cv_get_term_children($cvterm_id,$cnt_table = null,
             $count += $cnt->num_items;
          }
          if($count > 0){
-             $name .= " (".number_format($count)." $label)";
+            $name .= " (".number_format($count)." $label)";
+            // check if we have any children if so then set the value
+            $previous_db = tripal_db_set_active('chado');
+            $children = db_fetch_object(db_query($sql,$term->subject_id));
+            tripal_db_set_active($previous_db);
+            $state = 'leaf';
+            if($children){
+               $state = 'closed';
+            }
+            $content[] = array(
+               'attributes' => array (
+                  'id' => $term->subject_id,
+               ),
+               state => $state,
+               data => $name,
+               children => array(),
+            );
          }
+      } else {
+         // check if we have any children if so then set the value
+         $previous_db = tripal_db_set_active('chado');
+         $children = db_fetch_object(db_query($sql,$term->subject_id));
+         tripal_db_set_active($previous_db);
+         $state = 'leaf';
+         if($children){
+            $state = 'closed';
+         }
+         $content[] = array(
+            'attributes' => array (
+               'id' => $term->subject_id,
+            ),
+            state => $state,
+            data => $name,
+            children => array(),
+         );
       }
-      // check if we have any children if so then set the value
-      $previous_db = tripal_db_set_active('chado');
-      $children = db_fetch_object(db_query($sql,$term->subject_id));
-      tripal_db_set_active($previous_db);
-      $state = 'leaf';
-      if($children){
-         $state = 'closed';
-      }
-      $content[] = array(
-         'attributes' => array (
-            'id' => $term->subject_id,
-         ),
-         state => $state,
-         data => $name,
-         children => array(),
-      );
    }
    $content[] = $cnt_sql;
    return $content;

+ 13 - 0
tripal_feature/tripal_feature.module

@@ -294,6 +294,11 @@ function tripal_feature_block($op = 'list', $delta = 0, $edit=array()){
          $blocks['relationships_as_subject']['info'] = t('Tripal Feature Relationships as Subject');
          $blocks['relationships_as_subject']['cache'] = BLOCK_NO_CACHE;
 
+         $blocks['org_feature_counts']['info'] = t('Tripal Organism Feature Counts');
+         $blocks['org_feature_counts']['cache'] = BLOCK_NO_CACHE;
+
+         $blocks['org_feature_browser']['info'] = t('Tripal Organism Feature Browser');
+         $blocks['org_feature_browser']['cache'] = BLOCK_NO_CACHE;
          return $blocks;
 
 
@@ -344,6 +349,14 @@ function tripal_feature_block($op = 'list', $delta = 0, $edit=array()){
                   $block['subject'] = t('Subject Relationships');
                   $block['content'] = theme('tripal_feature_relationships_as_child',$node);
                   break;
+               case 'org_feature_counts':
+                  $block['subject'] = t('Feature Type Summary');
+                  $block['content'] = theme('tripal_organism_feature_counts', $node);
+                  break;
+               case 'org_feature_browser':
+                  $block['subject'] = t('Feature Browser');
+                  $block['content'] = theme('tripal_organism_feature_browser', $node);
+                  break;
                default :
             }
             return $block;

+ 78 - 190
tripal_library/tripal_library.module

@@ -1,8 +1,5 @@
 <?php
 
-//
-// Copyright 2009 Clemson University
-//
 
 /*******************************************************************************
  * Display help and module information
@@ -121,15 +118,6 @@ function tripal_library_menu() {
       'type' => MENU_NORMAL_ITEM
    );
 
-   $items['node/%/libraries'] = array(
-     'title' => t('Libraries'),
-     'page callback' => 'get_tripal_library_organism_libraries',
-     'page arguments' => array(1),
-     'access callback' => 'tripal_library_node_has_menu',
-     'access arguments' => array('access chado_library content',1),
-     'type' => MENU_LOCAL_TASK | MENU_NORMAL_ITEM
-   );
-
    return $items;
 }
 
@@ -145,28 +133,6 @@ function tripal_library_views_api() {
    );
 }
 
-/*******************************************************************************
- * Dynamic addition/removal of menu item
- */
-function tripal_library_node_has_menu($type,$vid){
-   // 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);
-
-   // menu status
-   $box_status =variable_get("tripal_library-box-libraries","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;
-   }
-}
-
 /*************************************************************************
  * Purpose: Provide Guidance to new Tripal Admin
  *
@@ -231,37 +197,28 @@ function tripal_library_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
+      // node. 
       case 'view':
-         // Set the node types for showing library information
-         $types_to_show = array('chado_organism', 'chado_feature');
-
-         // Abort if this node is not one of the types we should show.
-         if (!in_array($node->type, $types_to_show, TRUE)) {
-            break;
-         }
-
-         // 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_library_index_version'] = array(
-						'#value' => theme('tripal_library_search_index',$node),
-						'#weight' => 4,
-               );
-            } else if ($node->build_mode == NODE_BUILD_SEARCH_RESULT) {
-               $node->content['tripal_library_index_version'] = array(
-						'#value' => theme('tripal_library_search_result',$node),
-						'#weight' => 4,
-               );
-            } else {
-               // Show library if the organism/feature is not at teaser view
-               $node->content['tripal_library_node_addition'] = array(
-						'#value' => theme('tripal_library_node_libraries', $node),
-						'#weight' => 4
-               );
+         // add the library to the organism/feature search indexing
+         if($node->build_mode == NODE_BUILD_SEARCH_INDEX){
+            $node->content['tripal_library_index_version'] = array(
+					'#value' => theme('tripal_library_search_index',$node),
+            );
+         } else if ($node->build_mode == NODE_BUILD_SEARCH_RESULT) {
+            $node->content['tripal_library_index_version'] = array(
+					'#value' => theme('tripal_library_search_result',$node),
+            );
+         } else {
+            switch($node->type){
+               case 'chado_organism':
+                  // Show library if the organism/feature is not at teaser view
+                  $node->content['tripal_organism_library_list'] = array(
+					      '#value' => theme('tripal_organism_library_list', $node),
+                  );
+                  break;
             }
          }
+         break;
    }
 }
 
@@ -272,54 +229,75 @@ function tripal_library_nodeapi(&$node, $op, $teaser, $page) {
  */
 function tripal_library_theme () {
    return array(
-   	  'tripal_library_library_table' => array (
+   	 'tripal_library_library_table' => array (
          'arguments' => array('libraries'),
-   ),
+      ),
       'tripal_library_search_index' => array (
          'arguments' => array('node'),
-   ),
+      ),
       'tripal_library_search_result' => array (
          'arguments' => array('node'),
-   ),
-      'tripal_library_node_libraries' => array (
-         'arguments' => array('node'),
-   )
+      ),
+      'tripal_organism_library_list' => array (
+         'arguments' => array('node'=> null),
+         'template' => 'tripal_organism_library_list',
+      )
    );
 }
-
+/*******************************************************************************
+ *  
+ */
+function tripal_library_preprocess_tripal_organism_library_list(&$variables){
+   $organism = $variables['node']->organism;
+   $variables['tripal_library']['libraries'] = tripal_library_load_organism_library_list($organism);
+}
 /************************************************************************
- * This function is an extension of the chado_feature_view and
- * chado_organism_view by providing the markup for the feature/organism object
- * to show on a search result page.
+ * 
  */
-function theme_tripal_library_search_result ($node) {
-   if ($node->type == 'chado_organism') {
-      $content = "";
-      // get the libraries for the organism
+function tripal_library_load_organism_library_list ($organism) {
+
+   // get the libraries for the organism
+   $sql = "SELECT L.library_id, L.organism_id, L.name, L.uniquename, ".
+          "   L.type_id, CVT.name as cvname, CVT.definition ".
+          "FROM {library} L ".
+          "  INNER JOIN CVTerm CVT ON CVT.cvterm_id = L.type_id ".
+    	  	 "WHERE L.Organism_id = %d";
+   $previous_db = tripal_db_set_active('chado');
+   $results = db_query($sql,$organism->organism_id);
+   tripal_db_set_active($previous_db);
+
+
+   // iterate through all of the libraries and add in the node and 
+   // library description
+   $nsql = "SELECT nid FROM {chado_feature} ".
+           "WHERE feature_id = %d";
+   $dsql = "SELECT * FROM {libraryprop} LP ".
+     	    "  INNER JOIN CVTerm CVT ON CVT.cvterm_id = LP.type_id ".
+          "WHERE LP.library_id = %d ".
+          "  AND CVT.name = 'library_description'";
+   $i=0;
+   $libraries = array();
+   while($library = db_fetch_object($results)){
+      // get the description
       $previous_db = tripal_db_set_active('chado');
-      $sql = "SELECT * FROM {library} L ".
-       	     "WHERE L.Organism_id = $node->organism_id";
-      $libraries = array();
-      $results = db_query($sql);
-      while($library = db_fetch_object($results)){
-         // get the description
-         $sql = "SELECT * FROM {libraryprop} LP ".
-           	    "  INNER JOIN CVTerm CVT ON CVT.cvterm_id = LP.type_id ".
-                "WHERE LP.library_id = $library->library_id ".
-                "  AND CVT.name = 'library_description'";
-         $desc = db_fetch_object(db_query($sql));
-         $library->description = $desc->value;
-         $libraries[] = $library;
-      }
+      $desc = db_fetch_object(db_query($dsql,$library->library_id));
       tripal_db_set_active($previous_db);
-      if(count($libraries) > 0){
-         foreach ($libraries as $library){
-            $content .= "Library: $library->name. ";
-            $content .= "$library->description";
-         };
-      }
-      // Provide library names to show in a feature page
-   } else if ($node->type == 'chado_feature') {
+      // get the node
+      $node = db_fetch_object(db_query($nsql,$feature->feature_id));
+      // add the description and the node to the library
+      $library->nid = $node->nid;
+      $library->description = $desc->value;
+      $libraries[$i++] = $library;
+   }
+
+   return $libraries;           
+}
+/************************************************************************
+ * 
+ */
+function tripal_library_load_feature_library_list ($feature) {
+
+
       $content = "";
       $organism_id = $node->feature->organism_id;
       $previous_db = tripal_db_set_active('chado');
@@ -338,7 +316,7 @@ function theme_tripal_library_search_result ($node) {
             $content .= "Library: ".$library->name;
          };
       }
-   }
+
    return $content;
 
 
@@ -447,96 +425,6 @@ function theme_tripal_library_node_libraries($node) {
    }
    return $content;
 }
-/************************************************************************
- *
- */
-function get_tripal_library_organism_libraries($nid) {
-      $content = "";
-
-      // if this content is intended to be a menu item the 
-      // we need to know so we can format the content slightly different
-      $box_status =variable_get("tripal_library-box-libraries","menu_off");
-
-      // get the organism id for this node
-      $sql = "SELECT organism_id FROM {chado_organism} WHERE nid = %d";
-      $organism_id = db_result(db_query($sql, $nid));
-
-      // get the libraries for the organism
-      $previous_db = tripal_db_set_active('chado');
-      $sql = "SELECT L.library_id, L.organism_id, L.name, L.uniquename, ".
-             "   L.type_id, CVT.name as cvname, CVT.definition ".
-             "FROM {library} L ".
-             "  INNER JOIN CVTerm CVT ON CVT.cvterm_id = L.type_id ".
-       	  	 "WHERE L.Organism_id = $organism_id";
-      $libraries = array();
-      $results = db_query($sql);
-      while($library = db_fetch_object($results)){
-         // get the description
-         $sql = "SELECT * FROM {libraryprop} LP ".
-           	    "  INNER JOIN CVTerm CVT ON CVT.cvterm_id = LP.type_id ".
-                "WHERE LP.library_id = $library->library_id ".
-                "  AND CVT.name = 'library_description'";
-         $desc = db_fetch_object(db_query($sql));
-         $library->description = $desc->value;
-         $libraries[] = $library;
-      }
-      tripal_db_set_active($previous_db);
-      
-      if(strcmp($box_status,"menu_off")==0){
-         $content .= "<div id=\"tripal_library_box\" class=\"tripal_library-info-box\">";
-         $content .= "<br><div class=\"tripal_expandableBox\">".
-       			  	 	"<h3>Libraries associated with this organism</h3>".
-                 	 	"</div>";
-         $content .= "<div class=\"tripal_expandableBoxContent\">";
-      } else {
-   	  $content .= "<h3>Libraries associated with this organism</h3>";
-      }
-      $content .= "<table class=\"organism-libraries\">";
-      if (count($libraries) > 0) {
-         $content .= "  <tr>";
-         $content .= "    <th class=\"dbfieldname\">Name</th>";
-         $content .= "    <th class=\"dbfieldname\">Description</th>";
-         $content .= "    <th class=\"dbfieldname\">Type</th>";
-         $content .= "  </tr>";
-         foreach ($libraries as $library){
-            $content .= "<tr>";
-            $sql = "SELECT nid FROM {chado_library} WHERE library_id = %d";
-            $lib_nid = db_result(db_query($sql, $library->library_id));
-            $lib_url = url("node/$lib_nid");
-            if ($lib_nid) {
-               $content .= "  <td><a href=\"$lib_url\">$library->name</a></td>";
-            } else {
-               $content .= "  <td>$library->name</td>";
-            }
-            $content .= "  <td>$library->description</td>";
-            if ($library->cvname == 'cdna_library') {
-               $display_lib = 'cDNA';
-            } else if ($library->cvname == 'bac_library') {
-               $display_lib = 'BAC';
-            } else {
-               $display_lib = $library->cvname;
-            }
-            $content .= "  <td>$display_lib</td>";
-            $content .= "</tr>";
-         }
-      } else {
-       	$content .= '<tr><td>There are no libraries available for this organism</td></tr>';
-      }
-      $content .= "</table>";
-      if(user_access('access administrative pages')){
-         $link = url("tripal_toggle_box_menu/tripal_library/libraries/$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;
-}
 
 /************************************************************************
  *