tripal_feature_alignments.tpl.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 relationsips,
  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 following features are aligned</div><?php
  61. // the $headers array is an array of fields to use as the colum headers.
  62. // additional documentation can be found here
  63. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  64. $headers = array('Aligned Feature' ,'Feature Type', 'Alignment Location');
  65. // the $rows array contains an array of rows where each row is an array
  66. // of values for each column of the table in that row. Additional documentation
  67. // can be found here:
  68. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  69. $rows = array();
  70. foreach ($alignments as $alignment){
  71. $feature_name = $alignment->name;
  72. if (property_exists($alignment, 'nid')) {
  73. $feature_name = l($feature_name, "node/" . $alignment->nid);
  74. }
  75. $feature_loc = '';
  76. $strand = '.';
  77. if ($alignment->strand == -1) {
  78. $strand = '-';
  79. }
  80. elseif ($alignment->strand == 1) {
  81. $strand = '+';
  82. }
  83. // if this is a match then make the other location
  84. if(property_exists($alignment, 'right_feature')){
  85. $rstrand = '.';
  86. if ($alignment->right_strand == -1) {
  87. $rstrand = '-';
  88. }
  89. elseif ($alignment->right_strand == 1) {
  90. $rstrand = '+';
  91. }
  92. $feature_loc = $feature->name .":". ($alignment->fmin + 1) . ".." . $alignment->fmax . " " . $strand;
  93. $feature_loc .= "<br>" . $alignment->name .":". ($alignment->right_fmin + 1) . ".." . $alignment->right_fmax . " " . $rstrand;
  94. }
  95. else {
  96. $feature_loc = $alignment->name .":". ($alignment->fmin + 1) . ".." . $alignment->fmax . " " . $strand;
  97. }
  98. $rows[] = array(
  99. $feature_name,
  100. $alignment->type,
  101. $feature_loc
  102. );
  103. }
  104. // the $table array contains the headers and rows array as well as other
  105. // options for controlling the display of the table. Additional
  106. // documentation can be found here:
  107. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  108. $table = array(
  109. 'header' => $headers,
  110. 'rows' => $rows,
  111. 'attributes' => array(
  112. 'id' => 'tripal_feature-table-alignments',
  113. 'class' => 'tripal-data-table'
  114. ),
  115. 'sticky' => FALSE,
  116. 'caption' => '',
  117. 'colgroups' => array(),
  118. 'empty' => '',
  119. );
  120. // once we have our table array structure defined, we call Drupal's theme_table()
  121. // function to generate the table.
  122. print theme_table($table);
  123. }