PageRenderTime 42ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/sites/all/modules/tripal_analysis_interpro/theme/templates/tripal_feature_interpro_results.tpl.php

https://gitlab.com/vijaya.tsavatapalli/drupal7
PHP | 235 lines | 139 code | 19 blank | 77 comment | 25 complexity | e68f565551fee59ccdb2aebabcf1dfac MD5 | raw file
  1. <?php
  2. $feature = $variables['node']->feature;
  3. /* The results from an InterProScan analysis for this feature are avaialble to
  4. * this template in a array of the following format:
  5. *
  6. * $results[$analysis_id]['iprterms']
  7. * $results[$analysis_id]['goterms']
  8. * $results[$analysis_id]['analysis']
  9. * $results[$analysis_id]['format']
  10. *
  11. * Because there may be multiple InterProScan analyses for this feature, they
  12. * are separated in the array by the $analysis_id key. The deeper array
  13. * structure is as follows
  14. *
  15. * An arrray containing all of the IPR terms mapped to this feature. Each
  16. * IPR term is an array with 3 elements. The first element is the IPR
  17. * accession, the second is the name and the third is the description
  18. * $results[$analysis_id]['iprterms']
  19. *
  20. * A string indicating the XML format from which the original results
  21. * were obtained. Valid values are XML4 or XML5
  22. * $results[$analysis_id]['format']
  23. *
  24. * An array of terms, where GO:XXXXXXXX idicates a GO accession that
  25. * is used as a key for the array. All GO terms for all matches are stored here.
  26. * $results[$analysis_id]['goterms']['GO:XXXXXXX']['category']
  27. * $results[$analysis_id]['goterms']['GO:XXXXXXX']['name']
  28. *
  29. * An array of terms. The variable IPRXXXXXX indicates an IPR accession
  30. * that is used as a key for the array.
  31. * $results[$analysis_id]['iprterms']
  32. * $results[$analysis_id]['iprterms']['IPRXXXXXX']['ipr_name']
  33. * $results[$analysis_id]['iprterms']['IPRXXXXXX']['ipr_desc']
  34. * $results[$analysis_id]['iprterms']['IPRXXXXXX']['ipr_type']
  35. *
  36. *
  37. * Each term may have one or more matches. The variable $j indicates
  38. * an index variable for iterating through the matches.
  39. * $results[$analysis_id]['iprterms']['IPRXXXXXX']['matches'][$j]['match_id']
  40. * $results[$analysis_id]['iprterms']['IPRXXXXXX']['matches'][$j]['match_name']
  41. * $results[$analysis_id]['iprterms']['IPRXXXXXX']['matches'][$j]['match_desc']
  42. * $results[$analysis_id]['iprterms']['IPRXXXXXX']['matches'][$j]['match_dbname']
  43. * $results[$analysis_id]['iprterms']['IPRXXXXXX']['matches'][$j]['evalue']
  44. * $results[$analysis_id]['iprterms']['IPRXXXXXX']['matches'][$j]['score']
  45. *
  46. * An array of terms, where GO:XXXXXXXX idicates a GO accession that
  47. * is used as a key for the array. GO terms are stored a second time
  48. * here to associate them with the proper IPR.
  49. * $results[$analysis_id]['iprterms']['IPRXXXXXX']['goterms']['GO:XXXXXXX']['category']
  50. * $results[$analysis_id]['iprterms']['IPRXXXXXX']['goterms']['GO:XXXXXXX']['name']
  51. *
  52. * Each match can have multiple start and stop locations. The variable $k
  53. * indicates an index variable for iterating through the locations
  54. * $results[$analysis_id]['iprterms']['IPRXXXXXX']['matches'][$j]['locations'][$k]['match_start']
  55. * $results[$analysis_id]['iprterms']['IPRXXXXXX']['matches'][$j]['locations'][$k]['match_end']
  56. * $results[$analysis_id]['iprterms']['IPRXXXXXX']['matches'][$j]['locations'][$k]['match_score']
  57. * $results[$analysis_id]['iprterms']['IPRXXXXXX']['matches'][$j]['locations'][$k]['match_status']
  58. * $results[$analysis_id]['iprterms']['IPRXXXXXX']['matches'][$j]['locations'][$k]['match_evalue']
  59. * $results[$analysis_id]['iprterms']['IPRXXXXXX']['matches'][$j]['locations'][$k]['match_level']
  60. * $results[$analysis_id]['iprterms']['IPRXXXXXX']['matches'][$j]['locations'][$k]['match_evidence']
  61. */
  62. if (property_exists($feature, 'tripal_analysis_interpro')) {
  63. if (property_exists($feature->tripal_analysis_interpro->results, 'xml')) {
  64. // iterate through the results. They are organized by analysis id
  65. $results = $feature->tripal_analysis_interpro->results->xml;
  66. if(count($results) > 0){
  67. foreach($results as $analysis_id => $details){
  68. $analysis = $details['analysis'];
  69. $iprterms = $details['iprterms'];
  70. $format = $details['format'];
  71. // ANALYSIS DETAILS
  72. $aname = $analysis->name;
  73. if (property_exists($analysis, 'nid')) {
  74. $aname = l($aname, 'node/' . $analysis->nid, array('attributes' => array('target' => '_blank')));
  75. }
  76. $date_performed = preg_replace("/^(\d+-\d+-\d+) .*/", "$1", $analysis->timeexecuted);
  77. print "
  78. Analysis Name: $aname
  79. <br>Date Performed: $date_performed
  80. ";
  81. // ALIGNMENT SUMMARY
  82. $headers = array(
  83. 'IPR Term',
  84. 'IPR Description',
  85. 'Source',
  86. 'Source Term',
  87. 'Source Description',
  88. 'Alignment'
  89. );
  90. $rows = array();
  91. foreach ($iprterms as $ipr_id => $iprterm) {
  92. $matches = $iprterm['matches'];
  93. $ipr_name = $iprterm['ipr_name'];
  94. $ipr_desc = $iprterm['ipr_desc'];
  95. $ipr_type = $iprterm['ipr_type'];
  96. // iterate through the evidence matches
  97. foreach ($matches as $match) {
  98. $match_id = $match['match_id'];
  99. $match_name = $match['match_name'];
  100. $match_dbname = $match['match_dbname'];
  101. $locations = $match['locations'];
  102. $loc_details = '';
  103. foreach($locations as $location){
  104. if ($format == 'XML4') {
  105. $loc_details .= 'coord: ' . $location['match_start'] . ".." . $location['match_end'];
  106. if($location['match_score']) {
  107. $loc_details .= '<br>score: ' . $location['match_score'];
  108. }
  109. }
  110. if ($format == 'XML5') {
  111. $loc_details .= 'coord: ' . $location['match_start'] . ".." . $location['match_end'];
  112. if($location['match_evalue']) {
  113. $loc_details .= '<br>e-value: ' . $location['match_evalue'];
  114. }
  115. if($location['match_score']) {
  116. $loc_details .= '<br>score: ' . $location['match_score'];
  117. }
  118. $loc_details .= '<br>';
  119. }
  120. //$match_evidence = $location['match_evidence'];
  121. }
  122. // remove the trailing <br>
  123. $loc_details = substr($loc_details, 0, -4);
  124. if ($ipr_id == 'noIPR') {
  125. $ipr_id_link = 'None';
  126. $ipr_desc = 'No IPR available';
  127. }
  128. else {
  129. // we want to use the URL for the database
  130. $ipr_db = tripal_db_get_db(array('name' => 'INTERPRO'));
  131. $ipr_id_link = $ipr_id;
  132. if ($ipr_db and $ipr_db->urlprefix) {
  133. $ipr_id_link = l($ipr_id, $ipr_db->urlprefix . $ipr_id, array('attributes' => array('target' => '_blank')));
  134. }
  135. }
  136. // the Prosite databases are split into two libraries for InterProScan. But
  137. // we can just use the PROSITE database for both of them, so rename it here.
  138. $match_dbname = preg_replace('/(PROSITE)_.*/', '\1', $match_dbname);
  139. // get links for the matching databases
  140. $match_db = tripal_db_get_db(array('name' => strtoupper($match_dbname)));
  141. if ($match_db and $match_db->url) {
  142. // some databases need a prefix removed
  143. if ($match_dbname == "GENE3D") {
  144. $fixed_id = preg_replace('/G3DSA:/','', $match_id);
  145. $match_id = l($fixed_id, $match_db->urlprefix . $fixed_id, array('attributes' => array('target' => '_blank')));
  146. }
  147. elseif ($match_dbname == "SUPERFAMILY") {
  148. $fixed_id = preg_replace('/SSF/','', $match_id);
  149. $match_id = l($fixed_id, $match_db->urlprefix . $fixed_id, array('attributes' => array('target' => '_blank')));
  150. }
  151. // for all others, just link using the URL prefix
  152. else {
  153. $match_id = l($match_id, $match_db->urlprefix . $match_id, array('attributes' => array('target' => '_blank')));
  154. }
  155. }
  156. if ($match_db and $match_db->url) {
  157. $match_dbname = l($match_dbname, $match_db->url, array('attributes' => array('target' => '_blank')));
  158. }
  159. $rows[] = array(
  160. $ipr_id_link,
  161. $ipr_desc,
  162. $match_dbname,
  163. $match_id,
  164. $match_name,
  165. array(
  166. 'data' => $loc_details,
  167. 'nowrap' => 'nowrap'
  168. ),
  169. );
  170. } // end foreach ($matches as $match) {
  171. } // end foreach ($iprterms as $ipr_id => $iprterm) {
  172. if (count($rows) == 0) {
  173. $rows[] = array(
  174. array(
  175. 'data' => 'No results',
  176. 'colspan' => '6',
  177. ),
  178. );
  179. }
  180. $table = array(
  181. 'header' => $headers,
  182. 'rows' => $rows,
  183. 'attributes' => array(),
  184. 'sticky' => FALSE,
  185. 'caption' => '',
  186. 'colgroups' => array(),
  187. 'empty' => '',
  188. );
  189. // once we have our table array structure defined, we call Drupal's theme_table()
  190. // function to generate the table.
  191. print theme_table($table);
  192. print "<br>";
  193. }
  194. }
  195. }
  196. // for backwards compatibility we want to ensure that if any results are stored
  197. // as HTML that they can still be displayed. Although Tripal InterPro Analysis
  198. // v2.0 no longer supports importing of HTML results.
  199. if(property_exists($feature->tripal_analysis_interpro->results, 'html') and
  200. $feature->tripal_analysis_interpro->results->html) {
  201. $resultsHTML = $feature->tripal_analysis_interpro->results->html;
  202. // ANALYSIS DETAILS
  203. $aname = $analysis_name;
  204. if (property_exists($analysis, 'nid')) {
  205. $aname = l($aname, 'node/' . $analysis->nid, array('attributes' => array('target' => '_blank')));
  206. }
  207. $date_performed = preg_replace("/^(\d+-\d+-\d+) .*/", "$1", $analysis->timeexecuted);
  208. print "
  209. Analysis Name: $analysis_name
  210. <br>Date Performed: $date_performed
  211. "; ?>
  212. <div class="tripal_feature-interpro_results_subtitle">Summary of Annotated IPR terms</div> <?php
  213. print $resultsHTML;?>
  214. </div> <?php
  215. }
  216. }