tripal_feature.theme.inc 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. /**
  3. * @ingroup tripal_feature
  4. */
  5. function tripal_feature_preprocess_tripal_feature_sequence(&$variables) {
  6. // we want to provide a new variable that contains the matched features.
  7. $feature = $variables['node']->feature;
  8. // get the featureloc src features
  9. $options = array(
  10. 'return_array' => 1,
  11. 'include_fk' => array(
  12. 'srcfeature_id' => array(
  13. 'type_id' => 1
  14. ),
  15. ),
  16. );
  17. $feature = tripal_core_expand_chado_vars($feature, 'table', 'featureloc', $options);
  18. // because there are two foriegn keys in the featureloc table with the feature table
  19. // we have to access the records for each by specifying the field name after the table name:
  20. $ffeaturelocs = $feature->featureloc->feature_id;
  21. // now extract the sequences
  22. $featureloc_sequences = tripal_feature_load_featureloc_sequences($feature->feature_id, $ffeaturelocs);
  23. $feature->featureloc_sequences = $featureloc_sequences;
  24. }
  25. /**
  26. *
  27. *
  28. * @ingroup tripal_feature
  29. */
  30. function tripal_feature_preprocess_tripal_feature_relationships(&$variables) {
  31. // we want to provide a new variable that contains the matched features.
  32. $feature = $variables['node']->feature;
  33. if (!property_exists($feature, 'all_relationships')) {
  34. $feature->all_relationships = tripal_feature_get_feature_relationships($feature);
  35. }
  36. }
  37. /**
  38. *
  39. *
  40. * @ingroup tripal_feature
  41. */
  42. function tripal_feature_preprocess_tripal_feature_proteins(&$variables) {
  43. // we want to provide a new variable that contains the matched features.
  44. $feature = $variables['node']->feature;
  45. if (!property_exists($feature, 'all_relationships')) {
  46. $feature->all_relationships = tripal_feature_get_feature_relationships($feature);
  47. }
  48. }
  49. /**
  50. *
  51. *
  52. * @ingroup tripal_feature
  53. */
  54. function tripal_feature_preprocess_tripal_feature_alignments(&$variables) {
  55. // we want to provide a new variable that contains the matched features.
  56. $feature = $variables['node']->feature;
  57. $options = array(
  58. 'return_array' => 1,
  59. 'include_fk' => array(
  60. 'srcfeature_id' => array(
  61. 'type_id' => 1,
  62. ),
  63. 'feature_id' => array(
  64. 'type_id' => 1
  65. ),
  66. )
  67. );
  68. $feature = tripal_core_expand_chado_vars($feature, 'table', 'featureloc', $options);
  69. // get alignments as child
  70. $cfeaturelocs = $feature->featureloc->feature_id;
  71. if (!$cfeaturelocs) {
  72. $cfeaturelocs = array();
  73. }
  74. // get alignment as parent
  75. $pfeaturelocs = $feature->featureloc->srcfeature_id;
  76. if (!$pfeaturelocs) {
  77. $pfeaturelocs = array();
  78. }
  79. // get matched alignments (those with an itermediate 'match' or 'EST_match', etc
  80. $mfeaturelocs = tripal_feature_get_matched_alignments($feature);
  81. $feature->matched_featurelocs = $mfeaturelocs;
  82. // combine all three alignments into a single array for printing together in
  83. // a single list
  84. $alignments = array();
  85. foreach ($pfeaturelocs as $featureloc) {
  86. // if type is a 'match' then ignore it. We will handle those below
  87. if (preg_match('/(^match$|^.*?_match|match_part)$/', $featureloc->feature_id->type_id->name)) {
  88. continue;
  89. }
  90. $alignment = new stdClass();
  91. $alignment->record = $featureloc;
  92. $alignment->name = $featureloc->feature_id->name;
  93. $alignment->type = $featureloc->feature_id->type_id->name;
  94. $alignment->fmin = $featureloc->fmin;
  95. $alignment->fmax = $featureloc->fmax;
  96. $alignment->phase = $featureloc->phase;
  97. $alignment->strand = $featureloc->strand;
  98. $alignments[] = $alignment;
  99. if (property_exists($featureloc->feature_id, 'nid')) {
  100. $alignment->nid = $featureloc->feature_id->nid;
  101. }
  102. }
  103. foreach ($cfeaturelocs as $featureloc) {
  104. // if type is a 'match' then ignore it. We will handle those below
  105. if (preg_match('/(^match$|^.*?_match|match_part)$/', $featureloc->feature_id->type_id->name)) {
  106. continue;
  107. }
  108. $alignment = new stdClass();
  109. $alignment->record = $featureloc;
  110. $alignment->name = $featureloc->srcfeature_id->name;
  111. $alignment->type = $featureloc->srcfeature_id->type_id->name;
  112. $alignment->fmin = $featureloc->fmin;
  113. $alignment->is_fmin_partial = $featureloc->is_fmin_partial;
  114. $alignment->fmax = $featureloc->fmax;
  115. $alignment->is_fmax_partial = $featureloc->is_fmax_partial;
  116. $alignment->phase = $featureloc->phase;
  117. $alignment->strand = $featureloc->strand;
  118. $alignments[] = $alignment;
  119. if (property_exists($featureloc->srcfeature_id, 'nid')) {
  120. $alignment->nid = $featureloc->srcfeature_id->nid;
  121. }
  122. }
  123. // in matching features, the left feature is always the feature
  124. // provided to this function.
  125. foreach ($mfeaturelocs as $featureloc) {
  126. // get more information about the right feature
  127. $select = array('feature_id' => $featureloc->right_srcfeature_id);
  128. $rfeature = tripal_core_generate_chado_var('feature', $select);
  129. // now add to the list
  130. $alignment = new stdClass();
  131. $alignment->record = $featureloc;
  132. $alignment->right_feature = $rfeature;
  133. $alignment->name = $rfeature->name;
  134. $alignment->type = $rfeature->type_id->name;
  135. $alignment->fmin = $featureloc->left_fmin;
  136. $alignment->is_fmin_partial = $featureloc->left_is_fmin_partial;
  137. $alignment->fmax = $featureloc->left_fmax;
  138. $alignment->is_fmax_partial = $featureloc->left_is_fmax_partial;
  139. $alignment->phase = $featureloc->left_phase;
  140. $alignment->strand = $featureloc->left_strand;
  141. $alignment->right_fmin = $featureloc->right_fmin;
  142. $alignment->right_is_fmin_partial = $featureloc->right_is_fmin_partial;
  143. $alignment->right_fmax = $featureloc->right_fmax;
  144. $alignment->right_is_fmax_partial = $featureloc->right_is_fmax_partial;
  145. $alignment->right_phase = $featureloc->right_phase;
  146. $alignment->right_strand = $featureloc->right_strand;
  147. $alignments[] = $alignment;
  148. if (property_exists($rfeature, 'nid')) {
  149. $alignment->nid = $rfeature->nid;
  150. }
  151. }
  152. $feature->all_featurelocs = $alignments;
  153. }
  154. /**
  155. *
  156. *
  157. * @ingroup tripal_feature
  158. */
  159. function tripal_feature_preprocess_tripal_organism_feature_counts(&$variables, $hook) {
  160. $organism = $variables['node']->organism;
  161. $organism->feature_counts = tripal_feature_load_organism_feature_counts($organism);
  162. }