Browse Source

Many bug fixes, and theme updates

spficklin 14 years ago
parent
commit
e7ff3e0b80

+ 55 - 0
theme_tripal/css/tripal.css

@@ -106,3 +106,58 @@ table.tripal-table-horz .tripal-table-odd-row {
    padding: 10px;
    padding: 10px;
    background-color: #FFEEEE;
    background-color: #FFEEEE;
 }
 }
+
+.tripal_toc {
+  float: left;
+  width: 20%;
+  background-color: #EEEEEE;
+
+  -moz-border-radius: 15px;
+  -webkit-border-radius: 15px;
+  -khtml-border-radius: 15px;
+  border-radius: 15px;
+
+  -moz-box-shadow: 3px 3px 4px #888888;
+  -webkit-box-shadow: 3px 3px 4px #888888;
+  box-shadow: 3px 3px 4px #888888;
+
+
+
+  padding: 20px;
+  min-height: 500px;
+  border-style:solid;
+  border-width:1px;
+}
+.tripal_toc ul {
+ margin-left: 0px;
+ margin-top: 5px;
+ padding-left: 15px;
+}
+.tripal_toc_title {
+  font-size: 1.5em;
+  line-height: 110%;
+  padding-bottom: 10px;
+}
+.tripal_toc_desc {
+ /*font-style: italic; */
+}
+.tripal_details {
+  float: left;
+  width: 69%;
+  background-color: #FFFFFF;
+
+  -moz-border-radius: 15px;
+  -webkit-border-radius: 15px;
+  -khtml-border-radius: 15px;
+  border-radius: 15px;
+
+  -moz-box-shadow: 3px 3px 4px #888888;
+  -webkit-box-shadow: 3px 3px 4px #888888;
+  box-shadow: 3px 3px 4px #888888;
+  padding: 20px;
+  min-height: 500px;
+  margin-right: 10px;
+  margin-bottom: 10px;
+  border-style:solid;
+  border-width:1px;
+}

+ 10 - 0
theme_tripal/css/tripal_analysis_interpro.css

@@ -32,3 +32,13 @@
 .tripal_interpro_results_table tbody tr td table tr td{
 .tripal_interpro_results_table tbody tr td table tr td{
    background: #FFFFFF;
    background: #FFFFFF;
 }
 }
+/* feature node sepcific template */
+.tripal_feature_interpro-results-table {
+   padding-top: 10px;
+   padding-bottom: 10px;
+}
+.tripal_feature-interpro_results_subtitle{
+   padding-top: 10px;
+   padding-bottom: 10px;
+   font-weight: bold;
+}

+ 1 - 0
theme_tripal/css/tripal_feature.css

@@ -67,3 +67,4 @@ table.tripal_feature-references-table th {
    float: none;
    float: none;
    display: block;
    display: block;
 }
 }
+

+ 12 - 0
theme_tripal/css/tripal_organism.css

@@ -17,3 +17,15 @@
    clear: left;
    clear: left;
    width: auto;
    width: auto;
 }
 }
+
+#tripal_organism-base-box img {
+ float: left;
+ margin-bottom: 10px;
+}
+#tripal_organism-table-base {
+ float: left;
+ width: 330px;
+ margin-left: 10px;
+ margin-bottom: 10px;
+}
+

+ 3 - 0
theme_tripal/js/tripal.js

@@ -1,6 +1,7 @@
 
 
 
 
 if (Drupal.jsEnabled) {
 if (Drupal.jsEnabled) {
+
    //------------------------------------------------------------
    //------------------------------------------------------------
    // On document load we want to make sure the analysis result is shown
    // On document load we want to make sure the analysis result is shown
    var path = '';
    var path = '';
@@ -108,4 +109,6 @@ if (Drupal.jsEnabled) {
        }
        }
        return baseurl;
        return baseurl;
    }
    }
+
+   
 }
 }

+ 7 - 64
theme_tripal/node-chado_analysis.tpl.php

@@ -25,6 +25,8 @@
  //uncomment this line to see a full listing of the fields avail. to $node
  //uncomment this line to see a full listing of the fields avail. to $node
  //print '<pre>'.print_r($variables,TRUE).'</pre>';
  //print '<pre>'.print_r($variables,TRUE).'</pre>';
 
 
+drupal_add_css('./tripal-node-templates.css');
+
 $node = $variables['node'];
 $node = $variables['node'];
 $organism = $variables['node']->organism;
 $organism = $variables['node']->organism;
 ?>
 ?>
@@ -77,66 +79,7 @@ if (Drupal.jsEnabled) {
 }
 }
 </script>
 </script>
 
 
-<style type="text/css">
-  /* these styles are specific for this template and is not included 
-     in the main CSS files for the theme as it is anticipated that the
-     elements on this page may not be used for other customizations */
-  #tripal_analysis_toc {
-     float: left;
-     width: 20%;
-     background-color: #EEEEEE;
-     -moz-border-radius: 15px;
-     border-radius: 15px;
-     -moz-box-shadow: 3px 3px 4px #888888;
-	  -webkit-box-shadow: 3px 3px 4px #888888;
-	  box-shadow: 3px 3px 4px #888888;
-     padding: 20px;
-     min-height: 500px;
-     border-style:solid;
-     border-width:1px;
-  }
-  #tripal_analysis_toc ul {
-    margin-left: 0px;
-    margin-top: 5px;
-    padding-left: 15px;
-  }
-  #tripal_analysis_toc_title {
-     font-size: 1.5em;
-     line-height: 110%;
-  }
-  #tripal_analysis_toc_desc {
-    /*font-style: italic; */
-  }
-  #tripal_analysis_details {
-     float: left;
-     width: 70%;
-     background-color: #FFFFFF;
-     -moz-border-radius: 15px;
-     border-radius: 15px;
-     -moz-box-shadow: 3px 3px 4px #888888;
-	  -webkit-box-shadow: 3px 3px 4px #888888;
-	  box-shadow: 3px 3px 4px #888888;
-     padding: 20px;
-     min-height: 500px;
-     margin-right: 10px;
-     margin-bottom: 10px;
-     border-style:solid;
-     border-width:1px;
-  }
-  #tripal_analysis-base-box img {
-    float: left;
-    margin-bottom: 10px;
-  }
-  #tripal_analysis-table-base {
-    float: left;
-    width: 100%;
-    margin-left: 0px;
-    margin-bottom: 10px;
-  }
-</style>
-
-
-<div id="tripal_analysis_details">
+<div id="tripal_analysis_details" class="tripal_details">
 
 
    <!-- Basic Details Theme -->
    <!-- Basic Details Theme -->
    <?php include('tripal_analysis/tripal_analysis_base.tpl.php'); ?>
    <?php include('tripal_analysis/tripal_analysis_base.tpl.php'); ?>
@@ -145,10 +88,10 @@ if (Drupal.jsEnabled) {
 </div>
 </div>
 
 
 <!-- Table of contents -->
 <!-- Table of contents -->
-<div id="tripal_analysis_toc">
-   <div id="tripal_analysis_toc_title">Resources</i></div>
-   <span id="tripal_analysis_toc_desc">Select a link below for more information</span>
-   <ul id="tripal_analysis_toc_list">
+<div id="tripal_analysis_toc" class="tripal_toc">
+   <div id="tripal_analysis_toc_title" class="tripal_toc_title">Resources</i></div>
+   <span id="tripal_analysis_toc_desc" class="tripal_toc_desc">Select a link below for more information</span>
+   <ul id="tripal_analysis_toc_list"  class="tripal_toc_list">
 
 
    </ul>
    </ul>
 </div>
 </div>

+ 6 - 63
theme_tripal/node-chado_analysis_blast.tpl.php

@@ -24,6 +24,7 @@
 <?php
 <?php
  //uncomment this line to see a full listing of the fields avail. to $node
  //uncomment this line to see a full listing of the fields avail. to $node
  //print '<pre>'.print_r($variables,TRUE).'</pre>';
  //print '<pre>'.print_r($variables,TRUE).'</pre>';
+drupal_add_css('./tripal-node-templates.css');
 
 
 $node = $variables['node'];
 $node = $variables['node'];
 $organism = $variables['node']->organism;
 $organism = $variables['node']->organism;
@@ -76,66 +77,8 @@ if (Drupal.jsEnabled) {
 }
 }
 </script>
 </script>
 
 
-<style type="text/css">
-  /* these styles are specific for this template and is not included 
-     in the main CSS files for the theme as it is anticipated that the
-     elements on this page may not be used for other customizations */
-  #tripal_analysis_blast_toc {
-     float: left;
-     width: 20%;
-     background-color: #EEEEEE;
-     -moz-border-radius: 15px;
-     border-radius: 15px;
-     -moz-box-shadow: 3px 3px 4px #888888;
-	  -webkit-box-shadow: 3px 3px 4px #888888;
-	  box-shadow: 3px 3px 4px #888888;
-     padding: 20px;
-     min-height: 500px;
-     border-style:solid;
-     border-width:1px;
-  }
-  #tripal_analysis_blast_toc ul {
-    margin-left: 0px;
-    margin-top: 5px;
-    padding-left: 15px;
-  }
-  #tripal_analysis_blast_toc_title {
-     font-size: 1.5em;
-     line-height: 110%;
-  }
-  #tripal_analysis_blast_toc_desc {
-    /*font-style: italic; */
-  }
-  #tripal_analysis_blast_details {
-     float: left;
-     width: 70%;
-     background-color: #FFFFFF;
-     -moz-border-radius: 15px;
-     border-radius: 15px;
-     -moz-box-shadow: 3px 3px 4px #888888;
-	  -webkit-box-shadow: 3px 3px 4px #888888;
-	  box-shadow: 3px 3px 4px #888888;
-     padding: 20px;
-     min-height: 500px;
-     margin-right: 10px;
-     margin-bottom: 10px;
-     border-style:solid;
-     border-width:1px;
-  }
-  #tripal_analysis_blast-base-box img {
-    float: left;
-    margin-bottom: 10px;
-  }
-  #tripal_analysis_blast-table-base {
-    float: left;
-    width: 100%;
-    margin-left: 0px;
-    margin-bottom: 10px;
-  }
-</style>
 
 
-
-<div id="tripal_analysis_blast_details">
+<div id="tripal_analysis_blast_details" class="tripal_details">
 
 
    <!-- Basic Details Theme -->
    <!-- Basic Details Theme -->
    <?php include('tripal_analysis_blast/tripal_analysis_blast_base.tpl.php'); ?>
    <?php include('tripal_analysis_blast/tripal_analysis_blast_base.tpl.php'); ?>
@@ -144,10 +87,10 @@ if (Drupal.jsEnabled) {
 </div>
 </div>
 
 
 <!-- Table of contents -->
 <!-- Table of contents -->
-<div id="tripal_analysis_blast_toc">
-   <div id="tripal_analysis_blast_toc_title">Resources</i></div>
-   <span id="tripal_analysis_blast_toc_desc">Select a link below for more information</span>
-   <ul id="tripal_analysis_blast_toc_list">
+<div id="tripal_analysis_blast_toc" class="tripal_toc">
+   <div id="tripal_analysis_blast_toc_title" class="tripal_toc_title">Resources</i></div>
+   <span id="tripal_analysis_blast_toc_desc" class="tripal_toc_desc">Select a link below for more information</span>
+   <ul id="tripal_analysis_blast_toc_list" class="tripal_toc_list">
 
 
    </ul>
    </ul>
 </div>
 </div>

+ 93 - 65
theme_tripal/node-chado_analysis_interpro.tpl.php

@@ -1,70 +1,98 @@
 <?php
 <?php
+// Purpose: This template provides the layout of the organism node (page)
+//   using the same templates used for the various feature content blocks.
+//
+// To Customize the Featture Node Page:
+//   - This Template: customize basic layout and which elements are included
+//   - Using Panels: Override the node page using Panels3 and place the blocks
+//       of content as you please. This method requires no programming. See
+//       the Tripal User Guide for more details
+//   - Block Templates: customize the content/layout of each block of stock 
+//       content. These templates are found in the tripal_stock subdirectory
+//
+// Variables Available:
+//   - $node: a standard object which contains all the fields associated with
+//       nodes including nid, type, title, taxonomy. It also includes stock
+//       specific fields such as stock_name, uniquename, stock_type, synonyms,
+//       properties, db_references, object_relationships, subject_relationships,
+//       organism, etc.
+//   NOTE: For a full listing of fields available in the node object the
+//       print_r $node line below or install the Drupal Devel module which 
+//       provides an extra tab at the top of the node page labelled Devel
+?>
+
+<?php
+ //uncomment this line to see a full listing of the fields avail. to $node
+ //print '<pre>'.print_r($variables,TRUE).'</pre>';
+drupal_add_css('./tripal-node-templates.css');
 
 
+$node = $variables['node'];
+$organism = $variables['node']->organism;
 ?>
 ?>
 
 
-   <?php if ($picture) {
-      print $picture;
-   }?>
-    
-   <div class="node<?php if ($sticky) { print " sticky"; } ?><?php if (!$status) { print " node-unpublished"; } ?>">
+<?php if ($teaser) { 
+  include('tripal_analysis_interpro/tripal_analysis_interpro_teaser.tpl.php'); 
+} else { ?>
+
+<script type="text/javascript">
+if (Drupal.jsEnabled) {
+   $(document).ready(function() {
+      // hide all tripal info boxes at the start
+      $(".tripal-info-box").hide();
+ 
+      // iterate through all of the info boxes and add their titles
+      // to the table of contents
+      $(".tripal-info-box-title").each(function(){
+        var parent = $(this).parent();
+        var id = $(parent).attr('id');
+        var title = $(this).text();
+        $('#tripal_analysis_interpro_toc_list').append('<li><a href="#'+id+'" class="tripal_analysis_interpro_toc_item">'+title+'</a></li>');
+      });
+
+      // when a title in the table of contents is clicked, then
+      // show the corresponding item in the details box
+      $(".tripal_analysis_interpro_toc_item").click(function(){
+         $(".tripal-info-box").hide();
+         href = $(this).attr('href');
+         $(href).fadeIn('slow');
+         // we want to make sure our table of contents and the details
+         // box stay the same height
+         $("#tripal_analysis_interpro_toc").height($(href).parent().height());
+         return false;
+      }); 
+
+      // we want the base details to show up when the page is first shown 
+      // unless the user specified a specific block
+      var block = window.location.href.match(/\?block=.*/);
+      if(block != null){
+         block_title = block.toString().replace(/\?block=/g,'');
+         $("#tripal_analysis_interpro-"+block_title+"-box").show();
+      } else {
+         $("#tripal_analysis_interpro-base-box").show();
+      }
+
+      $("#tripal_analysis_interpro_toc").height($("#tripal_analysis_interpro-base-box").parent().height());
+      
+   });
+}
+</script>
+
+
+<div id="tripal_analysis_interpro_details" class="tripal_details">
+
+   <!-- Basic Details Theme -->
+   <?php include('tripal_analysis_interpro/tripal_analysis_interpro_base.tpl.php'); ?>
+
+   <?php print $content ?>
+</div>
+
+<!-- Table of contents -->
+<div id="tripal_analysis_interpro_toc" class="tripal_toc">
+   <div id="tripal_analysis_interpro_toc_title" class="tripal_toc_title">Resources</i></div>
+   <span id="tripal_analysis_interpro_toc_desc" class="tripal_toc_desc">Select a link below for more information</span>
+   <ul id="tripal_analysis_interpro_toc_list" class="tripal_toc_list">
+
+   </ul>
+</div>
 
 
-   <?php if ($page == 0) { ?><h2 class="nodeTitle"><a href="<?php print $node_url?>"><?php print $title?></a>
-	<?php global $base_url;
-	if ($sticky) { print '<img src="'.base_path(). drupal_get_path('theme','sanqreal').'/img/sticky.gif" alt="sticky icon" class="sticky" />'; } ?>
-	</h2><?php }; ?>
-    
-	<?php if (!$teaser): ?>
-	  <?php if ($submitted): ?>
-      <div class="metanode"><p><?php print t('') .'<span class="author">'. theme('username', $node).'</span>' . t(' - Posted on ') . '<span class="date">'.format_date($node->created, 'custom', "d F Y").'</span>'; ?></p></div>
-      <?php endif; ?>
-      <div>
-      <!-- tripal_analysis_interpro theme -->
-         <table>
-            <tr><th>Name</th><td><?php print $node->analysisname;?></td></tr>
-            <tr><th>Program (version)</th><td><?php print $node->program.' ('.$node->programversion.')';?></td></tr>
-            <?php
-               $ver = $node->sourceversion;
-               if ($node->sourceversion) {
-                  $ver = "($node->sourceversion)";
-               }
-               $date = preg_replace("/^(\d+-\d+-\d+) .*/","$1",$node->timeexecuted);
-            ?>
-            <tr><th>Source (version)</th><td><?php print $node->sourcename.' '.$ver;?></td></tr>
-            <tr><th>Source URI</th><td><?php print $node->sourceuri;?></td></tr>
-            <tr><th>Executed</th><td><?php print $date?></td></tr>
-            <tr><th>Description</th><td><?php print $node->description?></td></tr>
-            <tr><th>Interpro Settings</th>
-              <td>
-                <b>File:</b>
-                  <?php print preg_replace("/.*\/(.*)/", "$1", $node->interprofile); ?><br>
-                <b>Parameters:</b>
-                  <?php print $node->interproparameters?><br>
-                  <?php if ($node->interprojob) {
-                           print "A job for parsing interpro html output will be submitted.";
-                           if ($node->parsego) {
-                              print "<BR>GO terms will be parsed and stored.";
-                           }
-                        }
-                  ?>
-              </td>
-            </tr>
-         </table>
-      <!-- End of tripal_analysis_interpro theme-->
-	  </div> 
-    
-    <?php endif; ?>
-    
-    <div class="content"><?php print $content?></div>
-    
-    <?php if (!$teaser): ?>
-    <?php if ($links) { ?><div class="links"><?php print $links?></div><?php }; ?>
-    <?php endif; ?>
-    
-    <?php if ($teaser): ?>
-    <?php if ($links) { ?><div class="linksteaser"><div class="links"><?php print $links?></div></div><?php }; ?>
-    <?php endif; ?>
-    
-    <?php if (!$teaser): ?>
-    <?php if ($terms) { ?><div class="taxonomy"><span><?php print t('tags') ?></span> <?php print $terms?></div><?php } ?>
-    <?php endif; ?>
-  </div>
+<?php } ?>

+ 6 - 64
theme_tripal/node-chado_analysis_kegg.tpl.php

@@ -24,7 +24,7 @@
 <?php
 <?php
  //uncomment this line to see a full listing of the fields avail. to $node
  //uncomment this line to see a full listing of the fields avail. to $node
  //print '<pre>'.print_r($variables,TRUE).'</pre>';
  //print '<pre>'.print_r($variables,TRUE).'</pre>';
-
+drupal_add_css('./tripal-node-templates.css');
 $node = $variables['node'];
 $node = $variables['node'];
 $organism = $variables['node']->organism;
 $organism = $variables['node']->organism;
 ?>
 ?>
@@ -77,66 +77,8 @@ if (Drupal.jsEnabled) {
 }
 }
 </script>
 </script>
 
 
-<style type="text/css">
-  /* these styles are specific for this template and is not included 
-     in the main CSS files for the theme as it is anticipated that the
-     elements on this page may not be used for other customizations */
-  #tripal_analysis_kegg_toc {
-     float: left;
-     width: 20%;
-     background-color: #EEEEEE;
-     -moz-border-radius: 15px;
-     border-radius: 15px;
-     -moz-box-shadow: 3px 3px 4px #888888;
-	  -webkit-box-shadow: 3px 3px 4px #888888;
-	  box-shadow: 3px 3px 4px #888888;
-     padding: 20px;
-     min-height: 500px;
-     border-style:solid;
-     border-width:1px;
-  }
-  #tripal_analysis_kegg_toc ul {
-    margin-left: 0px;
-    margin-top: 5px;
-    padding-left: 15px;
-  }
-  #tripal_analysis_kegg_toc_title {
-     font-size: 1.5em;
-     line-height: 110%;
-  }
-  #tripal_analysis_kegg_toc_desc {
-    /*font-style: italic; */
-  }
-  #tripal_analysis_kegg_details {
-     float: left;
-     width: 70%;
-     background-color: #FFFFFF;
-     -moz-border-radius: 15px;
-     border-radius: 15px;
-     -moz-box-shadow: 3px 3px 4px #888888;
-	  -webkit-box-shadow: 3px 3px 4px #888888;
-	  box-shadow: 3px 3px 4px #888888;
-     padding: 20px;
-     min-height: 500px;
-     margin-right: 10px;
-     margin-bottom: 10px;
-     border-style:solid;
-     border-width:1px;
-  }
-  #tripal_analysis_kegg-base-box img {
-    float: left;
-    margin-bottom: 10px;
-  }
-  #tripal_analysis_kegg-table-base {
-    float: left;
-    width: 100%;
-    margin-left: 0px;
-    margin-bottom: 10px;
-  }
-</style>
-
 
 
-<div id="tripal_analysis_kegg_details">
+<div id="tripal_analysis_kegg_details" class="tripal_details">
 
 
    <!-- Basic Details Theme -->
    <!-- Basic Details Theme -->
    <?php include('tripal_analysis_kegg/tripal_analysis_kegg_base.tpl.php'); ?>
    <?php include('tripal_analysis_kegg/tripal_analysis_kegg_base.tpl.php'); ?>
@@ -146,10 +88,10 @@ if (Drupal.jsEnabled) {
 </div>
 </div>
 
 
 <!-- Table of contents -->
 <!-- Table of contents -->
-<div id="tripal_analysis_kegg_toc">
-   <div id="tripal_analysis_kegg_toc_title">Resources</i></div>
-   <span id="tripal_analysis_kegg_toc_desc">Select a link below for more information</span>
-   <ul id="tripal_analysis_kegg_toc_list">
+<div id="tripal_analysis_kegg_toc" class="tripal_toc">
+   <div id="tripal_analysis_kegg_toc_title" class="tripal_toc_title">Resources</i></div>
+   <span id="tripal_analysis_kegg_toc_desc" class="tripal_toc_desc">Select a link below for more information</span>
+   <ul id="tripal_analysis_kegg_toc_list" class="tripal_toc_list">
 
 
    </ul>
    </ul>
 </div>
 </div>

+ 6 - 65
theme_tripal/node-chado_analysis_unigene.tpl.php

@@ -24,7 +24,7 @@
 <?php
 <?php
  //uncomment this line to see a full listing of the fields avail. to $node
  //uncomment this line to see a full listing of the fields avail. to $node
 // print '<pre>'.print_r($node,TRUE).'</pre>';
 // print '<pre>'.print_r($node,TRUE).'</pre>';
-
+drupal_add_css('./tripal-node-templates.css');
 $node = $variables['node'];
 $node = $variables['node'];
 $analysis = $variables['node']->analysis;
 $analysis = $variables['node']->analysis;
 $unigene_name = $analysis->tripal_analysis_unigene->unigene_name;
 $unigene_name = $analysis->tripal_analysis_unigene->unigene_name;
@@ -81,66 +81,7 @@ if (Drupal.jsEnabled) {
 }
 }
 </script>
 </script>
 
 
-<style type="text/css">
-  /* these styles are specific for this template and is not included 
-     in the main CSS files for the theme as it is anticipated that the
-     elements on this page may not be used for other customizations */
-  #tripal_analysis_unigene_toc {
-     float: left;
-     width: 20%;
-     background-color: #EEEEEE;
-     -moz-border-radius: 15px;
-     border-radius: 15px;
-     -moz-box-shadow: 3px 3px 4px #888888;
-	  -webkit-box-shadow: 3px 3px 4px #888888;
-	  box-shadow: 3px 3px 4px #888888;
-     padding: 20px;
-     min-height: 500px;
-     border-style:solid;
-     border-width:1px;
-  }
-  #tripal_analysis_unigene_toc ul {
-    margin-left: 0px;
-    margin-top: 5px;
-    padding-left: 15px;
-  }
-  #tripal_analysis_unigene_toc_title {
-     font-size: 1.5em;
-     line-height: 110%;
-  }
-  #tripal_analysis_unigene_toc_desc {
-    font-style: italic;
-  }
-  #tripal_analysis_unigene_details {
-     float: left;
-     width: 70%;
-     background-color: #FFFFFF;
-     -moz-border-radius: 15px;
-     border-radius: 15px;
-     -moz-box-shadow: 3px 3px 4px #888888;
-	  -webkit-box-shadow: 3px 3px 4px #888888;
-	  box-shadow: 3px 3px 4px #888888;
-     padding: 20px;
-     min-height: 500px;
-     margin-right: 10px;
-     margin-bottom: 10px;
-     border-style:solid;
-     border-width:1px;
-  }
-  #tripal_analysis_unigene-base-box img {
-    float: left;
-    margin-bottom: 10px;
-  }
-  #tripal_analysis_unigene-table-base {
-    float: left;
-    width: 100%;
-    margin-left: 0px;
-    margin-bottom: 10px;
-  }
-</style>
-
-
-<div id="tripal_analysis_unigene_details">
+<div id="tripal_analysis_unigene_details" class="tripal_details">
 
 
    <!-- Basic Details Theme -->
    <!-- Basic Details Theme -->
    <?php include('tripal_analysis_unigene/tripal_analysis_unigene_base.tpl.php'); ?>
    <?php include('tripal_analysis_unigene/tripal_analysis_unigene_base.tpl.php'); ?>
@@ -149,10 +90,10 @@ if (Drupal.jsEnabled) {
 </div>
 </div>
 
 
 <!-- Table of contents -->
 <!-- Table of contents -->
-<div id="tripal_analysis_unigene_toc">
-   <div id="tripal_analysis_unigene_toc_title">Resources for Unigene <?php print $unigene_name ?></div>
-   <span id="tripal_analysis_unigene_toc_desc">Select a link below for more information</span>
-   <ul id="tripal_analysis_unigene_toc_list">
+<div id="tripal_analysis_unigene_toc" class="tripal_toc">
+   <div id="tripal_analysis_unigene_toc_title" class="tripal_toc_title">Resources for Unigene <?php print $unigene_name ?></div>
+   <span id="tripal_analysis_unigene_toc_desc" class="tripal_toc_desc">Select a link below for more information</span>
+   <ul id="tripal_analysis_unigene_toc_list" class="tripal_toc_list">
 
 
    </ul>
    </ul>
 </div>
 </div>

+ 6 - 54
theme_tripal/node-chado_feature.tpl.php

@@ -24,6 +24,7 @@
 <?php
 <?php
  //uncomment this line to see a full listing of the fields avail. to $node
  //uncomment this line to see a full listing of the fields avail. to $node
  //print '<pre>'.print_r($variables,TRUE).'</pre>';
  //print '<pre>'.print_r($variables,TRUE).'</pre>';
+drupal_add_css('./tripal-node-templates.css');
 $feature  = $variables['node']->feature;
 $feature  = $variables['node']->feature;
 ?>
 ?>
 
 
@@ -73,56 +74,7 @@ if (Drupal.jsEnabled) {
 }
 }
 </script>
 </script>
 
 
-<style type="text/css">
-  /* these styles are specific for this template and is not included 
-     in the main CSS files for the theme as it is anticipated that the
-     elements on this page may not be used for other customizations */
-  #tripal_feature_toc {
-     float: left;
-     width: 20%;
-     background-color: #EEEEEE;
-     -moz-border-radius: 15px;
-     border-radius: 15px;
-     -moz-box-shadow: 3px 3px 4px #888888;
-	  -webkit-box-shadow: 3px 3px 4px #888888;
-	  box-shadow: 3px 3px 4px #888888;
-     padding: 20px;
-     min-height: 500px;
-     border-style:solid;
-     border-width:1px;
-  }
-  #tripal_feature_toc ul {
-    margin-left: 0px;
-    margin-top: 5px;
-    padding-left: 15px;
-  }
-  #tripal_feature_toc_title {
-     font-size: 1.5em;
-     line-height: 110%;
-  }
-  #tripal_feature_toc_desc {
-    font-style: italic;
-  }
-  #tripal_feature_details {
-     float: left;
-     width: 70%;
-     background-color: #FFFFFF;
-     -moz-border-radius: 15px;
-     border-radius: 15px;
-     -moz-box-shadow: 3px 3px 4px #888888;
-	  -webkit-box-shadow: 3px 3px 4px #888888;
-	  box-shadow: 3px 3px 4px #888888;
-     padding: 20px;
-     min-height: 500px;
-     margin-right: 10px;
-     margin-bottom: 10px;
-     border-style:solid;
-     border-width:1px;
-  }
-</style>
-
-
-<div id="tripal_feature_details">
+<div id="tripal_feature_details" class="tripal_details">
 
 
    <!-- Basic Details Theme -->
    <!-- Basic Details Theme -->
    <?php include('tripal_feature/tripal_feature_base.tpl.php'); ?>
    <?php include('tripal_feature/tripal_feature_base.tpl.php'); ?>
@@ -158,10 +110,10 @@ if (Drupal.jsEnabled) {
 </div>
 </div>
 
 
 <!-- Table of contents -->
 <!-- Table of contents -->
-<div id="tripal_feature_toc">
-   <div id="tripal_feature_toc_title">Resources for <?php print $feature->cvname?><br><?php print $feature->featurename ?></div>
-   <span id="tripal_feature_toc_desc">Select a link below for more information</span>
-   <ul id="tripal_feature_toc_list">
+<div id="tripal_feature_toc" class="tripal_toc">
+   <div id="tripal_feature_toc_title" class="tripal_toc_title">Resources for <?php print $feature->cvname?><br><?php print $feature->featurename ?></div>
+   <span id="tripal_feature_toc_desc" class="tripal_toc_desc">Select a link below for more information</span>
+   <ul id="tripal_feature_toc_list" class="tripal_toc_list">
 
 
    </ul>
    </ul>
 </div>
 </div>

+ 1 - 3
theme_tripal/node-chado_library.tpl.php

@@ -1,7 +1,5 @@
 <?php
 <?php
-/*
- Copyright 2009 Clemson University
-*/
+
 ?>
 ?>
 
 
    <?php if ($picture) { print $picture; }?>
    <?php if ($picture) { print $picture; }?>

+ 6 - 63
theme_tripal/node-chado_organism.tpl.php

@@ -24,7 +24,7 @@
 <?php
 <?php
  //uncomment this line to see a full listing of the fields avail. to $node
  //uncomment this line to see a full listing of the fields avail. to $node
  //print '<pre>'.print_r($variables,TRUE).'</pre>';
  //print '<pre>'.print_r($variables,TRUE).'</pre>';
-
+drupal_add_css('./tripal-node-templates.css');
 $node = $variables['node'];
 $node = $variables['node'];
 $organism = $variables['node']->organism;
 $organism = $variables['node']->organism;
 ?>
 ?>
@@ -79,66 +79,9 @@ if (Drupal.jsEnabled) {
 }
 }
 </script>
 </script>
 
 
-<style type="text/css">
-  /* these styles are specific for this template and is not included 
-     in the main CSS files for the theme as it is anticipated that the
-     elements on this page may not be used for other customizations */
-  #tripal_organism_toc {
-     float: left;
-     width: 20%;
-     background-color: #EEEEEE;
-     -moz-border-radius: 15px;
-     border-radius: 15px;
-     -moz-box-shadow: 3px 3px 4px #888888;
-	  -webkit-box-shadow: 3px 3px 4px #888888;
-	  box-shadow: 3px 3px 4px #888888;
-     padding: 20px;
-     min-height: 500px;
-     border-style:solid;
-     border-width:1px;
-  }
-  #tripal_organism_toc ul {
-    margin-left: 0px;
-    margin-top: 5px;
-    padding-left: 15px;
-  }
-  #tripal_organism_toc_title {
-     font-size: 1.5em;
-     line-height: 110%;
-  }
-  #tripal_organism_toc_desc {
-    /*font-style: italic; */
-  }
-  #tripal_organism_details {
-     float: left;
-     width: 70%;
-     background-color: #FFFFFF;
-     -moz-border-radius: 15px;
-     border-radius: 15px;
-     -moz-box-shadow: 3px 3px 4px #888888;
-	  -webkit-box-shadow: 3px 3px 4px #888888;
-	  box-shadow: 3px 3px 4px #888888;
-     padding: 20px;
-     min-height: 500px;
-     margin-right: 10px;
-     margin-bottom: 10px;
-     border-style:solid;
-     border-width:1px;
-  }
-  #tripal_organism-base-box img {
-    float: left;
-    margin-bottom: 10px;
-  }
-  #tripal_organism-table-base {
-    float: left;
-    width: 330px;
-    margin-left: 10px;
-    margin-bottom: 10px;
-  }
-</style>
 
 
 
 
-<div id="tripal_organism_details">
+<div id="tripal_organism_details" class="tripal_details">
 
 
    <!-- Basic Details Theme -->
    <!-- Basic Details Theme -->
    <?php include('tripal_organism/tripal_organism_base.tpl.php'); ?>
    <?php include('tripal_organism/tripal_organism_base.tpl.php'); ?>
@@ -147,10 +90,10 @@ if (Drupal.jsEnabled) {
 </div>
 </div>
 
 
 <!-- Table of contents -->
 <!-- Table of contents -->
-<div id="tripal_organism_toc">
-   <div id="tripal_organism_toc_title">Resources for <br><i><?php print $organism->genus ?> <?php print $organism->species ?></i></div>
-   <span id="tripal_organism_toc_desc">Select a link below for more information</span>
-   <ul id="tripal_organism_toc_list">
+<div id="tripal_organism_toc" class="tripal_toc">
+   <div id="tripal_organism_toc_title" class="tripal_toc_title">Resources for <br><i><?php print $organism->genus ?> <?php print $organism->species ?></i></div>
+   <span id="tripal_organism_toc_desc" class="tripal_toc_desc">Select a link below for more information</span>
+   <ul id="tripal_organism_toc_list" class="tripal_toc_list">
 
 
    </ul>
    </ul>
 </div>
 </div>

+ 6 - 5
theme_tripal/node-chado_stock.tpl.php

@@ -26,6 +26,7 @@
 <?php
 <?php
  //uncomment this line to see a full listing of the fields avail. to $node
  //uncomment this line to see a full listing of the fields avail. to $node
  //print '<pre>'.print_r($node,TRUE).'</pre>';
  //print '<pre>'.print_r($node,TRUE).'</pre>';
+drupal_add_css('./tripal-node-templates.css');
 ?>
 ?>
 
 
 <?php if ($teaser) { 
 <?php if ($teaser) { 
@@ -130,7 +131,7 @@
   }
   }
 </style>
 </style>
 
 
-<div id="tripal_stock_details">
+<div id="tripal_stock_details" class="tripal_details">
 
 
   <!-- Base Theme -->
   <!-- Base Theme -->
   <?php include('tripal_stock/tripal_stock_base.tpl.php'); ?>
   <?php include('tripal_stock/tripal_stock_base.tpl.php'); ?>
@@ -152,10 +153,10 @@
 </div>
 </div>
 
 
 <!-- Table of contents -->
 <!-- Table of contents -->
-<div id="tripal_stock_toc">
-   <div id="tripal_stock_toc_title"><?php print $node->stock_name ?></div>
-   <span id="tripal_stock_toc_desc">Select a link below for more information</span>
-   <ul id="tripal_stock_toc_list">
+<div id="tripal_stock_toc" class="tripal_toc">
+   <div id="tripal_stock_toc_title" class="tripal_toc_title"><?php print $node->stock_name ?></div>
+   <span id="tripal_stock_toc_desc" class="tripal_toc_desc">Select a link below for more information</span>
+   <ul id="tripal_stock_toc_list" class="tripal_toc_list">
 
 
    </ul>
    </ul>
 </div>
 </div>

+ 0 - 0
theme_tripal/tripal-node-templates.css


+ 54 - 0
theme_tripal/tripal_analysis_interpro/tripal_analysis_interpro_base.tpl.php

@@ -0,0 +1,54 @@
+<?php
+$node = $variables['node'];
+$analysis = $variables['node']->analysis;
+$interpro = $node->analysis->tripal_analysis_interpro;
+
+?>
+<div id="tripal_analysis_interpro-base-box" class="tripal_analysis_interpro-info-box tripal-info-box">
+  <div class="tripal_analysis_interpro-info-box-title tripal-info-box-title">Details</div>
+   <table id="tripal_analysis_interpro-table-base" class="tripal_analysis_interpro-table tripal-table tripal-table-vert">
+      <tr class="tripal_analysis_interpro-table-even-row tripal-table-even-row">
+        <th>Analysis Name</th>
+        <td><?php print $analysis->name; ?></td>
+      </tr>
+      <tr class="tripal_analysis_interpro-table-odd-row tripal-table-odd-row">
+        <th nowrap>Software</th>
+        <td><?php 
+          print $analysis->program; 
+          if($analysis->programversion){
+             print " (" . $analysis->programversion . ")"; 
+          }
+          if($analysis->algorithm){
+             print ". " . $analysis->algorithm; 
+          }
+          ?>
+        </td>
+      </tr>
+      <tr class="tripal_analysis_interpro-table-even-row tripal-table-even-row">
+        <th nowrap>Source</th>
+        <td><?php 
+          if($analysis->sourceuri){
+             print "<a href=\"$analysis->sourceuri\">$analysis->sourcename</a>"; 
+          } else {
+             print $analysis->sourcename; 
+          }
+          if($analysis->sourceversion){
+             print " (" . $analysis->sourceversion . ")"; 
+          }
+          ?>
+          </td>
+      </tr>
+      <tr class="tripal_analysis_interpro-table-odd-row tripal-table-odd-row">
+        <th nowrap>Date performed</th>
+        <td><?php print preg_replace("/^(\d+-\d+-\d+) .*/","$1",$analysis->timeexecuted); ?></td>
+      </tr>
+      <tr class="tripal_analysis_interpro-table-even-row tripal-table-even-row">
+        <th nowrap>Description</th>
+        <td><?php print $analysis->description; ?></td>
+      </tr>      
+      <tr class="tripal_analysis_interpro-table-odd-row tripal-table-odd-row">
+        <th nowrap>InterProScan Arguments</th>
+        <td><?php print $interpro->interproparameters ?></td>
+      </tr>        	                                
+   </table>   
+</div>

+ 100 - 9
theme_tripal/tripal_feature/tripal_feature_interpro_results.tpl.php

@@ -1,13 +1,104 @@
 <?php
 <?php
 $results = $variables['tripal_analysis_interpro']['results'];
 $results = $variables['tripal_analysis_interpro']['results'];
+$feature  = $variables['node']->feature;
+//dpm($results);
+if($feature->cvname != 'gene' and count($results) > 0){ 
+   $i = 0;
+   foreach($results as $analysis_id => $analysisprops){ 
+     $analysis = $analysisprops['analysis'];
+     $protein_ORFs = $analysisprops['protein_ORFs']; 
+     $terms = $analysisprops['allterms']; 
+     ?>
+     <div id="tripal_feature-interpro_results_<?php print $i?>-box" class="tripal_analysis_interpro-box tripal-info-box">
+        <div class="tripal_feature-info-box-title tripal-info-box-title">InterPro Report <?php print preg_replace("/^(\d+-\d+-\d+) .*/","$1",$analysis->timeexecuted); ?></div>
+        <div class="tripal_feature-info-box-desc tripal-info-box-desc"><?php 
+            if($analysis->nid){ ?>
+               Analysis name: <a href="<?php print url('node/'.$analysis->nid) ?>"><?php print $analysis->name?></a><?php
+            } else { ?>
+               Analysis name: <?php print $analysis->name;
+            } ?><br>
+            Date Performed: <?php print preg_replace("/^(\d+-\d+-\d+) .*/","$1",$analysis->timeexecuted); ?>
+        </div>
+
+     <div class="tripal_feature-interpro_results_subtitle">Summary of Annotated IPR terms</div>
+     <table id="tripal_feature-interpro_summary-<?php $i ?>-table" class="tripal_analysis_interpro-summary-table tripal-table tripal-table-horz">
+      <tr>
+        <th>Term</td>
+        <th>Name</td>
+      </tr>
+     <?php 
+     $j=0;
+     foreach($terms as $term){ 
+       $ipr_id = $term[0];
+       $ipr_name = $term[1];
+       $class = 'tripal_feature-table-odd-row tripal-table-odd-row';
+       if($j % 2 == 0 ){
+         $class = 'tripal_feature-table-even-row tripal-table-even-row';
+       }?>
+       <tr class="<?php print $class ?>">
+         <td><?php print $ipr_id ?></td>
+         <td><?php print $ipr_name ?></td>         
+       </tr>
+       <?php
+       $j++;
+     } ?>
+     </table>
+     <br><br>
+     <div class="tripal_feature-interpro_results_subtitle">Analysis Details</div>
+     <table id="tripal_feature-interpro_results-<?php $i ?>-table" class="tripal-table tripal_feature_interpro-results-table tripal-table-horz" style="border-top: 0px; border-bottom: 0px">
+     <?php
+     foreach($protein_ORFs as $orf){  
+        $terms = $orf['terms'];
+        $orf = $orf['orf'];  
+        ?>
+        <?php foreach($terms as $term){ 
+          $matches = $term['matches'];
+          $ipr_id = $term['ipr_id'];
+          $ipr_name = $term['ipr_name'];
+          $ipr_type = $term['ipr_type']; ?>          
+            <tr>
+              <td colspan="4" style="padding-left: 0px">ORF: <?php print $orf['orf_id'] ?>, Length: <?php print $orf['orf_length'] ?> <br>
+                              IPR Term: <?php print "$ipr_id $ipr_name ($ipr_type)"; ?></th>
+            </tr>
+            <tr style="border-top: solid 1px;">
+              <th>Method</th>
+              <th>Identifier</th>
+              <th>Description</th>
+              <th>Matches</th>
+            </tr>
+            <?php $j = 0; 
+            foreach ($matches as $match){
+               $match_id = $match['match_id'];
+               $match_name = $match['match_name'];
+               $match_dbname = $match['match_dbname'];
+               $match_start = $match['match_start'];
+               $match_end = $match['match_end'];
+               $match_score = $match['match_score'];
+               $match_status = $match['match_status'];
+               $match_evidence =  $match['match_evidence'];
+
+               $class = 'tripal_feature-table-odd-row tripal-table-odd-row';
+               if($j % 2 == 0 ){
+                  $class = 'tripal_feature-table-even-row tripal-table-even-row';
+               }?>
+               <tr class="<?php print $class ?>">
+                <td><?php print $match_dbname ?></td>
+                <td><?php print $match_id ?></td>
+                <td><?php print $match_name ?></td>
+                <td nowrap>Score: <?php print $match_score ?> <br>
+                    Position: <?php print $match_start ?>..<?php print $match_end ?><br>
+                    Status: <?php print $match_status ?></td>
+               </tr>
+               <?php
+               $j++;  
+            } // end foreach matches ?>
+            <tr><td colspan="4">&nbsp;</td></tr> <?php
+        } // end foreach terms
+        $i++;
+     } // end foreach orfs ?>
+     </table>
+     </div> <?php
+   } // end for each analysis 
+} // end if
 ?>
 ?>
 
 
-<div id="tripal_feature-interpro_results-box" class="tripal_analysis_interpro-box tripal-info-box">
-  <div class="tripal_feature-info-box-title tripal-info-box-title">InterPro Report</div>
-  <div class="tripal_feature-info-box-desc tripal-info-box-desc"></div>
-  <?php if($results){?>
-     <?php print $results ?>
-  <?php } else { ?>
-    <div class="tripal-no-results">There is no InterPro report for this feature</div> 
-  <?php }?>
-</div>

+ 44 - 0
theme_tripal/tripal_feature/tripal_feature_kegg_terms.tpl.php

@@ -0,0 +1,44 @@
+<?php
+$results = $variables['tripal_analysis_kegg']['results'];
+$feature  = $variables['node']->feature;
+if($feature->cvname != 'gene' and count($results) > 0){ 
+   $i = 0;
+   foreach($results as $analysis_id => $analysisprops){ 
+     $analysis = $analysisprops['analysis'];
+     $terms = $analysisprops['terms']; 
+     ?>
+     <div id="tripal_feature-kegg_results_<?php print $i?>-box" class="tripal_analysis_kegg-box tripal-info-box">
+        <div class="tripal_feature-info-box-title tripal-info-box-title">KEGG Report <?php print preg_replace("/^(\d+-\d+-\d+) .*/","$1",$analysis->timeexecuted); ?></div>
+        <div class="tripal_feature-info-box-desc tripal-info-box-desc"><?php 
+            if($analysis->nid){ ?>
+               Analysis name: <a href="<?php print url('node/'.$analysis->nid) ?>"><?php print $analysis->name?></a><?php
+            } else { ?>
+               Analysis name: <?php print $analysis->name;
+            } ?><br>
+            Date Performed: <?php print preg_replace("/^(\d+-\d+-\d+) .*/","$1",$analysis->timeexecuted); ?>
+        </div>
+
+     <div class="tripal_feature-kegg_results_subtitle">Annotated Terms</div>
+     <table id="tripal_feature-kegg_summary-<?php $i ?>-table" class="tripal_analysis_kegg-summary-table tripal-table tripal-table-horz">
+     <?php 
+     $j=0;
+     foreach($terms as $term){ 
+       $ipr_id = $term[0];
+       $ipr_name = $term[1];
+       $class = 'tripal_feature-table-odd-row tripal-table-odd-row';
+       if($j % 2 == 0 ){
+         $class = 'tripal_feature-table-even-row tripal-table-even-row';
+       }?>
+       <tr class="<?php print $class ?>">
+         <td><?php print $term ?></td>
+       </tr>
+       <?php
+       $j++;
+     } ?>
+     </table>     
+     </div> <?php
+     $i++;
+   } // end for each analysis 
+} // end if
+?>
+

+ 516 - 0
tripal_analysis_interpro/parseInterpro.inc

@@ -0,0 +1,516 @@
+<?php
+
+/*******************************************************************************
+ * Parse Interpro HTML Output file into analysisfeatureprop table
+ */
+function tripal_analysis_interpro_parseHTMLFile ($analysis_id, $interprofile, $parsego, $job_id) {
+
+	// Prepare log
+	$filename = preg_replace("/.*\/(.*)/", "$1", $interprofile);
+	$logfile = file_directory_path() . "/tripal/tripal_analysis_interpro/load_$filename.log";
+	$log = fopen($logfile, 'a'); // append parsing results to log file
+
+	// Parsing started
+	print "Parsing File:".$interprofile." ...\n";
+	fwrite($log, date("D M j G:i:s Y").". Loading $interprofile\n");
+
+	// Get cvterm_id for 'analysis_interpro_output_iteration_hits' which is required
+	// for inserting into the analysisfeatureprop table
+	$previous_db = tripal_db_set_active('chado'); // use chado database
+	$sql = "SELECT CVT.cvterm_id FROM {cvterm} CVT ".
+          "INNER JOIN cv ON cv.cv_id = CVT.cv_id ".
+          "WHERE CVT.name = 'analysis_interpro_output_hit' ".
+          "AND CV.name = 'tripal'";
+	$type_id = db_result(db_query($sql));
+	print "cvterm_id for analysis_interpro_output_iteration_hits is $type_id\n";
+
+	// Load the HTML file and convert it into XML for loading
+	$dom = new domDocument;
+	$dom->loadHTMLFile($interprofile);
+	$xml = $dom->saveXML();
+	$interproput = simplexml_load_string($xml);
+
+	// Get html tables for parsing
+	$tables = $interproput->children()->children();
+
+	// Count the number of tables to be processed
+	$no_iterations = 0;
+	foreach($tables as $tmp) {
+		if ($tmp->getName() == 'table') {
+			$no_iterations ++;
+		}
+	}
+	print "$no_iterations html tables to be processed.\n";
+	$interval = intval($no_iterations * 0.01);
+	$idx_iterations = 0;
+
+	// Processed the tables
+	foreach ($tables as $table) {
+        //if (preg_match('/No hits reported/', $table->asXML()) ) {
+            //print "skipping this table b/c no hits are reported\n";
+        //}
+        // make sure we are looking at a table and its not an empty table
+        if ($table->getName() == 'table' && !preg_match('/No hits reported/', $table->asXML()) ) {
+            $idx_iterations ++;
+            if ($idx_iterations % $interval == 0) {
+                    $percentage = (int) ($idx_iterations / $no_iterations * 100);
+                    tripal_db_set_active($previous_db);
+                    tripal_job_set_progress($job_id, $percentage);
+                    $previous_db = tripal_db_set_active('chado');
+                    print $percentage."% ";
+            }
+
+            // Set job status
+            // Get the first row and match its name with the feature name
+            $firsttd = $table->children()->children()->children();
+            $feature_id = 0;
+            foreach($firsttd as $b) {
+                foreach($b->children() as $a) {
+                    if ($a->getName() == 'a') {
+                        // Remove _ORF from the sequence name
+                        $seqname = preg_replace('/^(.+?)_\d_.+/', "$1", $a);
+                        print "seqname is $seqname\n";
+    
+                        // Find out how many features match this uniquename
+                        $sql = "SELECT count(feature_id) FROM {feature} ".
+                        "WHERE uniquename = '%s' ";
+                        $no_features = db_result(db_query($sql, $seqname));
+						    
+                        // If there is only one match, get the feature_id
+                        if ($no_features == 1) {
+                            $sql = "SELECT feature_id FROM {feature} ".
+                                    "WHERE uniquename = '%s' ";
+                            $feature_id = db_result(db_query($sql, $seqname));
+                            print "\tfeature id is $feature_id\n";
+    
+                            // If the uniquename matches more than one features then skip and print 'Ambiguous'
+                        } else if ($no_features > 1) {
+                            fwrite($log, "Ambiguous: ".$seqname." matches more than one feature and is not processed.\n");
+                            continue;
+    
+                        // If the uniquename did not match, skip and print 'Failed'
+                        } else {
+                            fwrite($log, "Failed: ".$seqname."\n");
+                        }
+    
+                    }
+                }
+            }
+
+            // Successfully matched. print 'Succeeded'. Add analysis_id and
+            // feature_id to analysisfeature. Add the table as XML to analysisfeatureprop
+            if ($feature_id) {
+
+                //------------------------------------
+                // Clease unwanted rows from the table
+                //------------------------------------
+
+                $parent_row =   "/<tr><td valign=\"top\"><b>Parent<\/b><\/td>\s*<td valign=\"top\">\s*no.*?parent<\/td>\s*<\/tr>/";
+                $children_row = "/<tr><td valign=\"top\"><b>Children<\/b><\/td>\s*<td valign=\"top\">\s*no.*?children<\/td>\s*<\/tr>/";
+                $found_row    = "/<tr><td valign=\"top\"><b>Found.*?in<\/b><\/td>\s*<td valign=\"top\">\s*no.*?entries<\/td>\s*<\/tr>/";
+                $contains_row = "/<tr><td valign=\"top\"><b>Contains<\/b><\/td>\s*<td valign=\"top\">\s*no.*?entries<\/td>\s*<\/tr>/";
+                $go_row       = "/<tr><td valign=\"top\"><b>GO.*?terms<\/b><\/td>\s*<td valign=\"top\">\s*none<\/td>\s*<\/tr>/";
+    
+                $table_txt = $table->asXML();
+                $table_txt = preg_replace($parent_row, "", $table_txt);
+                $table_txt = preg_replace($children_row, "", $table_txt);
+                $table_txt = preg_replace($found_row, "", $table_txt);
+                $table_txt = preg_replace($contains_row, "", $table_txt);
+                $table_txt = preg_replace($go_row, "", $table_txt);
+
+                //------------------------------------
+                // Clease unwanted ORF link from table 
+                //------------------------------------
+                $orf_link = "/<b><a href=\"\/iprscan\/wget.*?\">(.*?)<\/a><\/b>/";
+                $table_txt = preg_replace($orf_link, "$1", $table_txt);
+
+                //print "----------------------------\n";
+                //print "old: ".$table->asXML()."\n\n\n";
+                //print "----------------------------\n";
+                //print "Fixed: $table_txt\n";
+                //print "----------------------------\n";
+
+                //------------------------------------
+                // If this feature has already been associated with this analysis, do not reinsert
+                // Otherwise, Insert into analysisfeature table
+                //------------------------------------
+                $sql = "Select analysisfeature_id as id from {analysisfeature} where feature_id = %d and analysis_id = %d";
+                $analysisfeature =  db_fetch_object(db_query($sql, $feature_id, $analysis_id));
+                if($analysisfeature){ $analysisfeature_id = $analysisfeature->id; }
+                if(!$analysisfeature_id){
+                    print "inserting analysisfeature\n";
+                   $sql = "INSERT INTO {analysisfeature} (feature_id, analysis_id) ".
+                        "VALUES (%d, %d)";
+                   db_query ($sql, $feature_id, $analysis_id);
+                   $sql = "Select analysisfeature_id from {analysisfeature} where feature_id = %d and analysis_id = %d";
+                   $analysisfeature =  db_fetch_object(db_query($sql, $feature_id, $analysis_id));
+                   $analysisfeature_id = $analysisfeature->id;
+                }
+
+                print "analysisfeature_id is $analysisfeature_id (analysis_id = $analysis_id; feature_id = $feature_id)\n";
+
+
+                // Get the higest rank for this feature_id in analysisfeatureprop table.
+                // If the value of the inserting content is not duplicate, add it to  
+                // analysisfeaturepro with 'higest_rank + 1'
+                $sql = "SELECT MAX(rank) FROM {analysisfeatureprop} AFP ".
+                        "INNER JOIN analysisfeature AF ON AF.analysisfeature_id = AFP.analysisfeature_id ".       
+                        "WHERE feature_id=%d ".
+                        "AND analysis_id=%d ".
+                        "AND type_id=%d ";
+
+                $afp =  db_fetch_object(db_query($sql, $feature_id, $analysis_id, $type_id));
+                $hi_rank = 0;
+                if ($afp) {
+                    $hi_rank = $afp->max + 1;
+                }
+            
+				//------------------------------------------------------------
+				// Insert interpro html tags into analysisfeatureprop table
+				//------------------------------------------------------------
+				// Before inserting, make sure it's not a duplicate
+				$sql = "SELECT value FROM {analysisfeatureprop} WHERE analysisfeature_id = %d AND type_id = %d";
+				$result = db_query($sql, $analysisfeature_id, $type_id);
+				$duplicate = 0;
+				while ($afp_value = db_fetch_object($result)) {
+				    if ($table_txt == $afp_value->value) {
+                        $duplicate = 1;
+				    }
+				}
+				if (!$duplicate) {
+				    $sql = "INSERT INTO {analysisfeatureprop} (analysisfeature_id, type_id, value, rank)".
+                            "VALUES (%d, %d, '%s', %d)";
+				    db_query($sql, $analysisfeature_id, $type_id, $table_txt, $hi_rank);
+				    fwrite($log, " (Insert)\n"); // write to log
+                    print "\twriting table\n";
+				} else {
+				   fwrite($log, " (Skipped)\n");
+                    print "\tskipping table - dup\n";
+				}
+				
+                // Parse GO terms. Make sure GO database schema is installed in chado
+                $go_db_id = db_result(db_query("SELECT db_id FROM {db} WHERE name='GO'"));
+                if (!$go_db_id) {
+                    print 'GO schema not installed in chado. GO terms are not processed.';
+                }
+                if ($go_db_id && $parsego) {
+                    $trs = $table->children();
+                    foreach ($trs as $tr) {
+                        $tds = $tr->children();
+                        foreach($tds as $td) {
+                            $gotags = $td->children();
+                            foreach ($gotags as $gotag) {
+                                // Look for 'GO:accession#'
+                                if (preg_match("/^.*?GO:(\d+).*$/", $gotag, $matches)) {
+                        	
+                                    // Find cvterm_id for the matched GO term
+                                    $sql = "SELECT cvterm_id FROM {cvterm} CVT 
+                                            INNER JOIN dbxref DBX ON CVT.dbxref_id = DBX.dbxref_id
+                                            WHERE DBX.accession = '%s' AND DBX.db_id = %d";
+                                    $goterm_id = db_result(db_query($sql, $matches[1], $go_db_id));
+                           
+                                    //-------------------------------------------
+                                    // Insert GO terms into feature_cvterm table
+                                    //-------------------------------------------
+                                    // Default pub_id = 1 (NULL) was used
+                                    $sql = "INSERT INTO {feature_cvterm} (feature_id, cvterm_id, pub_id)
+                                            VALUES (%d, %d, 1)";
+                                    db_query($sql, $feature_id, $goterm_id);
+
+                                    //------------------------------------------------
+                                    // Insert GO terms into analysisfeatureprop table
+                                    //------------------------------------------------
+                                    $sql = "INSERT INTO {analysisfeatureprop} (analysisfeature_id, type_id, value, rank) ".
+                                            "VALUES (%d, %d, '%s', 0)";
+                                    db_query($sql, $analysisfeature_id, $goterm_id, $matches[1]);
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+    tripal_db_set_active ($previous_db); // Use drupal database
+    print "Done.\nSuccessful and failed entries have been saved in the log file:\n $logfile\n";
+	
+    fwrite($log, "\n");
+    fclose($log);
+    return;
+}
+/**
+*
+*/
+function tripal_analysis_interpro_parseXMLFile ($analysis_id, $interproxmlfile, 
+   $parsego, $query_re, $query_type, $query_uniquename, $job_id) 
+{
+
+   // clear out the anslysisfeature table for this analysis before getting started
+   tripal_core_chado_delete('analysisfeature',array('analysis_id' => $analysis_id));
+
+   // Prepare log
+   $filename = preg_replace("/.*\/(.*)/", "$1", $interproxmlfile);
+   $logfile = file_directory_path() . "/tripal/tripal_analysis_interpro/load_$filename.log";
+   $log = fopen($logfile, 'a'); // append parsing results to log file
+
+   // Parsing started
+   print "Parsing File:".$interproxmlfile." ...\n";
+   fwrite($log, date("D M j G:i:s Y").". Loading $interproxmlfile\n");
+
+   // Get cvterm_id for 'analysis_interpro_xmloutput_hits' which is required
+   // for inserting into the analysisfeatureprop table
+   $previous_db = db_set_active('chado'); // use chado database
+   $sql = "SELECT CVT.cvterm_id FROM {cvterm} CVT ".
+   "INNER JOIN cv ON cv.cv_id = CVT.cv_id ".
+   "WHERE CVT.name = 'analysis_interpro_xmloutput_hit' ".
+   "AND CV.name = 'tripal'";
+   $type_id = db_result(db_query($sql));
+
+   // Load the XML file
+   $interproput =  simplexml_load_file($interproxmlfile);
+
+   // Get entries parsing
+   $proteins = $interproput->children();
+
+   // Count the number of entires to be processed
+   $no_iterations = 0;
+   foreach($proteins as $tmp) {
+      $no_iterations ++;
+   }
+   print "$no_iterations proteins to be processed.\n";
+   $interval = intval($no_iterations * 0.01);
+   $idx_iterations = 0;
+
+   // get the DB id for the GO database
+   $parsego = tripal_analysis_get_property($analysis_id,'analysis_interpro_parsego');
+   $go_db_id = db_result(db_query("SELECT db_id FROM {db} WHERE name='GO'"));
+   if ($parsego and !$go_db_id) {
+     print 'GO schema not installed in chado. GO terms are not processed.';;
+   }
+
+   // Processed each protein
+   foreach ($proteins as $protein) {
+      // Set job status
+      $idx_iterations ++;
+      if ($idx_iterations % $interval == 0) {
+         $percentage = (int) ($idx_iterations / $no_iterations * 100);
+         db_set_active($previous_db);
+         tripal_job_set_progress($job_id, $percentage);
+         $previous_db = db_set_active('chado');
+         print $percentage."% ";
+      }
+
+      // match the protein id with the feature name
+      $feature_id = 0;
+      $attr = $protein->attributes();
+      $seqname =$attr ['id'];
+
+      // Remove _ORF from the sequence name
+      $seqname = preg_replace('/^(.+)_\d+_ORF\d+.*/', '$1', $seqname);
+     
+      // if a regular expression is provided then pick out the portion requested
+		if ($query_re and preg_match("/$query_re/", $seqname, $matches)) {
+			$feature = $matches[1];
+		} 
+      // If no match by the regular expression then get everything up to the first space
+      else {
+			if (preg_match('/^(.*?)\s.*$/',  $seqname, $matches)) {
+				$feature = $matches[1];
+         } 
+         // if no match up to the first space then just use the entire string
+         else {
+            $feature =  $seqname;
+         }
+      }   
+
+      if(!$feature and $query_re){
+         print fwrite($log, "Failed: Cannot find feature for '$seqname' using the regular expression: $query_re\n");
+         continue;
+      }
+
+      // now find the feature in chado
+      $select = array();
+      if($query_uniquename){
+         $select['uniquename'] = $feature;
+      } else {
+         $select['name'] = $feature;
+      }
+      if($query_type){
+         $select['type_id'] = array(
+           'cv_id' => array(
+              'name' => 'sequence'
+           ),
+           'name' => $query_type,
+         );
+      }
+
+      $feature_arr = tripal_core_chado_select('feature',array('feature_id'),$select);
+      if(count($feature_arr) > 1){
+		   fwrite($log, "Ambiguous: '$feature' matches more than one feature and is being skipped.\n");
+			continue;
+      }
+      if(count($feature_arr) == 0){
+			fwrite($log, "Failed: '$feature' cannot find a matching feature in the database.\n");
+         continue;
+      }
+      $feature_id = $feature_arr[0]->feature_id;
+
+     
+      // Successfully matched. print 'Succeeded'. Add analysis_id and
+      // feature_id to analysisfeature. Add the table as XML to analysisfeatureprop
+      if ($feature_id) {
+
+         print "$idx_iterations Adding InterPro results for feature '$seqname' ($feature_id)\n";
+
+         // If a matched feature is found, write to log.
+         fwrite($log, "Succeeded: ".$seqname." => feature id:".$feature_id);
+
+         //------------------------------------
+         // Insert into analysisfeature table
+         //------------------------------------
+         $sql = "INSERT INTO {analysisfeature} (feature_id, analysis_id) ".
+                "VALUES (%d, %d)";
+         db_query ($sql, $feature_id, $analysis_id);                     
+
+         // Get the analysisfeature_id
+         $sql = "SELECT analysisfeature_id FROM {analysisfeature} WHERE feature_id = %d AND analysis_id = %d";
+         $analysisfeature_id = db_result(db_query($sql, $feature_id, $analysis_id));
+
+         //------------------------------------------------------------
+         // Insert interpro xml results into analysisfeatureprop table
+         //------------------------------------------------------------
+         // Check to see if we have an existing entry
+         $sql = "SELECT analysisfeatureprop_id,rank 
+                 FROM {analysisfeatureprop} 
+                 WHERE analysisfeature_id = %d AND type_id = %d 
+                 ORDER BY rank DESC";
+         $result = db_fetch_object(db_query($sql, $analysisfeature_id, $type_id));
+         $rank = 0;
+         if($result){
+            $afp_id = $result->analysisfeatureprop_id; 
+            $rank = $result->rank + 1; 
+         }
+         $sql = "INSERT INTO {analysisfeatureprop} (analysisfeature_id, type_id, value, rank)".
+                "VALUES (%d, %d, '%s', %d)";
+         db_query($sql, $analysisfeature_id, $type_id, $protein->asXML(), $rank);
+         fwrite($log, " (Insert)\n"); // write to log
+
+         // parse the XML for each protein if GO terms are requested
+
+         if($parsego and $go_db_id){		
+
+            $protein = tripal_analysis_interpro_get_result_object($protein->asXML(),$feature_id); 
+            $goterms = $protein['goterms'];                 
+
+            // cycle through the GO terms and add them to the database
+            foreach($goterms as $goterm){ 
+                   
+               // seperate the 'GO:' from the term
+               if (preg_match("/^.*?GO:(\d+).*$/", $goterm, $matches)) {
+
+                  // Find cvterm_id for the matched GO term
+                  $sql = "SELECT cvterm_id FROM {cvterm} CVT 
+                          INNER JOIN dbxref DBX ON CVT.dbxref_id = DBX.dbxref_id
+                          WHERE DBX.accession = '%s' AND DBX.db_id = %d";
+                  $goterm_id = db_result(db_query($sql, $matches[1], $go_db_id));
+
+                  // Insert GO terms into feature_cvterm table
+                  // Default pub_id = 1 (NULL) was used
+                  $sql = "INSERT INTO {feature_cvterm} (feature_id, cvterm_id, pub_id)
+                          VALUES (%d, %d, 1)";
+                  db_query($sql, $feature_id, $goterm_id);
+
+
+                  // Insert GO terms into analysisfeatureprop table
+                  $sql = "INSERT INTO {analysisfeatureprop} (analysisfeature_id, type_id, value, rank) ".
+                          "VALUES (%d, %d, '%s', 0)";
+                  db_query($sql, $analysisfeature_id, $goterm_id, $matches[1]);
+               } // end if preg_match
+            } // end for each goterm
+         } // end if($parsego and $go_db_id)
+      } // end if($feature_id)            
+   } // end foreach ($proteins as $protein)
+   db_set_active ($previous_db); // Use drupal database
+   print "Done.\nSuccessful and failed entries have been saved in the log file:\n $logfile\n";
+
+   fwrite($log, "\n");
+   fclose($log);
+   return;
+}
+/********************************************************************************
+ * 
+ */
+function tripal_analysis_interpro_get_result_object($interpro_xml,$feature_id){
+
+	// Load the XML into an object
+	$xmlObj = simplexml_load_string($interpro_xml);
+
+   // iterate through each interpro results for this protein
+   $results = array();
+   $terms = array();
+   $protein = array();
+   $iprterms = array();
+   $goterms = array();
+
+   $term_count = 0;
+   $match_count = 0;
+   
+   // get the properties of this result
+   $attr = $xmlObj->attributes();
+   $protein['orf_id'] = (string) $attr["id"];
+   $protein['orf_length'] = (string) $attr["length"];
+   $protein['orf_crc64'] = (string) $attr["crc64"];
+   
+	foreach($xmlObj->children() as $intepro){
+      // get the interpro term for this match
+      $attr = $intepro->attributes();
+	   $terms[$term_count]['ipr_id'] = (string) $attr["id"];
+	   $terms[$term_count]['ipr_name'] = (string) $attr["name"];
+	   $terms[$term_count]['ipr_type'] = (string) $attr["type"];
+      $iprterms[] = array($terms[$term_count]['ipr_id'],$terms[$term_count]['ipr_name']);
+ 
+      // iterate through the elements of the interpro result
+      $matches[$term_count]['matches'] = array();
+      $match_count = 0;
+  	   foreach($intepro->children() as $level1){
+			$element_name = $level1->getName();
+			if($element_name == 'match'){
+            // get the match name for this match
+            $attr = $level1->attributes();
+	         $terms[$term_count]['matches'][$match_count]['match_id'] = (string) $attr["id"];
+	         $terms[$term_count]['matches'][$match_count]['match_name'] = (string) $attr["name"];
+	         $terms[$term_count]['matches'][$match_count]['match_dbname'] = (string) $attr["dbname"];
+            
+            // get the location information for this match     
+            $loc_count = 0;
+            foreach($level1->children() as $level2){
+			      $element_name = $level2->getName();
+			      if($element_name == 'location'){
+                  $attr = $level2->attributes();
+	               $terms[$term_count]['matches'][$match_count]['locations'][$loc_count]['match_start'] = (string) $attr["start"];
+	               $terms[$term_count]['matches'][$match_count]['locations'][$loc_count]['match_end'] = (string) $attr["end"];
+	               $terms[$term_count]['matches'][$match_count]['locations'][$loc_count]['match_score'] = (string) $attr["score"];
+	               $terms[$term_count]['matches'][$match_count]['locations'][$loc_count]['match_status'] = (string) $attr["status"];
+	               $terms[$term_count]['matches'][$match_count]['locations'][$loc_count]['match_evidence'] = (string) $attr["evidence"];
+                  $loc_count++;
+               }
+            }
+            $match_count++;
+         }
+
+			if($element_name == 'classification'){
+            $attr = $level1->attributes();
+            if($attr['class_type'] == 'GO'){
+               $terms[$term_count]['matches'][$match_count]['go_terms'][] = (string) $attr['id'];
+               $goterms[] = (string) $attr['id'];
+            }
+         }
+      }
+      $term_count++;
+	}
+   $results['terms'] = $terms;
+   $results['orf'] = $protein;
+   $results['iprterms'] = $iprterms;
+   $results['goterms'] = $goterms;
+	return $results;
+}

+ 30 - 7
tripal_analysis_interpro/tripal_analysis_interpro.install

@@ -17,12 +17,8 @@ function tripal_analysis_interpro_install() {
    // Inert into drupal's {tripal_analysis}
    // Inert into drupal's {tripal_analysis}
    tripal_analysis_register_child('tripal_analysis_interpro');
    tripal_analysis_register_child('tripal_analysis_interpro');
    
    
-   // Add cvterm 'analysis_interpro_output_iteration_hits' for inserting into featureprop table
-   tripal_add_cvterms('analysis_interpro_output_hit', 'Hit in the interpro html '.
-      'output. Each hit belongs to a chado feature. This cvterm represents a hit in the output');
-   // Add cvterm 'analysis_interpro_settings' for inserting into analysisprop table
-   tripal_add_cvterms('analysis_interpro_settings', 'Settings of an interpro analysis, '.
-      'including output file and run parameters separated by a bar |');
+   // add the CVterms needed for this module
+   tripal_analysis_interpro_add_cvterms();
 }
 }
 
 
 /*******************************************************************************
 /*******************************************************************************
@@ -44,7 +40,34 @@ function tripal_analysis_interpro_uninstall() {
             'tripal_analysis_interpro_setting');
             'tripal_analysis_interpro_setting');
 
 
 }
 }
+/**
+*
+*/
+function tripal_analysis_interpro_add_cvterms(){
+   // Add cvterm 'analysis_interpro_output_iteration_hits' for inserting into featureprop table
+   tripal_add_cvterms('analysis_interpro_output_hit', 'Hit in the interpro html output. Each hit belongs to a chado feature. This cvterm represents a hit in the output');
+   tripal_add_cvterms('analysis_interpro_settings', 'Settings of an interpro analysis, including output file and run parameters separated by a bar |');
+   tripal_add_cvterms('analysis_interpro_interproparameters','The parameters used when executing an InterProScan job');
+   tripal_add_cvterms('analysis_interpro_interprofile','Used to hold the name of the XML file containing the InterProScan results');
+   tripal_add_cvterms('analysis_interpro_parsego','Indicates whether or not the GO terms should be extracted when parsing the InterProScan XML file');
+   tripal_add_cvterms('analysis_interpro_query_re','The regular expression for finding the feature name in the query definition line of the InterPro results');
+   tripal_add_cvterms('analysis_interpro_query_type','The feature type (e.g. mRNA, polypeptide) of the query input file. This type is used to identify the query feature when multiple features have the same name');
+   tripal_add_cvterms('analysis_interpro_query_uniquename','Indicates if the matched name in the query definition line of the blast results is feature uniquename');
+}
+/**
+ * 
+ */
+function tripal_analysis_interpro_update_6000(){
 
 
+   // we have some new cvterms to add
+   tripal_analysis_interpro_add_cvterms();
+
+   $ret = array(
+      '#finished' => 1,
+   );
+   
+   return $ret;
+}
 /*******************************************************************************
 /*******************************************************************************
  * Implementation of hook_requirements(). Make sure 'Tripal Core' and 'Tripal
  * Implementation of hook_requirements(). Make sure 'Tripal Core' and 'Tripal
  * Analysis' are enabled before installation
  * Analysis' are enabled before installation
@@ -61,4 +84,4 @@ function tripal_analysis_interpro_requirements($phase) {
       }
       }
    }
    }
    return $requirements;
    return $requirements;
-}
+}

+ 219 - 604
tripal_analysis_interpro/tripal_analysis_interpro.module

@@ -1,15 +1,16 @@
 <?php
 <?php
+
+require_once "parseInterpro.inc";
+
 /*******************************************************************************
 /*******************************************************************************
  * Tripal Interpro lets users show/hide iprscan results associated with a tripal
  * Tripal Interpro lets users show/hide iprscan results associated with a tripal
  * feature
  * feature
  ******************************************************************************/
  ******************************************************************************/
 function tripal_analysis_interpro_init(){
 function tripal_analysis_interpro_init(){
 	// Add javascript and style sheet
 	// Add javascript and style sheet
-	drupal_add_css(drupal_get_path('theme', 'tripal').
-                                  '/css/tripal_analysis_interpro.css');
+	drupal_add_css(drupal_get_path('theme', 'tripal').'/css/tripal_analysis_interpro.css');
 	// Add javascript and style sheet
 	// Add javascript and style sheet
-   drupal_add_js(drupal_get_path('theme', 'tripal').
-                                  '/js/tripal_analysis_interpro.js');
+   drupal_add_js(drupal_get_path('theme', 'tripal').'/js/tripal_analysis_interpro.js');
 }
 }
 /*******************************************************************************
 /*******************************************************************************
  *  Provide information to drupal about the node types that we're creating
  *  Provide information to drupal about the node types that we're creating
@@ -60,99 +61,19 @@ function tripal_analysis_interpro_block($op = 'list', $delta = 0, $edit=array())
  */
  */
 function chado_analysis_interpro_form ($node){
 function chado_analysis_interpro_form ($node){
 
 
-	$type = node_get_types('type', $node);
-	$form = array();
-	$form['title']= array(
-      '#type' => 'hidden',
-      '#default_value' => $node->title,
-	);
-	$form['analysisname']= array(
-      '#type' => 'textfield',
-      '#title' => t('Analysis Name'),
-      '#required' => FALSE,
-      '#default_value' => $node->analysisname,
-      '#weight' => 1
-	);
-	$form['program']= array(
-      '#type' => 'textfield',
-      '#title' => t('Program'),
-      '#required' => TRUE,
-      '#default_value' => $node->program,
-      '#weight' => 2
-	);
-	$form['programversion']= array(
-      '#type' => 'textfield',
-      '#title' => t('Program Version'),
-      '#required' => TRUE,
-      '#default_value' => $node->programversion,
-      '#weight' => 3
-	);
-	$form['algorithm']= array(
-      '#type' => 'textfield',
-      '#title' => t('Algorithm'),
-      '#required' => FALSE,
-      '#default_value' => $node->algorithm,
-      '#weight' => 4
-	);
-	$form['sourcename']= array(
-      '#type' => 'textfield',
-      '#title' => t('Source Name'),
-      '#required' => FALSE,
-      '#default_value' => $node->sourcename,
-      '#weight' => 5
-	);
-	$form['sourceversion']= array(
-      '#type' => 'textfield',
-      '#title' => t('Source Version'),
-      '#required' => FALSE,
-      '#default_value' => $node->sourceversion,
-      '#weight' => 6
-	);
-	$form['sourceuri']= array(
-      '#type' => 'textfield',
-      '#title' => t('Source URI'),
-      '#required' => FALSE,
-      '#default_value' => $node->sourceuri,
-      '#weight' => 7
-	);
-	// Get time saved in chado
-	$default_time = $node->timeexecuted;
-	$year = preg_replace("/^(\d+)-\d+-\d+ .*/", "$1", $default_time);
-	$month = preg_replace("/^\d+-0?(\d+)-\d+ .*/", "$1", $default_time);
-	$day = preg_replace("/^\d+-\d+-0?(\d+) .*/", "$1", $default_time);
-	// If the time is not set, use current time
-	if (!$default_time) {
-		$default_time = time();
-		$year = format_date($default_time, 'custom', 'Y');
-		$month = format_date($default_time, 'custom', 'n');
-		$day = format_date($default_time, 'custom', 'j');
-	}
-	$form['timeexecuted']= array(
-      '#type' => 'date',
-      '#title' => t('Time Executed'),
-      '#required' => TRUE,
-      '#default_value' => array(
-         'year' => $year,
-         'month' => $month,
-         'day' => $day,
-	),
-      '#weight' => 8
-	);
-	$form['description']= array(
-      '#type' => 'textarea',
-      '#rows' => 15,
-      '#title' => t('Description and/or Program Settings'),
-      '#required' => FALSE,
-      '#default_value' => $node->description,
-      '#weight' => 9
-	);
+   // add in the default fields for the analysis
+   $form = chado_analysis_form($node);
+
+   $analysis = $node->analysis;
+
+   $interprofile = $analysis->tripal_analysis_interpro->interprofile;
+   $interproparameters = $analysis->tripal_analysis_interpro->interproparameters;
+   $parsego = $analysis->tripal_analysis_interpro->parsego;
+   $query_re = $analysis->tripal_analysis_interpro->query_re;
+   $query_type = $analysis->tripal_analysis_interpro->query_type;
+   $query_uniquename = $analysis->tripal_analysis_interpro->query_uniquename;
+
 
 
-	//----InterProScan Settings (Shown only when Tripal Interpro is enabled) ----
-	if (preg_match("/.*\|.*/",$node->interprofile)) {
-		$prop_values = explode("|", $node->interprofile);
-		$node->interprofile = $prop_values[0];
-		$node->interproparameters = $prop_values[1];
-	}
 	$moreSettings ['interpro'] = 'Interpro Settings';
 	$moreSettings ['interpro'] = 'Interpro Settings';
 	$form['interpro'] = array(
 	$form['interpro'] = array(
       '#title' => t('Interpro Settings'),
       '#title' => t('Interpro Settings'),
@@ -163,19 +84,19 @@ function chado_analysis_interpro_form ($node){
       '#weight' => 11
       '#weight' => 11
 	);
 	);
 	$form['interpro']['interprofile'] = array(
 	$form['interpro']['interprofile'] = array(
-      '#title' => t('Interproscan Output File (in html format)'),
+      '#title' => t('Interproscan Output File (in XML format)'),
       '#type' => 'textfield',
       '#type' => 'textfield',
-      '#description' => t('The html output file generated by Interproscan in full path.'),
-      '#default_value' => $node->interprofile,
+      '#description' => t('Please provide the full path to the XML output file generated by InterProScan.'),
+      '#default_value' => $interprofile,
 	);
 	);
 	$form['interpro']['interprojob'] = array(
 	$form['interpro']['interprojob'] = array(
       '#type' => 'checkbox',
       '#type' => 'checkbox',
-      '#title' => t('Submit a job to parse the Interpro html output'),
+      '#title' => t('Submit a job to parse the InterProScan XML file'),
       '#description' => t('Note: features associated with the interpro results must '.
       '#description' => t('Note: features associated with the interpro results must '.
                              'exist in chado before parsing the file. Otherwise, interpro '.
                              'exist in chado before parsing the file. Otherwise, interpro '.
                              'results that cannot be linked to a feature will be '.
                              'results that cannot be linked to a feature will be '.
-                             'discarded. Also, Triapl Interpro module needs to be enabled.'),
-      '#default_value' => $node->interprojob,
+                             'discarded.'),
+      '#default_value' => $interprojob,
 	   '#attributes' => array(
 	   '#attributes' => array(
         'onclick' => 'return isSubmittingJob(this)'
         'onclick' => 'return isSubmittingJob(this)'
       )
       )
@@ -184,290 +105,167 @@ function chado_analysis_interpro_form ($node){
       '#type' => 'checkbox',
       '#type' => 'checkbox',
       '#title' => t('Load GO terms to the database'),
       '#title' => t('Load GO terms to the database'),
       '#description' => t('Check the box to load GO terms to chado database'),
       '#description' => t('Check the box to load GO terms to chado database'),
-      '#default_value' => $node->parsego
+      '#default_value' => $parsego
    );
    );
 	$form['interpro']['interproparameters'] = array(
 	$form['interpro']['interproparameters'] = array(
       '#title' => t('Parameters'),
       '#title' => t('Parameters'),
       '#type' => 'textfield',
       '#type' => 'textfield',
-      '#description' => t('The parameters for running the interpro analysis.'),
-      '#default_value' => $node->interproparameters,
+      '#description' => t('The parameters used when running the InterProScan analysis.'),
+      '#default_value' => $interproparameters,
+	);
+
+	$form['interpro']['query_re'] = array(
+      '#title' => t('Query Name RE'),
+      '#type' => 'textfield',
+      '#description' => t('Enter the regular expression that will extract the '.
+         'feature name from the query line in the interpro results. This should be '.
+         'the same as the definition line in the query FASTA file.  This option is '.
+         'is only required when the query does not identically match a feature '.
+         'in the database.'),
+      '#default_value' => $query_re,
+	);
+
+	$form['interpro']['query_type'] = array(
+      '#title' => t('Query Type'),
+      '#type' => 'textfield',
+      '#description' => t('Please enter the Sequence Ontology term that describes '.
+         'the query sequences used for InterProScan.  This is only necessary if two '.
+         'or more sequences have the same name.'),
+      '#default_value' => $query_type,
+	);
+
+	$form['interpro']['query_uniquename'] = array(
+      '#title' => t('Use Unique Name'),
+      '#type' => 'checkbox',
+      '#description' => t('Select this checboxk if the query name in the results file '.
+        'matches the uniquename of the feature.  By default, the blast results will '.
+        'mapped to the "name" of the feature.'),
+      '#default_value' => $query_uniquename,
 	);
 	);
 	return $form;
 	return $form;
 }
 }
-/*******************************************************************************
+/**
+ * 
+ * 
+ */
+function chado_analysis_interpro_load($node){
+
+   // load the default set of analysis fields
+	$additions = chado_analysis_load($node);
+
+   // create some variables for easier lookup
+   $analysis = $additions->analysis;
+   $analysis_id = $analysis->analysis_id;
+
+   $intepro_settings  = tripal_analysis_get_property($analysis->analysis_id,'analysis_interpro_settings');	
+   $interprofile      = tripal_analysis_get_property($analysis->analysis_id,'analysis_interpro_interprofile');
+   $interproparameters= tripal_analysis_get_property($analysis->analysis_id,'analysis_interpro_interproparameters');
+   $parsego           = tripal_analysis_get_property($analysis->analysis_id,'analysis_interpro_parsego');		
+   $query_re          = tripal_analysis_get_property($analysis->analysis_id,'analysis_interpro_query_re');	
+   $query_type        = tripal_analysis_get_property($analysis->analysis_id,'analysis_interpro_query_type');	
+   $query_uniquename  = tripal_analysis_get_property($analysis->analysis_id,'analysis_interpro_query_uniquename');	
+
+   $analysis->tripal_analysis_interpro->interprofile      = $interprofile->value;
+   $analysis->tripal_analysis_interpro->interproparameters= $interproparameters->value;
+   $analysis->tripal_analysis_interpro->parsego           = $parsego->value;
+   $analysis->tripal_analysis_interpro->query_re          = $query_re->value;
+   $analysis->tripal_analysis_interpro->query_type        = $query_type->value;
+   $analysis->tripal_analysis_interpro->query_uniquename  = $query_uniquename->value;
+
+   // if there is an old style 'interpro_settings' array, then break these out for
+   // use in the new format
+   if(count($interpro_settings)>0){
+	   $prop_values = explode ("|", $interpro_settings->value);
+      $analysis->tripal_analysis_interpro->interprofile       = $prop_values[0];
+      $analysis->tripal_analysis_interpro->interproparameters = $prop_values[1];
+   }
+	return $additions;
+}
+/**
  *  
  *  
  */
  */
 function chado_analysis_interpro_insert($node){
 function chado_analysis_interpro_insert($node){
-	global $user;
-	// Create a timestamp so we can insert it into the chado database
-	$time = $node->timeexecuted;
-	$month = $time['month'];
-	$day = $time['day'];
-	$year = $time['year'];
-	$timestamp = $month.'/'.$day.'/'.$year;
-
-	// If this analysis already exists then don't recreate it in chado
-	$analysis_id = $node->analysis_id;
-	if ($analysis_id) {
-		$sql = "SELECT analysis_id ".
-               "FROM {Analysis} ".
-               "WHERE analysis_id = %d ";
-		$previous_db = tripal_db_set_active('chado');
-		$analysis = db_fetch_object(db_query($sql, $node->analysis_id));
-		tripal_db_set_active($previous_db);
-	}
+  // insert the analysistripal_core_generate_chado_var
+   chado_analysis_insert($node);
+
+   // set the type for this analysis
+   tripal_analysis_insert_property($node->analysis_id,'analysis_type','tripal_analysis_interpro');
+
+   // now add in the remaining settings as a single property but separated by bars
+   tripal_analysis_insert_property($node->analysis_id,'analysis_interpro_interprofile',$node->interprofile);
+   tripal_analysis_insert_property($node->analysis_id,'analysis_interpro_interproparameters',$node->interproparameters);
+   tripal_analysis_insert_property($node->analysis_id,'analysis_interpro_parsego',$node->parsego);		
+   tripal_analysis_insert_property($node->analysis_id,'analysis_interpro_query_re',$node->query_re);	
+   tripal_analysis_insert_property($node->analysis_id,'analysis_interpro_query_type',$node->query_type);	
+   tripal_analysis_insert_property($node->analysis_id,'analysis_interpro_query_uniquename',$node->query_uniquename);	
+  
+   // submit the parsing jobs
+   chado_analysis_interpro_submit_job($node);
 
 
-	// If the analysis doesn't exist then let's create it in chado.
-	if(!$analysis){
-		// First add the item to the chado analysis table
-		$sql = "INSERT INTO {analysis} ".
-             "  (name, description, program, programversion, algorithm, ".
-             "   sourcename, sourceversion, sourceuri, timeexecuted) ".
-             "VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s')";
-		$previous_db = tripal_db_set_active('chado');  // use chado database
-		db_query($sql,$node->analysisname, $node->description,
-		$node->program,$node->programversion,$node->algorithm,
-		$node->sourcename, $node->sourceversion, $node->sourceuri,
-		$timestamp);
-
-		// find the newly entered analysis_id
-		$sql = "SELECT analysis_id ".
-             "FROM {Analysis} ".
-             "WHERE program='%s'".
-             "AND programversion='%s'".
-             "AND sourcename='%s'";
-		$analysis_id = db_result(db_query($sql, $node->program,
-		$node->programversion, $node->sourcename));
-
-		// Get cvterm_id for 'analysis_interpro_settings'
-		$sql = "SELECT CVT.cvterm_id FROM {cvterm} CVT ".
-             "INNER JOIN cv ON cv.cv_id = CVT.cv_id ".
-             "WHERE CVT.name = 'analysis_interpro_settings' ".
-             "AND CV.name = 'tripal'";
-		$type_id = db_result(db_query($sql));
-
-		// Insert into chado {analysisprop} table
-		$sql = "INSERT INTO {analysisprop} (analysis_id, type_id, value) ".
-             "VALUES (%d, %d, '%s')";
-		$interprosettings = $node->interprofile."|".$node->interproparameters;
-		db_query($sql, $analysis_id, $type_id, $interprosettings);
-
-		tripal_db_set_active($previous_db);  // switch back to drupal database
-		// Add a job if the user wants to parse the html output
-		if($node->interprojob) {
-			$job_args[0] = $analysis_id;
-			$job_args[1] = $node->interprofile;
-			if ($node->parsego) {
-			   $job_args[2] = 1;
-			} else {
-            $job_args[2] = 0;
-         }
-			if (is_readable($node->interprofile)) {
-				$fname = preg_replace("/.*\/(.*)/", "$1", $node->interprofile);
-				tripal_add_job("Parse interpro: $fname",'tripal_analysis_interpro',
-                           'tripal_analysis_interpro_parseHTMLFile', $job_args, $user->uid);
-			} else {
-				drupal_set_message("Can not open interpro output file. Job not scheduled.");
-			}
-		}
-	}
-
-	// Make sure the entry for this analysis doesn't already exist in the
-	// chado_analysis table if it doesn't exist then we want to add it.
-	$node_check_sql = "SELECT * FROM {chado_analysis} ".
-                     "WHERE analysis_id = %d";
-	$node_check = db_fetch_object(db_query($node_check_sql, $analysis_id));
-	if(!$node_check){
-		// next add the item to the drupal table
-		$sql = "INSERT INTO {chado_analysis} (nid, vid, analysis_id) ".
-             "VALUES (%d, %d, %d)";
-		db_query($sql,$node->nid,$node->vid,$analysis_id);
-		// Create a title for the analysis node using the unique keys so when the
-		// node is saved, it will have a title
-		$record = new stdClass();
-		// If the analysis has a name, use it as the node title. If not, construct
-		// the title using program, programversion, and sourcename
-		if ($node->analysisname) {
-			$record->title = $node->analysisname;
-		} else {
-			//Construct node title as "program (version)
-			$record->title = "$node->program ($node->programversion)";
-		}
-		$record->nid = $node->nid;
-		drupal_write_record('node',$record,'nid');
-		drupal_write_record('node_revisions',$record,'nid');
-	}
 }
 }
-/*******************************************************************************
- * Delete interpro anlysis
+/**
+ * 
  */
  */
-function chado_analysis_interpro_delete($node){
-	// Before removing, get analysis_id so we can remove it from chado database
-	// later
-	$sql_drupal = "SELECT analysis_id ".
-                 "FROM {chado_analysis} ".
-                 "WHERE nid = %d ".
-                 "AND vid = %d";
-	$analysis_id = db_result(db_query($sql_drupal, $node->nid, $node->vid));
-
-	// Remove data from the {chado_analysis}, {node}, and {node_revisions} tables
-	$sql_del = "DELETE FROM {chado_analysis} ".
-              "WHERE nid = %d ".
-              "AND vid = %d";
-	db_query($sql_del, $node->nid, $node->vid);
-	$sql_del = "DELETE FROM {node} ".
-              "WHERE nid = %d ".
-              "AND vid = %d";
-	db_query($sql_del, $node->nid, $node->vid);
-	$sql_del = "DELETE FROM {node_revisions} ".
-              "WHERE nid = %d ".
-              "AND vid = %d";
-	db_query($sql_del, $node->nid, $node->vid);
-
-	//Remove from analysisfeatureprop, analysisfeature, analysis, and analysisprop tables
-   $previous_db = tripal_db_set_active('chado');
-   $sql = "SELECT analysisfeature_id FROM {analysisfeature} WHERE analysis_id=%d";
-   $results = db_query($sql, $analysis_id);
-   while ($af = db_fetch_object($results)) {
-      db_query("DELETE FROM {analysisfeatureprop} WHERE analysisfeature_id = %d", $af->analysisfeature_id);
+function chado_analysis_interpro_update($node){
+  // insert the analysistripal_core_generate_chado_var
+   chado_analysis_update($node);
+
+   // set the type for this analysis
+   tripal_analysis_update_property($node->analysis_id,'analysis_type','tripal_analysis_interpro',1);
+
+   // now add in the remaining settings as a single property but separated by bars
+   tripal_analysis_update_property($node->analysis_id,'analysis_interpro_interprofile',$node->interprofile,1);
+   tripal_analysis_update_property($node->analysis_id,'analysis_interpro_interproparameters',$node->interproparameters,1);
+   tripal_analysis_update_property($node->analysis_id,'analysis_interpro_parsego',$node->parsego,1);		
+   tripal_analysis_update_property($node->analysis_id,'analysis_interpro_query_re',$node->query_re,1);	
+   tripal_analysis_update_property($node->analysis_id,'analysis_interpro_query_type',$node->query_type,1);	
+   tripal_analysis_update_property($node->analysis_id,'analysis_interpro_query_uniquename',$node->query_uniquename,1);	
+
+   // if this analysis uses the old style settings cvterm then remove that term
+   $old = tripal_analysis_get_property($node->analysis_id,'analysis_interpro_settings');
+   if(count($old) > 0){
+      tripal_analysis_delete_property($node->analysis_id,'analysis_interpro_settings');
    }
    }
-   db_query("DELETE FROM {analysisfeature} WHERE analysis_id = %d", $analysis_id);
-   db_query("DELETE FROM {analysisprop} WHERE analysis_id = %d", $analysis_id);
-   db_query("DELETE FROM {analysis} WHERE analysis_id = %d", $analysis_id);
-   tripal_db_set_active($previous_db);
+  
+   // submit the parsing jobs
+   chado_analysis_interpro_submit_job($node);
 }
 }
-
 /*******************************************************************************
 /*******************************************************************************
- * Update interpro analysis
+ * Delete interpro anlysis
  */
  */
-function chado_analysis_interpro_update($node){
-	global $user;
-	if($node->revision){
-		// TODO -- decide what to do about revisions
-	} else {
-		// Create a timestamp so we can insert it into the chado database
-		$time = $node->timeexecuted;
-		$month = $time['month'];
-		$day = $time['day'];
-		$year = $time['year'];
-		$timestamp = $month.'/'.$day.'/'.$year;
-
-		// get the analysis_id for this node:
-		$sql = "SELECT analysis_id ".
-             "FROM {chado_analysis} ".
-             "WHERE vid = %d";
-		$analysis_id = db_fetch_object(db_query($sql, $node->vid))->analysis_id;
-
-		$sql = "UPDATE {analysis} ".
-             "SET name = '%s', ".
-             "    description = '%s', ".
-             "    program = '%s', ".
-             "    programversion = '%s', ".
-             "    algorithm = '%s', ".
-             "    sourcename = '%s', ".
-             "    sourceversion = '%s', ".
-             "    sourceuri = '%s', ".
-             "    timeexecuted = '%s' ".
-             "WHERE analysis_id = %d ";
-
-		$previous_db = tripal_db_set_active('chado');  // use chado database
-		db_query($sql, $node->analysisname, $node->description, $node->program,
-		$node->programversion,$node->algorithm,$node->sourcename,
-		$node->sourceversion, $node->sourceuri, $timestamp, $analysis_id);
-
-		// Get cvterm_id for 'analysis_interpro_settings'
-		$sql = "SELECT CVT.cvterm_id FROM {cvterm} CVT ".
-             "INNER JOIN cv CV ON CV.cv_id = CVT.cv_id ".
-             "WHERE CVT.name = 'analysis_interpro_settings' ".
-             "AND CV.name = 'tripal'";
-		$type_id = db_result(db_query($sql));
-		 
-		$sql = "UPDATE {analysisprop} ".
-             "SET value = '%s' ".
-             "WHERE analysis_id = %d AND type_id = %d";
-		$interprosettings = $node->interprofile."|".$node->interproparameters;
-		db_query($sql, $interprosettings, $analysis_id, $type_id);
-		tripal_db_set_active($previous_db);  // switch back to drupal database
-		// Add a job if the user wants to parse the html output
-		if($node->interprojob) {
-			$job_args[0] = $analysis_id;
-			$job_args[1] = $node->interprofile;
-		   if ($node->parsego) {
-            $job_args[2] = 1;
-         } else {
-            $job_args[2] = 0;
-         }
-			if (is_readable($node->interprofile)) {
-				$fname = preg_replace("/.*\/(.*)/", "$1", $node->interprofile);
-				tripal_add_job("Parse interpro: $fname",'tripal_analysis_interpro',
-                           'tripal_analysis_interpro_parseHTMLFile', $job_args, $user->uid);
-			} else {
-				drupal_set_message("Can not open interpro output file. Job not scheduled.");
-			}
-		}
+function chado_analysis_interpro_delete($node){
+	chado_analysis_delete($node);
+}
 
 
-		// Create a title for the analysis node using the unique keys so when the
-		// node is saved, it will have a title
-		$record = new stdClass();
-		// If the analysis has a name, use it as the node title. If not, construct
-		// the title using program, programversion, and sourcename
-		if ($node->analysisname) {
-			$record->title = $node->analysisname;
+/**
+*
+*/
+function chado_analysis_interpro_submit_job($node){
+   global $user;
+
+	// Add a job if the user wants to parse the html output
+	if($node->interprojob) {
+		$job_args[0] = $node->analysis_id;
+		$job_args[1] = $node->interprofile;
+		if ($node->parsego) {
+		   $job_args[2] = 1;
+		} else {
+         $job_args[2] = 0;
+      }
+		$job_args[3] = $node->query_re;
+		$job_args[4] = $node->query_type;
+		$job_args[5] = $node->query_uniquename;
+
+		if (is_readable($node->interprofile)) {
+			$fname = preg_replace("/.*\/(.*)/", "$1", $node->interprofile);
+			tripal_add_job("Parse interpro: $fname",'tripal_analysis_interpro',
+                        'tripal_analysis_interpro_parseXMLFile', $job_args, $user->uid);
 		} else {
 		} else {
-			//Construct node title as "program (version)
-			$record->title = "$node->program ($node->programversion)";
+			drupal_set_message("Can not open interpro output file. Job not scheduled.");
 		}
 		}
-		$record->nid = $node->nid;
-		drupal_write_record('node',$record,'nid');
-		drupal_write_record('node_revisions',$record,'nid');
 	}
 	}
 }
 }
-/*******************************************************************************
- *  When a node is requested by the user this function is called to allow us
- *  to add auxiliary data to the node object.
- */
-function chado_analysis_interpro_load($node){
-	// get the analysis_id for this node:
-	$sql = "SELECT analysis_id FROM {chado_analysis} WHERE vid = %d";
-	$ana_node = db_fetch_object(db_query($sql, $node->vid));
-	$additions = new stdClass();
-	if ($ana_node) {
-		// get analysis information
-		$sql = "SELECT Analysis_id, name AS analysisname, description, program, ".
-             "  programversion, algorithm, sourcename, sourceversion, ".
-             "  sourceuri, timeexecuted ".
-             "FROM {Analysis} ".
-             "WHERE Analysis_id = $ana_node->analysis_id";
-		$previous_db = tripal_db_set_active('chado');  // use chado database
-		$additions = db_fetch_object(db_query($sql));
-
-		// get cvterm_id for 'analysis_interpro_settings'
-		$sql = "SELECT CVT.cvterm_id FROM {cvterm} CVT ".
-             "INNER JOIN cv ON cv.cv_id = CVT.cv_id ".
-             "WHERE CVT.name = 'analysis_interpro_settings' ".
-             "AND CV.name = 'tripal'";
-		$type_id = db_result(db_query($sql));
-		// get analysisprop information
-		$sql = "SELECT value FROM {analysisprop} ".
-             "WHERE analysis_id = %d ".
-             "AND type_id = %d";
-		$analysisprop = db_result(db_query($sql, $ana_node->analysis_id, $type_id));
-		$prop_values = explode ("|", $analysisprop, 1);
-		$additions->interprofile = $prop_values[0];
-		$additions->interproparameters = $prop_values[1];
-
-		tripal_db_set_active($previous_db);  // now use drupal database
-	}
-	// If the analysis has a name, use it as the node title. If not, construct
-	// the title using program programversion, and sourcename
-	if ($additions->analysisname) {
-		$additions->title = $additions->analysisname;
-	} else {
-		// Construct node title as "program version (source)
-		$additions->title = "$additions->program ($additions->programversion)";
-	}
-	return $additions;
-}
+
 
 
 /*******************************************************************************
 /*******************************************************************************
  *  This function customizes the view of the chado_analysis node.  It allows
  *  This function customizes the view of the chado_analysis node.  It allows
@@ -498,244 +296,6 @@ function chado_analysis_interpro_view ($node, $teaser = FALSE, $page = FALSE) {
 	return $node;
 	return $node;
 }
 }
 
 
-/*******************************************************************************
- * Parse Interpro HTML Output file into analysisfeatureprop table
- */
-function tripal_analysis_interpro_parseHTMLFile ($analysis_id, $interprofile, $parsego, $job_id) {
-
-	// Prepare log
-	$filename = preg_replace("/.*\/(.*)/", "$1", $interprofile);
-	$logfile = file_directory_path() . "/tripal/tripal_analysis_interpro/load_$filename.log";
-	$log = fopen($logfile, 'a'); // append parsing results to log file
-
-	// Parsing started
-	print "Parsing File:".$interprofile." ...\n";
-	fwrite($log, date("D M j G:i:s Y").". Loading $interprofile\n");
-
-	// Get cvterm_id for 'analysis_interpro_output_iteration_hits' which is required
-	// for inserting into the analysisfeatureprop table
-	$previous_db = tripal_db_set_active('chado'); // use chado database
-	$sql = "SELECT CVT.cvterm_id FROM {cvterm} CVT ".
-          "INNER JOIN cv ON cv.cv_id = CVT.cv_id ".
-          "WHERE CVT.name = 'analysis_interpro_output_hit' ".
-          "AND CV.name = 'tripal'";
-	$type_id = db_result(db_query($sql));
-	print "cvterm_id for analysis_interpro_output_iteration_hits is $type_id\n";
-
-	// Load the HTML file and convert it into XML for loading
-	$dom = new domDocument;
-	$dom->loadHTMLFile($interprofile);
-	$xml = $dom->saveXML();
-	$interproput = simplexml_load_string($xml);
-
-	// Get html tables for parsing
-	$tables = $interproput->children()->children();
-
-	// Count the number of tables to be processed
-	$no_iterations = 0;
-	foreach($tables as $tmp) {
-		if ($tmp->getName() == 'table') {
-			$no_iterations ++;
-		}
-	}
-	print "$no_iterations html tables to be processed.\n";
-	$interval = intval($no_iterations * 0.01);
-	$idx_iterations = 0;
-
-	// Processed the tables
-	foreach ($tables as $table) {
-        //if (preg_match('/No hits reported/', $table->asXML()) ) {
-            //print "skipping this table b/c no hits are reported\n";
-        //}
-        // make sure we are looking at a table and its not an empty table
-        if ($table->getName() == 'table' && !preg_match('/No hits reported/', $table->asXML()) ) {
-            $idx_iterations ++;
-            if ($idx_iterations % $interval == 0) {
-                    $percentage = (int) ($idx_iterations / $no_iterations * 100);
-                    tripal_db_set_active($previous_db);
-                    tripal_job_set_progress($job_id, $percentage);
-                    $previous_db = tripal_db_set_active('chado');
-                    print $percentage."% ";
-            }
-
-            // Set job status
-            // Get the first row and match its name with the feature name
-            $firsttd = $table->children()->children()->children();
-            $feature_id = 0;
-            foreach($firsttd as $b) {
-                foreach($b->children() as $a) {
-                    if ($a->getName() == 'a') {
-                        // Remove _ORF from the sequence name
-                        $seqname = preg_replace('/^(.+?)_\d_.+/', "$1", $a);
-                        print "seqname is $seqname\n";
-    
-                        // Find out how many features match this uniquename
-                        $sql = "SELECT count(feature_id) FROM {feature} ".
-                        "WHERE uniquename = '%s' ";
-                        $no_features = db_result(db_query($sql, $seqname));
-						    
-                        // If there is only one match, get the feature_id
-                        if ($no_features == 1) {
-                            $sql = "SELECT feature_id FROM {feature} ".
-                                    "WHERE uniquename = '%s' ";
-                            $feature_id = db_result(db_query($sql, $seqname));
-                            print "\tfeature id is $feature_id\n";
-    
-                            // If the uniquename matches more than one features then skip and print 'Ambiguous'
-                        } else if ($no_features > 1) {
-                            fwrite($log, "Ambiguous: ".$seqname." matches more than one feature and is not processed.\n");
-                            continue;
-    
-                        // If the uniquename did not match, skip and print 'Failed'
-                        } else {
-                            fwrite($log, "Failed: ".$seqname."\n");
-                        }
-    
-                    }
-                }
-            }
-
-            // Successfully matched. print 'Succeeded'. Add analysis_id and
-            // feature_id to analysisfeature. Add the table as XML to analysisfeatureprop
-            if ($feature_id) {
-
-                //------------------------------------
-                // Clease unwanted rows from the table
-                //------------------------------------
-
-                $parent_row =   "/<tr><td valign=\"top\"><b>Parent<\/b><\/td>\s*<td valign=\"top\">\s*no.*?parent<\/td>\s*<\/tr>/";
-                $children_row = "/<tr><td valign=\"top\"><b>Children<\/b><\/td>\s*<td valign=\"top\">\s*no.*?children<\/td>\s*<\/tr>/";
-                $found_row    = "/<tr><td valign=\"top\"><b>Found.*?in<\/b><\/td>\s*<td valign=\"top\">\s*no.*?entries<\/td>\s*<\/tr>/";
-                $contains_row = "/<tr><td valign=\"top\"><b>Contains<\/b><\/td>\s*<td valign=\"top\">\s*no.*?entries<\/td>\s*<\/tr>/";
-                $go_row       = "/<tr><td valign=\"top\"><b>GO.*?terms<\/b><\/td>\s*<td valign=\"top\">\s*none<\/td>\s*<\/tr>/";
-    
-                $table_txt = $table->asXML();
-                $table_txt = preg_replace($parent_row, "", $table_txt);
-                $table_txt = preg_replace($children_row, "", $table_txt);
-                $table_txt = preg_replace($found_row, "", $table_txt);
-                $table_txt = preg_replace($contains_row, "", $table_txt);
-                $table_txt = preg_replace($go_row, "", $table_txt);
-
-                //------------------------------------
-                // Clease unwanted ORF link from table 
-                //------------------------------------
-                $orf_link = "/<b><a href=\"\/iprscan\/wget.*?\">(.*?)<\/a><\/b>/";
-                $table_txt = preg_replace($orf_link, "$1", $table_txt);
-
-                //print "----------------------------\n";
-                //print "old: ".$table->asXML()."\n\n\n";
-                //print "----------------------------\n";
-                //print "Fixed: $table_txt\n";
-                //print "----------------------------\n";
-
-                //------------------------------------
-                // If this feature has already been associated with this analysis, do not reinsert
-                // Otherwise, Insert into analysisfeature table
-                //------------------------------------
-                $sql = "Select analysisfeature_id as id from {analysisfeature} where feature_id = %d and analysis_id = %d";
-                $analysisfeature =  db_fetch_object(db_query($sql, $feature_id, $analysis_id));
-                if($analysisfeature){ $analysisfeature_id = $analysisfeature->id; }
-                if(!$analysisfeature_id){
-                    print "inserting analysisfeature\n";
-                   $sql = "INSERT INTO {analysisfeature} (feature_id, analysis_id) ".
-                        "VALUES (%d, %d)";
-                   db_query ($sql, $feature_id, $analysis_id);
-                   $sql = "Select analysisfeature_id from {analysisfeature} where feature_id = %d and analysis_id = %d";
-                   $analysisfeature =  db_fetch_object(db_query($sql, $feature_id, $analysis_id));
-                   $analysisfeature_id = $analysisfeature->id;
-                }
-
-                print "analysisfeature_id is $analysisfeature_id (analysis_id = $analysis_id; feature_id = $feature_id)\n";
-
-
-                // Get the higest rank for this feature_id in analysisfeatureprop table.
-                // If the value of the inserting content is not duplicate, add it to  
-                // analysisfeaturepro with 'higest_rank + 1'
-                $sql = "SELECT MAX(rank) FROM {analysisfeatureprop} AFP ".
-                        "INNER JOIN analysisfeature AF ON AF.analysisfeature_id = AFP.analysisfeature_id ".       
-                        "WHERE feature_id=%d ".
-                        "AND analysis_id=%d ".
-                        "AND type_id=%d ";
-
-                $afp =  db_fetch_object(db_query($sql, $feature_id, $analysis_id, $type_id));
-                $hi_rank = 0;
-                if ($afp) {
-                    $hi_rank = $afp->max + 1;
-                }
-            
-				//------------------------------------------------------------
-				// Insert interpro html tags into analysisfeatureprop table
-				//------------------------------------------------------------
-				// Before inserting, make sure it's not a duplicate
-				$sql = "SELECT value FROM {analysisfeatureprop} WHERE analysisfeature_id = %d AND type_id = %d";
-				$result = db_query($sql, $analysisfeature_id, $type_id);
-				$duplicate = 0;
-				while ($afp_value = db_fetch_object($result)) {
-				    if ($table_txt == $afp_value->value) {
-                        $duplicate = 1;
-				    }
-				}
-				if (!$duplicate) {
-				    $sql = "INSERT INTO {analysisfeatureprop} (analysisfeature_id, type_id, value, rank)".
-                            "VALUES (%d, %d, '%s', %d)";
-				    db_query($sql, $analysisfeature_id, $type_id, $table_txt, $hi_rank);
-				    fwrite($log, " (Insert)\n"); // write to log
-                    print "\twriting table\n";
-				} else {
-				   fwrite($log, " (Skipped)\n");
-                    print "\tskipping table - dup\n";
-				}
-				
-                // Parse GO terms. Make sure GO database schema is installed in chado
-                $go_db_id = db_result(db_query("SELECT db_id FROM {db} WHERE name='GO'"));
-                if (!$go_db_id) {
-                    print 'GO schema not installed in chado. GO terms are not processed.';
-                }
-                if ($go_db_id && $parsego) {
-                    $trs = $table->children();
-                    foreach ($trs as $tr) {
-                        $tds = $tr->children();
-                        foreach($tds as $td) {
-                            $gotags = $td->children();
-                            foreach ($gotags as $gotag) {
-                                // Look for 'GO:accession#'
-                                if (preg_match("/^.*?GO:(\d+).*$/", $gotag, $matches)) {
-                        	
-                                    // Find cvterm_id for the matched GO term
-                                    $sql = "SELECT cvterm_id FROM {cvterm} CVT 
-                                            INNER JOIN dbxref DBX ON CVT.dbxref_id = DBX.dbxref_id
-                                            WHERE DBX.accession = '%s' AND DBX.db_id = %d";
-                                    $goterm_id = db_result(db_query($sql, $matches[1], $go_db_id));
-                           
-                                    //-------------------------------------------
-                                    // Insert GO terms into feature_cvterm table
-                                    //-------------------------------------------
-                                    // Default pub_id = 1 (NULL) was used
-                                    $sql = "INSERT INTO {feature_cvterm} (feature_id, cvterm_id, pub_id)
-                                            VALUES (%d, %d, 1)";
-                                    db_query($sql, $feature_id, $goterm_id);
-
-                                    //------------------------------------------------
-                                    // Insert GO terms into analysisfeatureprop table
-                                    //------------------------------------------------
-                                    $sql = "INSERT INTO {analysisfeatureprop} (analysisfeature_id, type_id, value, rank) ".
-                                            "VALUES (%d, %d, '%s', 0)";
-                                    db_query($sql, $analysisfeature_id, $goterm_id, $matches[1]);
-                                }
-                            }
-                        }
-                    }
-                }
-            }
-        }
-    }
-    tripal_db_set_active ($previous_db); // Use drupal database
-    print "Done.\nSuccessful and failed entries have been saved in the log file:\n $logfile\n";
-	
-    fwrite($log, "\n");
-    fclose($log);
-    return;
-}
 
 
 /*******************************************************************************
 /*******************************************************************************
  * tripal_analysis_interpro_nodeapi()
  * tripal_analysis_interpro_nodeapi()
@@ -798,7 +358,7 @@ function tripal_analysis_interpro_theme () {
 
 
 function tripal_analysis_interpro_preprocess_tripal_feature_interpro_results(&$variables){
 function tripal_analysis_interpro_preprocess_tripal_feature_interpro_results(&$variables){
    $feature = $variables['node']->feature;
    $feature = $variables['node']->feature;
-	$variables['tripal_analysis_interpro']['results'] = tripal_get_interpro_results($feature->feature_id);
+	$variables['tripal_analysis_interpro']['results'] = tripal_get_interpro_XML_results($feature->feature_id);
 }
 }
 
 
 /*******************************************************************************
 /*******************************************************************************
@@ -809,12 +369,67 @@ function theme_parse_EBI_Interpro_XML_index_version ($node) {
 	$content = tripal_get_interpro_results_index_version($feature->feature_id);
 	$content = tripal_get_interpro_results_index_version($feature->feature_id);
 	return $content;
 	return $content;
 }
 }
+/**
+ * 
+ */
+function tripal_get_interpro_XML_results($feature_id){
+
+	// 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.
+   $select = array(
+      'analysisfeature_id' => array(
+         'feature_id' => $feature_id,
+      ), 
+      'type_id' => array(
+         'name' => 'analysis_interpro_xmloutput_hit',
+         'cv_id' => array(
+            'name' => 'tripal'
+         ),
+      ),         
+   );
+   $afeatureprops = tripal_core_chado_select('analysisfeatureprop',array('*'),$select);
+
+   // iterate through all of the interpro XML properties for this feature
+	$results = array ();
+	foreach ($afeatureprops as $index => $afeatureprop) {
+
+      // get the analysis feature record
+      $analysisfeature_arr = tripal_core_chado_select('analysisfeature',array('analysis_id'),
+         array('analysisfeature_id' => $afeatureprop->analysisfeature_id));
+      $analysisfeature = $analysisfeature_arr[0];
+
+      // get the analysis record and the analysis_id
+      $analysis = tripal_core_generate_chado_var('analysis',
+         array('analysis_id' => $analysisfeature->analysis_id));
+      $analysis_id = $analysis->analysis_id;
 
 
+
+      // parse the XML and add it to the array of blast results to be returned
+      $interpro_xml = $afeatureprop->value;
+      $orf = tripal_analysis_interpro_get_result_object($interpro_xml,$feature_id);
+		$results[$analysis->analysis_id]['protein_ORFs'][] = $orf;
+      $results[$analysis->analysis_id]['analysis'] = $analysis;
+
+      // iterate through all of the protein ORFs and combine the terms into one large list
+      if(!is_array($results[$analysis->analysis_id]['allterms'])){
+        $results[$analysis->analysis_id]['allterms'] = array();
+      }
+      if(!is_array($results[$analysis->analysis_id]['goterms'])){
+        $results[$analysis->analysis_id]['goterms'] = array();
+      }
+      $results[$analysis->analysis_id]['allterms'] = array_merge($results[$analysis->analysis_id]['allterms'],$orf['iprterms']);
+      $results[$analysis->analysis_id]['goterms'] = array_merge($results[$analysis->analysis_id]['goterms'],$orf['goterms']);
+      $i++;
+	}
+   return $results;
+}
 /*******************************************************************************
 /*******************************************************************************
  * tripal_get_interpro_results()
  * tripal_get_interpro_results()
  * Get interpro result from featureprop table for the feature
  * Get interpro result from featureprop table for the feature
  */
  */
-function tripal_get_interpro_results($feature_id){
+function tripal_get_interpro_HTML_results($feature_id){
 	// Get cvterm_id for 'analysis_interpro_output_hit' which is required
 	// Get cvterm_id for 'analysis_interpro_output_hit' which is required
 	// for inserting into the analysisfeatureprop table
 	// for inserting into the analysisfeatureprop table
 	$previous_db = tripal_db_set_active('chado');
 	$previous_db = tripal_db_set_active('chado');

+ 370 - 259
tripal_analysis_kegg/tripal_analysis_kegg.module

@@ -379,10 +379,11 @@ function tripal_analysis_kegg_parseHierFile ($analysis_id, $hierfile, $base_path
    $interval = intval($total_files * 0.01);
    $interval = intval($total_files * 0.01);
    $no_file = 0;
    $no_file = 0;
 
 
-   // Remove the analysis features for this analysis
+   // Remove the analysis feature this analysis
    // we will rebuild them from just this parsing
    // we will rebuild them from just this parsing
-   if(!tripal_core_chado_delete('analysisfeature',array('analysis_id' => $analysis_id))){
-      print "ERROR: Cannot prepare the analysis for addint features\n";
+   $select =  array('analysis_id' => $analysis_id);
+   if(!tripal_core_chado_delete('analysisfeature',$select)){
+      print "ERROR: Cannot prepare the analysis for adding features\n";
       exit;
       exit;
    }
    }
 
 
@@ -397,17 +398,17 @@ function tripal_analysis_kegg_parseHierFile ($analysis_id, $hierfile, $base_path
          }
          }
          $no_file ++;
          $no_file ++;
          
          
-         # $type variable will be set in tripal_analysis_kegg_parse_kegg_file()
-         $content = tripal_analysis_kegg_parse_kegg_file("$hierdir/$file",$type,
+         # $heirarchy variable will be set in tripal_analysis_kegg_parse_kegg_file()
+         $results = tripal_analysis_kegg_parse_kegg_file("$hierdir/$file",$heirarchy,
             $analysis_id, $base_path, $query_re,$query_type,$query_uniquename);
             $analysis_id, $base_path, $query_re,$query_type,$query_uniquename);
 
 
          # add the item to the database
          # add the item to the database
-         if($content){
+         if(count($results) > 0){
             //------------------------------------------------------
             //------------------------------------------------------
             // Insert into analysisprop table
             // Insert into analysisprop table
             //------------------------------------------------------
             //------------------------------------------------------
-            // Make sure the same value doesn't exist before inserting into chado
-            $sql = "SELECT value
+            // Remove the property if it already exists we'll replace it
+            $sql = "DELETE
                     FROM {analysisprop}
                     FROM {analysisprop}
                     WHERE analysis_id = %d
                     WHERE analysis_id = %d
                     AND type_id = (SELECT cvterm_id 
                     AND type_id = (SELECT cvterm_id 
@@ -416,31 +417,35 @@ function tripal_analysis_kegg_parseHierFile ($analysis_id, $hierfile, $base_path
                                    WHERE CV.name = 'tripal' AND CVT.name = '%s'
                                    WHERE CV.name = 'tripal' AND CVT.name = '%s'
                                    )
                                    )
                    ";
                    ";
+
             $previous_db = tripal_db_set_active('chado');
             $previous_db = tripal_db_set_active('chado');
-            $oldvalue = db_result(db_query($sql, $analysis_id, $type));
+            db_result(db_query($sql, $analysis_id, $heirarchy));
             tripal_db_set_active($previous_db);
             tripal_db_set_active($previous_db);
             
             
-            // Insert the content
-            if ($oldvalue != $content) {
-            	
-            	$previous_db = tripal_db_set_active('chado'); // Use chado database
-            	// Get type_id for the BRITE term
-            	$sql = "SELECT cvterm_id 
-                       FROM {cvterm} CVT 
-                       INNER JOIN CV ON CVT.cv_id = CV.cv_id
-                       WHERE CV.name = 'tripal' AND CVT.name = '%s'";
-            	$brite_cvterm_id = db_result(db_query($sql, $type)); 
-
-            	// Replace all single quote as HTML code before insert
-            	$content = preg_replace("/\'/", "&#39;", $content);
             	
             	
-            	// Insert the value
-               $sql = "INSERT INTO {analysisprop} (analysis_id, type_id, value) 
-                       VALUES (%d, %d,'$content')";   
-               
-               db_query($sql, $analysis_id, $brite_cvterm_id);
-               tripal_db_set_active($previous_db); // Use drupal database
-            }
+         	$previous_db = tripal_db_set_active('chado'); // Use chado database
+         	// Get type_id for the BRITE term
+         	$sql = "SELECT cvterm_id 
+                    FROM {cvterm} CVT 
+                    INNER JOIN CV ON CVT.cv_id = CV.cv_id
+                    WHERE CV.name = 'tripal' AND CVT.name = '%s'";
+         	$brite_cvterm_id = db_result(db_query($sql, $heirarchy)); 
+
+            // convert the array to text for saving in the database
+         	// Replace all single quote as HTML code before insert
+            $i = 0;
+            $content = '<ul>';
+            tripal_analysis_kegg_array2list($results,$content,$i);
+            $content .= '</ul>';
+         	$content = preg_replace("/\'/", "&#39;", $content);
+         	
+         	// Insert the value
+            $sql = "INSERT INTO {analysisprop} (analysis_id, type_id, value) 
+                    VALUES (%d, %d,'$content')";   
+            
+            db_query($sql, $analysis_id, $brite_cvterm_id);
+            tripal_db_set_active($previous_db); // Use drupal database
+
             
             
          }
          }
       }
       }
@@ -455,200 +460,294 @@ function tripal_analysis_kegg_parseHierFile ($analysis_id, $hierfile, $base_path
    }
    }
    return;
    return;
 }
 }
+/**
+*
+*/
+function tripal_analysis_kegg_array2list($array,&$content,&$i){
+   foreach($array as $index => $item){
+      if(is_array($item)){
+         if(is_numeric($index)){
+            tripal_analysis_kegg_array2list($item,$content,$i);
+         } else {
+            $content .= "<li id=\"term_$i\"><a></a>$index\n<ul>";
+            $i++;
+            tripal_analysis_kegg_array2list($item,$content,$i);
+            $content .= "</ul>\n</li>\n";
+         }
+      } else {
+         $content .= "<li id=\"term_$i\"><a></a>$item</li>\n";
+         $i++;
+      }
+   }   
+}
 /*******************************************************************************
 /*******************************************************************************
  * Parse *.keg files. 
  * Parse *.keg files. 
  * Each file has a definition line. BRITE term is extracted * from this line 
  * Each file has a definition line. BRITE term is extracted * from this line 
  * and added to chado as a cvterm. Tree structure for this cvterm is then 
  * and added to chado as a cvterm. Tree structure for this cvterm is then 
  * generated and saved to analysisfeature and analysisfeatureprop tables.
  * generated and saved to analysisfeature and analysisfeatureprop tables.
  */
  */
-function tripal_analysis_kegg_parse_kegg_file ($file,&$type,$analysis_id, $base_path, $query_re,$query_type,$query_uniquename){
-   $handle = fopen($file,'r');
-   $depth = array();
-   $current = '@';  # this is one character below 'A' in the ASCII table
-   $prev = '@';
-   $id = 0;
-   $type_id = 0;
-   $no_line = 0;
-   $ul_content = array();
-   $has_feature = 0;
-   $level = -1;
+function tripal_analysis_kegg_parse_kegg_file ($file, &$heirarchy, $analysis_id, 
+   $base_path, $query_re, $query_type, $query_uniquename)
+{
+
+   print "Parsing $file\n";
 
 
+   // get the 'kegg_brite_data' cvterm
+   $select = array('name' => 'kegg_brite_data', 
+                   'cv_id' => array('name' => 'tripal'));
+   $bdt_arr = tripal_core_chado_select('cvterm',array('cvterm_id'),$select);
+   $brite_id = $bdt_arr[0]->cvterm_id;
+
+   $filepos = 0;
+
+   // iterate through the lines of the file and recurse through the various levels
+   $handle = fopen($file,'r');
    while($line = fgets($handle)){
    while($line = fgets($handle)){
-      $no_line ++;
-      // Find out what kind of file we're looking at.
+      $filepos += strlen($line);
+      $line = trim($line);
+
+      // the first line of the file provides the BRITE heirarchy name
       if(preg_match("/#.*nbsp;\s(.*)<\/h2>$/",$line,$matches)){
       if(preg_match("/#.*nbsp;\s(.*)<\/h2>$/",$line,$matches)){
-         // Set type as the matched term in the DEFINITION line and add it as a new cvterm
-         $type = $matches[1];
-         // Before inserting, make sure this cvterm doesn't exist
-         $previous_db = tripal_db_set_active('chado');
-         $sql = "SELECT cvterm_id 
-                 FROM {cvterm} CVT
-                 INNER JOIN cv ON cv.cv_id = CVT.cv_id
-                 WHERE cv.name = 'tripal'
-                 AND CVT.name = '%s'";
-         $type_id = db_result(db_query($sql, $type));
-         tripal_db_set_active($previous_db);
-         if (!$type_id) {
+         // For each BRITE heirarchy file we'll add an analysisprop where we'll
+         // store the report.  If the CVTerm doesn't exist then add it.
+         $heirarchy = $matches[1];
+         $select = array('name' => $heirarchy,'cv_id' => array('name' => 'tripal'));
+         $cvt_arr = tripal_core_chado_select('cvterm',array('cvterm_id'),$select);
+         if (count($cvt_arr) == 0) {
             tripal_add_cvterms($type, "KEGG BRITE term: $type");
             tripal_add_cvterms($type, "KEGG BRITE term: $type");
-            // Get newly added type_id
-            $sql = "SELECT cvterm_id 
-                    FROM {cvterm} CVT
-                    INNER JOIN cv ON cv.cv_id = CVT.cv_id
-                    WHERE cv.name = 'tripal'
-                    AND CVT.name = '%s'";
-            $previous_db = tripal_db_set_active('chado');
-            $type_id = db_result(db_query($sql, $type));
-            tripal_db_set_active($previous_db);
+            $cvt_arr = tripal_core_chado_select('cvterm',array('cvterm_id'),$select);
+         }
+         $heirarchy_id = $cvt_arr[0]->cvterm_id;
+
+         // now that we have the file type we can recurse
+         $next = tripal_analysis_kegg_get_next_line($handle,$filepos);
+         $results = tripal_analysis_kegg_recurse_heir($handle,$next,$query_re,
+            $query_type,$query_uniquename,$base_path,$analysis_id,
+            $brite_id,$heirarchy,$filepos);
+      }
+   }
+   fclose($handle);
+   return $results;
+}
+
+/**
+*
+*/
+function tripal_analysis_kegg_recurse_heir($handle, $line,$query_re,
+   $query_type, $query_uniquename, $base_path, $analysis_id, $brite_id, 
+   $heirarchy,&$filepos)
+{
+   $results = array(); 
+
+   // get the current level and the value
+   $level = $line[0];
+   $value = $line[1];
+
+   // now get the next line to see what is coming next.  If the 
+   // next level is greater then recurse immediately. 
+   $prevpos = $filepos;
+   while($next = tripal_analysis_kegg_get_next_line($handle,$filepos)){
+      $next_level = $next[0];
+      $next_value = $next[1];
+
+      // check this line to see if it has a feature we need to keep
+      $ret = tripal_analysis_kegg_check_line_handle_feature($query_re,
+         $query_type, $query_uniquename, $base_path, $analysis_id, $brite_id, 
+         $heirarchy,$value);
+      if($ret){
+         $results[] = $ret;
+      }
+
+      // if we're going up a level then recurse immediately and add results to our array
+      if(ord($next_level) > ord($level)){
+         // now recurse
+         $ret = tripal_analysis_kegg_recurse_heir($handle,$next, 
+            $query_re,$query_type, $query_uniquename, $base_path, $analysis_id,
+            $brite_id,$heirarchy,$filepos);
+         if(count($ret) > 0){
+            $results[][$value] = $ret; 
          }
          }
       }
       }
-      // get the depth of the hierarch (e.g. A,B,C or D);
+
+      // if we go down a level on the next line then reset the 
+      // filepointer and return
+      elseif(ord($next_level) < ord($level)){
+          fseek($handle,$prevpos);
+          $filepos = $prevpos;
+          return $results;
+      }
+      else {
+         $line = $next;
+         $level = $next[0];
+         $value = $next[1];
+      }
+      $prevpos = $filepos; 
+   }
+
+   return $results;
+}
+/**
+*
+*/
+
+function tripal_analysis_kegg_get_next_line($handle,&$filepos){
+   $good = 0;
+
+   // get the next line in the file
+   $line = fgets($handle);
+   $filepos += strlen($line);
+
+   // we hit the end of the file, so exit with a null
+   if(!$line){
+      return null;
+   }  
+   while(!$good){
+      $line = trim($line);
       preg_match("/^([ABCDEFGHIJKLMNOP])\s*(.*)/",$line,$matches);
       preg_match("/^([ABCDEFGHIJKLMNOP])\s*(.*)/",$line,$matches);
+      $level = $matches[1];
+      $value = $matches[2];
 
 
       // skip lines that aren't data or are empty
       // skip lines that aren't data or are empty
-      if(!$matches[1] or !$matches[2]){continue;}
- 
-      // set the current level and keep track of the previous level (e.g. A,B,C...)
-      $prev = $current;
-      $current = $matches[1];
-
-      // if we have matches and we are going down to a lower level then we 
-      // want to close off each <ul> until we hit the level we are currently at
-      // and at the same time we want to keep the text. If we don't have a 
-      // match then we'll throw out the text.
-      if($has_feature){
-         for($i = (ord($current) - ord($prev)); $i < 0; $i++){
-            $ul_content[$level] .= "</ul>\n";
-            $content .= $ul_content[$level];
-            $ul_content[$level--] = '';
-         }
-         $has_feature = 0;
+      if($level and $value) {
+
+         // change all relative paths to absolute paths pointing to KEGG (www.genome.jp)
+         // add id to <a> tags so we can link kegg.gif to it in tripal_analysis_kegg.css
+         $value = preg_replace("/<a href=\"\//i","<a href=\"http://www.genome.jp/",$value);     
+         $value = preg_replace("/<a href=\"/i","<a id=\"tripal_kegg_brite_links\" target=\"_blank\" href=\"",$value);
+
+         // this line is good so let's exit out
+         $good = 1;
       } else {
       } else {
-         for($i = (ord($current) - ord($prev)); $i < 0; $i++){
-            $ul_content[$level--] = '';
+         $line = fgets($handle);
+         $filepos += strlen($line);
+         // we hit the end of the file, so exit with a null
+         if(!$line){
+            return null;
+         }         
+      }
+   }
+   return array($level,$value);
+}
+/**
+*
+*/
+function tripal_analysis_kegg_check_line_handle_feature($query_re,
+   $query_type, $query_uniquename, $base_path, $analysis_id, $brite_id, 
+   $heirarchy,$value)
+{
+
+   // extract the features that have been mapped to the KEGG IDs
+   if(preg_match("/^(.*?);\s*(\<a.+)/",$value,$matches)){
+      $has_feature = 1;
+      $fname = $matches[1];
+      $keggterm = $matches[2];
+
+		// get the feature name using the user's regular expression
+		if ($query_re and preg_match("/$query_re/", $fname, $matches)) {
+			$feature = $matches[1];
+		} 
+      // If not in above format then pull up to the first space
+      else {
+			if (preg_match('/^(.*?)\s.*$/', $fname, $matches)) {
+				$feature = $matches[1];
+         } 
+         // if no match up to the first space then just use the entire string
+         else {
+            $feature = $fname;
          }
          }
+      } 
+
+      // now find the feature in chado
+      $select = array();
+      if($query_uniquename){
+         $select['uniquename'] = $feature;
+      } else {
+         $select['name'] = $feature;
       }
       }
-      // if we've gone up a level then add a new <ul> block
-      for($i = 0; $i < (ord($current) - ord($prev)); $i++){
-         $ul_content[++$level] .= "<ul>\n";
+      if($query_type){
+         $select['type_id'] = array(
+           'cv_id' => array(
+              'name' => 'sequence'
+           ),
+           'name' => $query_type,
+         );
       }
       }
-      
-      // change all relative paths to absolute paths pointing to KEGG (www.genome.jp)
-      $matches[2] = preg_replace("/<a href=\"\//i","<a href=\"http://www.genome.jp/",$matches[2]);
-      
-      // add id to <a> tags so we can link kegg.gif to it in tripal_analysis_kegg.css
-      $matches[2] = preg_replace("/<a href=\"/i","<a id=\"tripal_kegg_brite_links\" target=\"_blank\" href=\"",$matches[2]);
-
-      // extract the features that have been mapped to the KEGG IDs
-      if(preg_match("/^(.*?);\s*(\<a.+)/",$matches[2],$keggline)){
-         $has_feature = 1;
-
-         // Find cvterm_id for 'kegg_brite_data'
-         $sql = "SELECT cvterm_id 
-                 FROM {cvterm} CVT
-                 INNER JOIN cv ON cv.cv_id = CVT.cv_id
-                 WHERE cv.name = 'tripal'
-                 AND CVT.name = '%s'";
-         $previous_db = tripal_db_set_active('chado');
-         $brite_data_type_id = db_result(db_query($sql, 'kegg_brite_data'));
-         tripal_db_set_active($previous_db);
-
-			// get the feature name using the user's regular expression
-			if ($query_re and preg_match("/$query_re/", $keggline[1], $parts)) {
-				$feature = $parts[1];
-			} 
-         // If not in above format then pull up to the first space
-         else {
-				if (preg_match('/^(.*?)\s.*$/', $keggline[1], $parts)) {
-					$feature = $parts[1];
-            } 
-            // if no match up to the first space then just use the entire string
-            else {
-               $feature = $keggline[1];
-            }
-         } 
+      $feature_arr = tripal_core_chado_select('feature',array('feature_id'),$select);
 
 
-         // now find the feature in chado
-         $select = array();
-         if($query_uniquename){
-            $select['uniquename'] = $feature;
-         } else {
-            $select['name'] = $feature;
-         }
-         if($query_type){
-            $select['type_id'] = array(
-              'cv_id' => array(
-                 'name' => 'sequence'
-              ),
-              'name' => $query_type,
-            );
-         }
-         $feature_arr = tripal_core_chado_select('feature',array('feature_id'),$select);
+      if(count($feature_arr) > 1){
+		   print "Ambiguous: '$feature' matches more than one feature and is being skipped.\n";
+			continue;
+      }
+      if(count($feature_arr) == 0){
+			print "Failed: '$feature' cannot find a matching feature in the database.\n";
+         continue;
+      }
+      $feature_id = $feature_arr[0]->feature_id;
 
 
-         if(count($feature_arr) > 1){
-			   print "Ambiguous: '$feature' matches more than one feature and is being skipped.\n";
-				continue;
-         }
-         if(count($feature_arr) == 0){
-				print "Failed: '$feature' cannot find a matching feature in the database.\n";
-            continue;
-         }
-         print "Adding KEGG results for $feature ($feature_id,$analysis_id): $type\n";
-         $feature_id = $feature_arr[0]->feature_id;
+      if($feature_id){
+         print "Adding KEGG term for $feature ($feature_id,$analysis_id). $heirarchy\n";
 
 
-         if($feature_id){
-            // get the node ID of the feature if one exists
-            $sql = "SELECT nid FROM {chado_feature} WHERE feature_id = %d";
-            $nid = db_result(db_query($sql, $feature_id)); 
-    
-            //------------------------------------------------------
-            // Insert into analysisfeature table
-            //------------------------------------------------------
-            // Get the higest rank for this feature_id in analysisfeatureprop table
-            $sql = "SELECT MAX(rank) FROM {analysisfeatureprop} AFP ".
-                   "INNER JOIN analysisfeature AF ON AF.analysisfeature_id = AFP.analysisfeature_id ".       
-                   "WHERE feature_id=%d ".
-                   "AND analysis_id=%d ".
-                   "AND type_id=%d ";
-            $previous_db = tripal_db_set_active('chado');
-            $afp =  db_fetch_object(db_query($sql, $feature_id, $analysis_id, $brite_data_type_id));
-            tripal_db_set_active($prevous_db);
-            $hi_rank = 0;
-            if ($afp) {
-               $hi_rank = $afp->max + 1;
-            }
+         // add this term to the analysis feature properties
+         tripal_analysis_kegg_insert_featureprop($feature_id,$analysis_id,
+            $brite_id,$keggterm);
 
 
-            $sql = "INSERT INTO {analysisfeature} (feature_id, analysis_id) ".
-                   "VALUES (%d, %d)";
-            $previous_db = tripal_db_set_active('chado');
-            db_query ($sql, $feature_id, $analysis_id);
-            tripal_db_set_active($previous_db);
+         // get the node ID of the feature if one exists
+         $sql = "SELECT nid FROM {chado_feature} WHERE feature_id = %d";
+         $nid = db_result(db_query($sql, $feature_id)); 
 
 
-            // Get the newly inserted analysisfeature_id
-            $sql = "SELECT analysisfeature_id FROM {analysisfeature} WHERE feature_id = %d AND analysis_id = %d";
-            $previous_db = tripal_db_set_active('chado');
-            $analysisfeature_id = db_result(db_query($sql, $feature_id, $analysis_id));
-            tripal_db_set_active($previous_db);
-            
-            // Insert into analysisfeatureprop table
-            $sql = "INSERT INTO {analysisfeatureprop} (analysisfeature_id, type_id, value, rank)".
-                   "VALUES (%d, %d, '%s', %d)";
-            $previous_db = tripal_db_set_active('chado');
-            db_query($sql, $analysisfeature_id, $brite_data_type_id, $keggline[2], $hi_rank);
-            tripal_db_set_active($previous_db);
+         // Add link to each matched feature
+         if($nid){
+            $value = preg_replace("/^(.*?)(;\s*\<a)/","<a id=\"tripal_kegg_feature_links\" target=\"_blank\" href=\"".url("node/$nid")."\">"."$1"."</a>"."$2",$value);
 
 
-            // Add link to each matched feature
-            if($nid){
-               $matches[2] = preg_replace("/^(.*?)(;\s*\<a)/","<a id=\"tripal_kegg_feature_links\" target=\"_blank\" href=\"".url("/node/$nid")."\">"."$1"."</a>"."$2",$matches[2]);
-            }
          }
          }
-         // we only want to store results with features
-         $ul_content[$level] .= "<li id=\"term_$id\">$matches[2]</li>\n";
-      }     
-      $id++;
+         // if we have a feature match then add this to our results array
+         return $value;  
+      }       
+   }
+   return null;
+}
+/**
+*
+*/
+function tripal_analysis_kegg_insert_featureprop ($feature_id, $analysis_id,
+   $brite_id,$keggterm)
+{
+
+   // add the analysisfeature record if it doesn't already exist.
+   $values = array('feature_id' => $feature_id,'analysis_id' => $analysis_id);
+   $analysisfeature_arr = tripal_core_chado_select('analysisfeature',
+      array('analysisfeature_id'),$values);
+   if(count($analysisfeature_arr) == 0){
+      tripal_core_chado_insert('analysisfeature',$values);
+      $analysisfeature_arr = tripal_core_chado_select('analysisfeature',
+         array('analysisfeature_id'),$values);
+   }
+   $analysisfeature_id = $analysisfeature_arr[0]->analysisfeature_id;            
+   // Insert into analysisfeatureprop if the value doesn't already exist
+   // KEGG heir results sometimes have the same record more than once.
+   if($analysisfeature_id){
+      // Get the highest rank for this feature_id in analysisfeatureprop table
+      $sql = "SELECT rank FROM analysisfeatureprop WHERE analysisfeature_id = %d and type_id = %d ORDER BY rank DESC";
+      $previous_db = tripal_db_set_active('chado');
+      $result = db_fetch_object(db_query($sql,$analysisfeature_id,$brite_id));
+      tripal_db_set_active($previous);
+      $rank = 0;
+      if ($result and $result->rank > 0) {
+         $rank = $result->rank + 1;
+      }
+
+      $values = array(
+         'analysisfeature_id' => $analysisfeature_id, 
+         'type_id' => $brite_id,
+         'value' => $keggterm,
+         'rank' => $rank,
+      );
+
+      return tripal_core_chado_insert('analysisfeatureprop',$values);
+   }
+   else {
+      return 0;
    }
    }
-   $content .= "</ul>";
-   fclose($handle);
-   return $content;
 }
 }
 /*******************************************************************************
 /*******************************************************************************
  * HOOK: Implementation of hook_nodeapi()
  * HOOK: Implementation of hook_nodeapi()
@@ -673,12 +772,16 @@ function tripal_analysis_kegg_nodeapi(&$node, $op, $teaser, $page) {
          } else {
          } else {
             switch($node->type){
             switch($node->type){
                case 'chado_organism':
                case 'chado_organism':
-                  // Show KEGG BRITE on an analysis page OR KEGG info box on a feature page
+                  // Show KEGG report on the analysis page
                   $node->content['tripal_organism_kegg_summary'] = array(
                   $node->content['tripal_organism_kegg_summary'] = array(
                      '#value' => theme('tripal_organism_kegg_summary', $node),
                      '#value' => theme('tripal_organism_kegg_summary', $node),
-                     '#weight' => 6
                   );
                   );
                   break;
                   break;
+               case 'chado_feature':
+                  // Show KEGG terms on a feature page
+                  $node->content['tripal_feature_kegg_terms'] = array(
+                     '#value' => theme('tripal_feature_kegg_terms', $node),
+                  );
             }
             }
 
 
          }
          }
@@ -703,6 +806,10 @@ function tripal_analysis_kegg_theme () {
          'arguments' => array('node'=> null),
          'arguments' => array('node'=> null),
          'template' => 'tripal_organism_kegg_summary',
          'template' => 'tripal_organism_kegg_summary',
       ),
       ),
+      'tripal_feature_kegg_terms' => array (
+         'arguments' => array('node'=> null),
+         'template' => 'tripal_feature_kegg_terms',
+      ),
       'tripal_analysis_kegg_report' => array (
       'tripal_analysis_kegg_report' => array (
          'arguments' => array('node'=> null),
          'arguments' => array('node'=> null),
          'template' => 'tripal_analysis_kegg_report',
          'template' => 'tripal_analysis_kegg_report',
@@ -731,6 +838,14 @@ function tripal_analysis_kegg_preprocess_tripal_organism_kegg_summary(&$variable
    $node = $variables['node'];
    $node = $variables['node'];
    $variables['tripal_analysis_kegg']['select_form'] = tripal_analysis_kegg_load_organism_kegg_summary($node);
    $variables['tripal_analysis_kegg']['select_form'] = tripal_analysis_kegg_load_organism_kegg_summary($node);
 }
 }
+/**
+*
+*/
+function tripal_analysis_kegg_preprocess_tripal_feature_kegg_terms(&$variables){
+   $node = $variables['node'];
+   $feature = $node->feature;
+   $variables['tripal_analysis_kegg']['results'] = tripal_analysis_kegg_load_feature_terms($feature);
+}
 /************************************************************************
 /************************************************************************
  */
  */
 function theme_tripal_analysis_kegg_search_index($node){
 function theme_tripal_analysis_kegg_search_index($node){
@@ -742,7 +857,7 @@ function theme_tripal_analysis_kegg_search_index($node){
               WHERE cv.name = 'tripal'
               WHERE cv.name = 'tripal'
               AND CVT.name = '%s'";
               AND CVT.name = '%s'";
       $previous_db = tripal_db_set_active('chado');
       $previous_db = tripal_db_set_active('chado');
-      $brite_data_type_id = db_result(db_query($sql, 'kegg_brite_data'));
+      $brite_id = db_result(db_query($sql, 'kegg_brite_data'));
       
       
       // Get analysis id
       // Get analysis id
       $sql = "SELECT analysis_id AS aid 
       $sql = "SELECT analysis_id AS aid 
@@ -753,8 +868,8 @@ function theme_tripal_analysis_kegg_search_index($node){
               GROUP BY analysis_id";
               GROUP BY analysis_id";
       $feature = $node->feature;
       $feature = $node->feature;
       $feature_id = $feature->feature_id;
       $feature_id = $feature->feature_id;
-      $hasResult = db_result(db_query($sql, $feature_id, $brite_data_type_id));
-      $result = db_query($sql, $feature->feature_id, $brite_data_type_id);
+      $hasResult = db_result(db_query($sql, $feature_id, $brite_id));
+      $result = db_query($sql, $feature->feature_id, $brite_id);
 
 
       // Show kegg result ORDER BY time
       // Show kegg result ORDER BY time
       if ($hasResult) { // If there is any result, show expandable box
       if ($hasResult) { // If there is any result, show expandable box
@@ -800,6 +915,7 @@ function theme_tripal_analysis_kegg_search_result($node){
    return $content;
    return $content;
 }
 }
 
 
+
 /************************************************************************
 /************************************************************************
  */
  */
 function tripal_analysis_kegg_load_organism_kegg_summary($node) {
 function tripal_analysis_kegg_load_organism_kegg_summary($node) {
@@ -905,67 +1021,62 @@ function tripal_analysis_kegg_organism_results($node) {
 }
 }
 /************************************************************************
 /************************************************************************
 */
 */
-function tripal_analysis_kegg_feature_add($node) {
-      // Find cvterm_id for 'kegg_brite_data'
-      $sql = "SELECT cvterm_id 
-              FROM {cvterm} CVT
-              INNER JOIN cv ON cv.cv_id = CVT.cv_id
-              WHERE cv.name = 'tripal'
-              AND CVT.name = '%s'";
-      $previous_db = tripal_db_set_active('chado');
-      $brite_data_type_id = db_result(db_query($sql, 'kegg_brite_data'));
-      
-      // Get analysis id
-      $sql = "SELECT analysis_id AS aid 
-              FROM {analysisfeature} AF 
-              INNER JOIN analysisfeatureprop AFP ON AF.analysisfeature_id = AFP.analysisfeature_id
-              WHERE feature_id = %d
-              AND AFP.type_id = %d
-              GROUP BY analysis_id";
-      $feature = $node->feature;
-      $feature_id = $feature->feature_id;
-      $hasResult = db_result(db_query($sql, $feature_id, $brite_data_type_id));
-      $result = db_query($sql, $feature->feature_id, $brite_data_type_id);
+function tripal_analysis_kegg_load_feature_terms($feature) {
+  
+   $feature_id = $feature->feature_id;
+
+	// Get the KEGG results stored using the term 'kegg_brite_data'
+   $select = array(
+      'analysisfeature_id' => array(
+         'feature_id' => $feature_id,
+      ), 
+      'type_id' => array(
+         'name' => 'kegg_brite_data',
+         'cv_id' => array(
+            'name' => 'tripal'
+         ),
+      ),         
+   );
+   $afeatureprops = tripal_core_chado_select('analysisfeatureprop',array('*'),$select);
 
 
-      // 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\">
-                        <table class=\"tripal_kegg_results_table\">
-                          <tr><td>";
+   // iterate through all of the KEGG properties for this feature
+   $results = array();
+	foreach ($afeatureprops as $index => $afeatureprop) {
 
 
-         while ($ana = db_fetch_object($result)) {
-            // Show analysis date
-            $sql = "SELECT name, to_char(timeexecuted, 'MM-DD-YYYY') AS time 
-                    FROM {analysis} 
-                    WHERE analysis_id = %d";
-            $ana_details = db_fetch_object(db_query($sql, $ana->aid));
-            // Find node id for the analysis
-            tripal_db_set_active($previous_db);
-            $ana_nid = db_result(db_query("SELECT nid FROM {chado_analysis} WHERE analysis_id = %d", $ana->aid));
-            $ana_url = url("node/".$ana_nid);
-            $previous_db = tripal_db_set_active('chado');
-       
-            // Show content
-            $content .= "<strong>Analysis Date:</strong> $ana_details->time
-                           (<a href=$ana_url>$ana_details->name</a>)<br>";
-         
-            // Show Kegg results
-            $sql = "SELECT AFP.value AS afpvalue
-                    FROM {analysisfeatureprop} AFP
-                    INNER JOIN analysisfeature AF on AF.analysisfeature_id = AFP.analysisfeature_id
-                    WHERE AF.analysis_id = %d
-                    AND AF.feature_id = %d
-                   ";
-            $kegg_results = db_query($sql, $ana->aid, $feature_id);
-            while ($afp = db_fetch_object($kegg_results)) {
-               $content .= "$afp->afpvalue<br>";
-            }
-            $content .= "<br>";
-         }
-         $content .= '</td></tr></table></div>';
+      // get the analysis feature record
+      $analysisfeature_arr = tripal_core_chado_select('analysisfeature',array('analysis_id'),
+         array('analysisfeature_id' => $afeatureprop->analysisfeature_id));
+      $analysisfeature = $analysisfeature_arr[0];
+
+      // get the analysis record and the analysis_id
+      $analysis = tripal_core_generate_chado_var('analysis',
+         array('analysis_id' => $analysisfeature->analysis_id));
+      $analysis_id = $analysis->analysis_id;
+    
+      $results[$analysis_id]['analysis'] = $analysis;
+   }
+
+   // now get all the terms for each analysis
+   foreach($results as $analysis_id => $arr){
+      $select = array(
+         'analysisfeature_id' => array(
+            'analysis_id' => $analysis_id,
+            'feature_id' => $feature_id,
+         ),
+         'type_id' => array(
+            'name' => 'kegg_brite_data',
+            'cv_id' => array(
+               'name' => 'tripal',
+            ),
+         ),
+      );
+      $terms = tripal_core_chado_select('analysisfeatureprop',array('*'),$select);
+      foreach ($terms as $term){
+         $results[$analysis_id]['terms'][] = $term->value;
       }
       }
-      tripal_db_set_active($previous_db);
-   return $content;
+   }
+
+   return $results;
 }
 }
 /************************************************************************
 /************************************************************************
 */
 */

+ 4 - 0
tripal_core/tripal_core.module

@@ -44,6 +44,10 @@ function tripal_core_init(){
       }  
       }  
       tripal_db_set_active($previous_db);  // now use drupal database
       tripal_db_set_active($previous_db);  // now use drupal database
    }
    }
+
+   // the tripal themeing uses rounded corners. We could use CSS but IE8 doesn't supprt
+   // rouneded corners so we will use the JQuery method.
+   drupal_add_js (drupal_get_path('theme', 'tripal').'/js/jquery-corners-0.3/jquery.corners.min.js');
 }
 }
 
 
 /**
 /**