tripal_feature_alignments.tpl.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /*
  3. * Typically in a Tripal template, the data needed is retrieved using a call to
  4. * chado_expand_var function. For example, to retrieve all
  5. * of the feature alignments for this node, the following function call would be made:
  6. *
  7. * $feature = chado_expand_var($feature,'table','featureloc');
  8. *
  9. * However, this will return all records from the featureloc table without any context.
  10. * To help provide context, a special variable is provided to this template named
  11. * 'all_featurelocs'.
  12. *
  13. * $feature->all_featurelocs
  14. *
  15. * The records in the 'all_featurelocs' array are all properly arranged for easy iteration.
  16. *
  17. * However, access to the original alignment records is possible through the
  18. * $feature->featureloc object. In the following ways:
  19. *
  20. * Alignment context #1:
  21. * --------------------
  22. * If the feature for this node is the parent in the alignment relationships,
  23. * then those alignments are available in this variable:
  24. *
  25. * $feature->featureloc->srcfeature_id;
  26. *
  27. *
  28. * Alignment context #2:
  29. * ---------------------
  30. * If the feature for this node is the child in the alignment relationships,
  31. * then those alignments are available in this variable:
  32. *
  33. * $feature->featureloc->feature_id;
  34. *
  35. *
  36. * Alignment context #3:
  37. * --------------------
  38. * If the feature is aligned to another through an intermediary feature (e.g.
  39. * a feature of type 'match', 'EST_match', 'primer_match', etc) then those
  40. * alignments are stored in this variable:
  41. * feature->matched_featurelocs
  42. *
  43. * Below is an example of a feature that may be aligned to another through
  44. * an intermediary:
  45. *
  46. * Feature 1: Contig --------------- (left feature)
  47. * Feature 2: EST_match -------
  48. * Feature 3: EST --------- (right feature)
  49. *
  50. * The feature for this node is always "Feature 1". The purpose of this type
  51. * alignment is to indicate cases where there is the potential for overhang
  52. * in the alignments, or, the ends of the features are not part of the alignment
  53. * prehaps due to poor quality of the ends. Blast results and ESTs mapped to
  54. * contigs in Unigenes would fall under this category.
  55. *
  56. */
  57. $feature = $variables['node']->feature;
  58. $alignments = $feature->all_featurelocs;
  59. if (count($alignments) > 0) { ?>
  60. <div class="tripal_feature-data-block-desc tripal-data-block-desc">The
  61. following features are aligned
  62. </div><?php
  63. // the $headers array is an array of fields to use as the colum headers.
  64. // additional documentation can be found here
  65. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  66. $headers = ['Aligned Feature', 'Feature Type', 'Alignment Location'];
  67. // the $rows array contains an array of rows where each row is an array
  68. // of values for each column of the table in that row. Additional documentation
  69. // can be found here:
  70. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  71. $rows = [];
  72. foreach ($alignments as $alignment) {
  73. $feature_name = $alignment->name;
  74. if (property_exists($alignment, 'nid')) {
  75. $feature_name = l($feature_name, "node/" . $alignment->nid);
  76. }
  77. $feature_loc = '';
  78. $strand = '.';
  79. if ($alignment->strand == -1) {
  80. $strand = '-';
  81. }
  82. elseif ($alignment->strand == 1) {
  83. $strand = '+';
  84. }
  85. // if this is a match then make the other location
  86. if (property_exists($alignment, 'right_feature')) {
  87. $rstrand = '.';
  88. if ($alignment->right_strand == -1) {
  89. $rstrand = '-';
  90. }
  91. elseif ($alignment->right_strand == 1) {
  92. $rstrand = '+';
  93. }
  94. $feature_loc = $feature->name . ":" . ($alignment->fmin + 1) . ".." . $alignment->fmax . " " . $strand;
  95. $feature_loc .= "<br>" . $alignment->name . ":" . ($alignment->right_fmin + 1) . ".." . $alignment->right_fmax . " " . $rstrand;
  96. }
  97. else {
  98. $feature_loc = $alignment->name . ":" . ($alignment->fmin + 1) . ".." . $alignment->fmax . " " . $strand;
  99. }
  100. $rows[] = [
  101. $feature_name,
  102. $alignment->type,
  103. $feature_loc,
  104. ];
  105. }
  106. // the $table array contains the headers and rows array as well as other
  107. // options for controlling the display of the table. Additional
  108. // documentation can be found here:
  109. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  110. $table = [
  111. 'header' => $headers,
  112. 'rows' => $rows,
  113. 'attributes' => [
  114. 'id' => 'tripal_feature-table-alignments',
  115. 'class' => 'tripal-data-table',
  116. ],
  117. 'sticky' => FALSE,
  118. 'caption' => '',
  119. 'colgroups' => [],
  120. 'empty' => '',
  121. ];
  122. // once we have our table array structure defined, we call Drupal's theme_table()
  123. // function to generate the table.
  124. print theme_table($table);
  125. }