tripal_feature_sequence.tpl.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /*
  3. * There are two ways that sequences can be displayed. They can come from the
  4. * feature.residues column or they can come from an alignment with another feature.
  5. * This template will show both or one or the other depending on the data available.
  6. *
  7. * For retreiving the sequence from an alignment we would typically make a call to
  8. * chado_expand_var function. For example, to retrieve all
  9. * of the featurelocs in order to get the sequences needed for this template, the
  10. * following function call would be made:
  11. *
  12. * $feature = chado_expand_var($feature,'table','featureloc');
  13. *
  14. * Then all of the sequences would need to be retreived from the alignments and
  15. * formatted for display below. However, to simplify this template, this has already
  16. * been done by the tripal_feature module and the sequences are made available in
  17. * the variable:
  18. *
  19. * $feature->featureloc_sequences
  20. *
  21. */
  22. $feature = $variables['node']->feature;
  23. // we don't want to get the sequence for traditionally large types. They are
  24. // too big, bog down the web browser, take longer to load and it's not
  25. // reasonable to print them on a page.
  26. $residues ='';
  27. if(strcmp($feature->type_id->name,'scaffold') !=0 and
  28. strcmp($feature->type_id->name,'chromosome') !=0 and
  29. strcmp($feature->type_id->name,'supercontig') !=0 and
  30. strcmp($feature->type_id->name,'pseudomolecule') !=0) {
  31. $feature = chado_expand_var($feature,'field','feature.residues');
  32. $residues = $feature->residues;
  33. }
  34. // get the sequence derived from alignments
  35. $feature = $variables['node']->feature;
  36. $featureloc_sequences = $feature->featureloc_sequences;
  37. if ($residues or count($featureloc_sequences) > 0) {
  38. $sequences_html = ''; // a variable for holding all sequences HTML text
  39. $list_items = array(); // a list to be used for theming of content on this page ?>
  40. <div class="tripal_feature-data-block-desc tripal-data-block-desc">The following sequences are available for this feature:</div> <?php
  41. // ADD IN RESIDUES FOR THIS FEATURE
  42. // add in the residues if they are present
  43. if ($residues) {
  44. $list_items[] = '<a href="#residues">Current ' . $feature->type_id->name . ' sequence</a>';
  45. // format the sequence to break every 50 residues
  46. $sequences_html .= '<a name="residues"></a>';
  47. $sequences_html .= '<div class="tripal_feature-sequence-item">';
  48. $sequences_html .= '<p><b>Current ' . $feature->type_id->name . ' sequence</b></p>';
  49. $sequences_html .= '<pre class="tripal_feature-sequence">';
  50. $sequences_html .= '>' . tripal_get_fasta_defline($feature) . "\n";
  51. $sequences_html .= preg_replace("/(.{50})/","\\1<br>",$feature->residues);
  52. $sequences_html .= '</pre>';
  53. $sequences_html .= '<a href="#sequences-top">back to top</a>';
  54. $sequences_html .= '</div>';
  55. }
  56. // ADD IN RELATIONSHIP SEQUENCES (e.g. proteins)
  57. // see the explanation in the tripal_feature_relationships.tpl.php
  58. // template for how the 'all_relationships' is provided. It is this
  59. // variable that we use to get the proteins.
  60. $all_relationships = $feature->all_relationships;
  61. $object_rels = $all_relationships['object'];
  62. foreach ($object_rels as $rel_type => $rels){
  63. foreach ($rels as $subject_type => $subjects){
  64. foreach ($subjects as $subject){
  65. if ($rel_type == 'derives from' and $subject_type == 'polypeptide') {
  66. $protein = $subject->record->subject_id;
  67. $protein = chado_expand_var($protein, 'field', 'feature.residues');
  68. $list_items[] = '<a href="#residues">Protein sequence of ' . $protein->name . '</a>';
  69. $sequences_html .= '<a name="protein-' . $protein->feature_id . '"></a>';
  70. $sequences_html .= '<div class="tripal_feature-sequence-item">';
  71. $sequences_html .= '<p><b>Protein sequence of ' . $protein->name . '</b></p>';
  72. $sequences_html .= '<pre class="tripal_feature-sequence">';
  73. $sequences_html .= '>' . tripal_get_fasta_defline($protein) . "\n";
  74. $sequences_html .= preg_replace("/(.{50})/","\\1<br>", $protein->residues);
  75. $sequences_html .= '</pre>';
  76. $sequences_html .= '<a href="#sequences-top">back to top</a>';
  77. $sequences_html .= '</div>';
  78. }
  79. // add any other sequences by by relationship in a similar way
  80. }
  81. }
  82. }
  83. // ADD IN ALIGNMENT SEQUENCES FOR THIS FEATURE
  84. // show the alignment sequences first as they are colored with child features
  85. if(count($featureloc_sequences) > 0){
  86. foreach($featureloc_sequences as $src => $attrs){
  87. // the $attrs array has the following keys
  88. // * src: a unique identifier combining the feature id with the cvterm id
  89. // * type: the type of sequence (e.g. mRNA, etc)
  90. // * location: the alignment location
  91. // * defline: the definition line
  92. // * formatted_seq: the formatted sequences
  93. $list_items[] = '<a href="#' . $attrs['src'] . '">Alignment at ' . $attrs['location'];
  94. $sequences_html .= '<a name="' . $attrs['src'] . '"></a>';
  95. $sequences_html .= '<div class="tripal_feature-sequence-item">';
  96. $sequences_html .= '<p><b>Alignment at ' . $attrs['location'] .'</b></p>';
  97. $sequences_html .= $attrs['formatted_seq'];
  98. $sequences_html .= '<a href="#sequences-top">back to top</a>';
  99. $sequences_html .= '</div>';
  100. }
  101. }
  102. // first add a list at the top of the page that can be formatted as the
  103. // user desires. We use the theme_item_list function of Drupal to create
  104. // the list rather than hard-code the HTML here. Instructions for how
  105. // to create the list can be found here:
  106. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_item_list/7
  107. print '<a name="sequences-top"></a>';
  108. print theme_item_list(array(
  109. 'items' => $list_items,
  110. 'title' => '',
  111. 'type' => 'ul',
  112. 'attributes' => array(),
  113. ));
  114. // now print the sequences
  115. print $sequences_html;
  116. }