Browse Source

Renamed include files in the tripal_core module that didn't get renamed. Fixed sequence template to better handle original, alignment and protein sequences

Stephen Ficklin 11 years ago
parent
commit
979660aa34

+ 0 - 0
tripal_core/includes/chado_install.inc → tripal_core/includes/tripal_core.chado_install.inc


+ 0 - 0
tripal_core/includes/custom_tables.inc → tripal_core/includes/tripal_core.custom_tables.inc


+ 0 - 0
tripal_core/includes/form_elements.inc → tripal_core/includes/tripal_core.form_elements.inc


+ 0 - 0
tripal_core/includes/jobs.inc → tripal_core/includes/tripal_core.jobs.inc


+ 0 - 0
tripal_core/includes/mviews.inc → tripal_core/includes/tripal_core.mviews.inc


+ 1 - 1
tripal_core/theme/templates/node--chado-generic.tpl.php

@@ -25,7 +25,7 @@ else {
   
       // if a ?block= is specified in the URL then we want to show the
       // requested block
-      var block = window.location.href.match(/[\?|\&]block=(.+?)\&/)
+      var block = window.location.href.match(/[\?|\&]block=(.+?)[\&|\#]/)
       if(block == null){
         block = window.location.href.match(/[\?|\&]block=(.+)/)
       }

+ 5 - 5
tripal_core/tripal_core.module

@@ -36,11 +36,11 @@ require_once 'api/tripal_core.tripal.api.inc';
 require_once 'api/tripal_core.DEPRECATED.inc';
 
 // INCLUDES -------------------------------------
-require_once 'includes/jobs.inc';
-require_once 'includes/mviews.inc';
-require_once 'includes/custom_tables.inc';
-require_once 'includes/chado_install.inc';
-require_once 'includes/form_elements.inc';
+require_once 'includes/tripal_core.jobs.inc';
+require_once 'includes/tripal_core.mviews.inc';
+require_once 'includes/tripal_core.custom_tables.inc';
+require_once 'includes/tripal_core.chado_install.inc';
+require_once 'includes/tripal_core.form_elements.inc';
 
 tripal_core_set_globals();
 /**

+ 46 - 0
tripal_feature/api/tripal_feature.api.inc

@@ -467,4 +467,50 @@ function tripal_get_fasta_sequence($feature, $desc) {
 
   return $fasta;
 
+}
+
+/**
+ * Returns a definition line that can be used in a FASTA file
+ * 
+ * @param $feature
+ *   A single feature object containing all the fields from the chado.feature table
+ * @param $alignment
+ *   Optional: A single featureloc object generated using chado_generate_var that
+ *   contains a record from the chado.featureloc table.
+ *   
+ * @return
+ *   A string of the format: uniquename|name|type|feature_id
+ *   or if an alignment:  srcfeature_name:fmin..fmax[+-]; alignment of uniquename|name|type|feature_id 
+ */
+function tripal_get_fasta_defline($feature, $featureloc = NULL) {
+   $defline = $feature->uniquename . "|" . $feature->name . "|" . $feature->type_id->name . "|" . $feature->feature_id; 
+   if ($featureloc) {
+     $defline = tripal_get_location_string($featureloc) . "; alignment of " . $defline;
+   }
+   
+   return $defline;
+}
+
+/**
+ * Returns a string representing a feature location in an alignment
+ *  
+ * @param unknown $featureloc
+ *   A single featureloc object generated using chado_generate_var that
+ *   contains a record from the chado.featureloc table.
+ */
+function tripal_get_location_string($featureloc) {
+  $feature = $featureloc->feature_id;
+  
+  if ($featureloc->strand < 0) {
+    $residues = tripal_feature_reverse_complement($residues);
+  }
+  $strand = '.';
+  if ($featureloc->strand == 1) {
+    $strand = '+';
+  }
+  elseif ($featureloc->strand == -1) {
+    $strand = '-';
+  }
+  
+  return $featureloc->srcfeature_id->name . ":" . ($featureloc->fmin + 1) . ".." . $featureloc->fmax .  $strand;  
 }

+ 4 - 4
tripal_feature/includes/tripal_feature.chado_node.inc

@@ -233,7 +233,7 @@ function chado_feature_form($node, &$form_state) {
   
   // TODO: For some reason adding a relationship to the form breaks AJAX
   // for features (works for other node type)... need to debug
-  /*
+  
   // RELATIONSHIPS FORM
   //---------------------------------------------
   $relationship_cv = tripal_get_default_cv('feature_relationship', 'type_id');
@@ -247,7 +247,7 @@ function chado_feature_form($node, &$form_state) {
     'cv_id' => $cv_id
   );
   chado_add_node_form_relationships($form, $form_state, $details);
-  */
+  
 
   return $form;
 }
@@ -951,8 +951,8 @@ function tripal_feature_node_view($node, $view_mode, $langcode) {
         );
         $node->content['tripal_feature_seqence'] = array(
           '#markup' => theme('tripal_feature_sequence', array('node' => $node)),
-          '#tripal_toc_id'    => 'sequence',
-          '#tripal_toc_title' => 'Sequence',
+          '#tripal_toc_id'    => 'sequences',
+          '#tripal_toc_title' => 'Sequences',
         );
         $node->content['tripal_feature_synonyms'] = array(
           '#markup' => theme('tripal_feature_synonyms', array('node' => $node)),

+ 8 - 7
tripal_feature/theme/css/tripal_feature.css

@@ -1,17 +1,18 @@
-#tripal_feature-featureloc_sequence,
-#tripal_feature-sequence-residues {
+.tripal_feature-sequence {
   background-color: #FFFFFF;
   font-family: monospace;
   margin: 10px 0 0 0;
   padding: 0px;
   font-size: medium;
 }
-
-pre#tripal_feature-featureloc_sequence {
+.tripal_feature-sequence-item {
+  margin-top: 20px;
+}
+pre.tripal_feature-sequence {
   color: #000000;
-  /*
-  height: 400px;
-  overflow: scroll; */
+  height: 300px;
+  overflow: scroll; 
+  border: 1px solid #DDDDDD;
 }
 
 div#tripal_feature-featureloc_sequence-legend {

+ 12 - 8
tripal_feature/theme/js/tripal_feature.js

@@ -1,15 +1,19 @@
-if (Drupal.jsEnabled) {
-  $(document).ready(function() {
-    $('.tripal_feature-legend-item').bind("mouseover", function(){
+(function($) {
+  Drupal.behaviors.tripal_featureBehavior = {
+    attach: function (context, settings){
 
+      // the following function is used when viewing sequence alignments
+      // on the feature page. When mousing over the feature type legend
+      // it should highlight regions in the sequence
+      $('.tripal_feature-legend-item').bind("mouseover", function(){
         var classes = $(this).attr('class').split(" ");
         var type_class = classes[1];       
-  
-        $("." + type_class).css("border", "1px solid red");
 
+        $("." + type_class).css("border", "1px solid red");
         $(this).bind("mouseout", function(){
           $("." + type_class).css("border", "0px");
         })    
-    });
-  });
-}
+      });
+    }
+  };
+})(jQuery);

+ 84 - 12
tripal_feature/theme/templates/tripal_feature_sequence.tpl.php

@@ -38,21 +38,93 @@ if(strcmp($feature->type_id->name,'scaffold') !=0 and
 $feature = $variables['node']->feature;
 $featureloc_sequences = $feature->featureloc_sequences;
 
-if ($residues or count($featureloc_sequences) > 0) { ?>
-  <div class="tripal_feature-data-block-desc tripal-data-block-desc"></div> <?php
+if ($residues or count($featureloc_sequences) > 0) { 
+
+  $sequences_html = '';  // a variable for holding all sequences HTML text
+  $list_items = array(); // a list to be used for theming of content on this page ?>
+  
+  <div class="tripal_feature-data-block-desc tripal-data-block-desc">The following sequences are available for this feature:</div> <?php
+  
+  // ADD IN RESIDUES FOR THIS FEATURE
+  // add in the residues if they are present
+  if ($residues) {
+    $list_items[] = '<a href="#residues">Current ' . $feature->type_id->name . ' sequence</a>';
+     
+    // format the sequence to break every 50 residues
+    $sequences_html .= '<a name="residues"></a>';
+    $sequences_html .= '<div class="tripal_feature-sequence-item">';
+    $sequences_html .= '<p><b>Current ' . $feature->type_id->name . ' sequence</b></p>';
+    $sequences_html .= '<pre class="tripal_feature-sequence">';
+    $sequences_html .= '>' . tripal_get_fasta_defline($feature) . "\n";
+    $sequences_html .= preg_replace("/(.{50})/","\\1<br>",$feature->residues);
+    $sequences_html .= '</pre>';
+    $sequences_html .= '<a href="#sequences-top">back to top</a>';
+    $sequences_html .= '</div>';
+    
+  }
   
+  // ADD IN RELATIONSHIP SEQUENCES (e.g. proteins)
+  // see the explanation in the tripal_feature_relationships.tpl.php 
+  // template for how the 'all_relationships' is provided. It is this
+  // variable that we use to get the proteins.
+  $all_relationships = $feature->all_relationships;
+  $object_rels = $all_relationships['object'];
+  foreach ($object_rels as $rel_type => $rels){
+    foreach ($rels as $subject_type => $subjects){
+      foreach ($subjects as $subject){
+        if ($rel_type == 'derives from' and $subject_type == 'polypeptide') {
+          $protein = $subject->record->subject_id;
+          $protein = chado_expand_var($protein, 'field', 'feature.residues');
+          
+          $list_items[] = '<a href="#residues">Protein sequence of ' . $protein->name . '</a>';
+          $sequences_html .= '<a name="protein-' . $protein->feature_id . '"></a>';
+          $sequences_html .= '<div class="tripal_feature-sequence-item">';
+          $sequences_html .= '<p><b>Protein sequence of ' . $protein->name . '</b></p>';
+          $sequences_html .= '<pre class="tripal_feature-sequence">';
+          $sequences_html .= '>' . tripal_get_fasta_defline($protein) . "\n";
+          $sequences_html .= preg_replace("/(.{50})/","\\1<br>", $protein->residues);
+          $sequences_html .= '</pre>';
+          $sequences_html .= '<a href="#sequences-top">back to top</a>';
+          $sequences_html .= '</div>';
+        }
+        // add any other sequences by by relationship in a similar way
+      }
+    }
+  }
+  
+  // ADD IN ALIGNMENT SEQUENCES FOR THIS FEATURE
   // show the alignment sequences first as they are colored with child features
   if(count($featureloc_sequences) > 0){
-    foreach($featureloc_sequences as $src => $attrs){ 
-      print $attrs['formatted_seq'];
-    } 
+    foreach($featureloc_sequences as $src => $attrs){
+      // the $attrs array has the following keys
+      //   * src:  a unique identifier combining the feature id with the cvterm id
+      //   * type: the type of sequence (e.g. mRNA, etc)
+      //   * location:  the alignment location
+      //   * defline: the definition line
+      //   * formatted_seq: the formatted sequences
+      $list_items[] = '<a href="#' . $attrs['src'] . '">Alignment at  ' . $attrs['location'];
+      $sequences_html .= '<a name="' . $attrs['src'] . '"></a>';
+      $sequences_html .= '<div class="tripal_feature-sequence-item">';
+      $sequences_html .= '<p><b>Alignment at  ' . $attrs['location'] .'</b></p>';
+      $sequences_html .= $attrs['formatted_seq'];
+      $sequences_html .= '<a href="#sequences-top">back to top</a>';
+      $sequences_html .= '</div>';
+    }
   }
   
-  // add in the residues if they are present
-  if ($residues) { ?>
-    <pre id="tripal_feature-sequence-residues"><?php 
-      // format the sequence to break every 100 residues
-      print preg_replace("/(.{50})/","\\1<br>",$feature->residues); ?>  
-    </pre> <?php 
-  } 
+  // first add a list at the top of the page that can be formatted as the
+  // user desires.  We use the theme_item_list function of Drupal to create 
+  // the list rather than hard-code the HTML here.  Instructions for how
+  // to create the list can be found here:
+  // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_item_list/7
+  print '<a name="sequences-top"></a>';
+  print theme_item_list(array(
+    'items' => $list_items,
+    'title' => '',
+    'type' => 'ul',
+    'attributes' => array(),
+  ));
+  
+  // now print the sequences
+  print $sequences_html;
 }

+ 7 - 0
tripal_feature/theme/tripal_feature.theme.inc

@@ -27,6 +27,13 @@ function tripal_feature_preprocess_tripal_feature_sequence(&$variables) {
   // now extract the sequences
   $featureloc_sequences = tripal_feature_load_featureloc_sequences($feature->feature_id, $ffeaturelocs);
   $feature->featureloc_sequences = $featureloc_sequences;
+  
+  // if this feature has associated protein sequences (or others via relationships
+  // then we want to make sure the relationships are added so that we can 
+  // show the protein sequences
+  if (!$feature->all_relationships) {
+    $feature->all_relationships = tripal_feature_get_feature_relationships($feature);
+  }
 }
 /**
  *

+ 4 - 3
tripal_feature/tripal_feature.module

@@ -634,8 +634,9 @@ function tripal_feature_load_featureloc_sequences($feature_id, $featurelocs) {
       elseif ($featureloc->strand == -1) {
         $strand = '-';
       }
-      $defline = $featureloc->feature_id->name . " " . $featureloc->srcfeature_id->name . ":" . ($featureloc->fmin + 1) . ".." . $featureloc->fmax . " " . $strand;
-      $floc_sequences[$src]['formatted_seq'] =  tripal_feature_color_sequence($residues, $parts, $defline);
+      $floc_sequences[$src]['location'] = tripal_get_location_string($featureloc);
+      $floc_sequences[$src]['defline'] = tripal_get_fasta_defline($featureloc->feature_id, $featureloc);
+      $floc_sequences[$src]['formatted_seq'] =  tripal_feature_color_sequence($residues, $parts, $floc_sequences[$src]['defline']);
     }
   }
   return $floc_sequences;
@@ -855,7 +856,7 @@ function tripal_feature_color_sequence($sequence, $parts, $defline) {
 
   // set the background color of the rows based on the type
   $pos = 0;
-  $newseq .= "<pre id=\"tripal_feature-featureloc_sequence\">";
+  $newseq .= "<pre class=\"tripal_feature-sequence\">";
   $newseq .= ">$defline\n";
 
   // iterate through the parts. They should be in order.