blast_ui.linkouts.inc 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. /**
  3. * @file
  4. * Provides Link-out functionality for BLAST hits.
  5. *
  6. * Specifically,
  7. */
  8. /**
  9. * Implements hook_blast_linkout_info().
  10. *
  11. * Provide information on basic link-out types: link, GBrowse, JBrowse.
  12. */
  13. function blast_ui_blast_linkout_info() {
  14. $types = array();
  15. $types['link'] = array(
  16. // Human-readable Type name to display to users in the BLAST Database
  17. // create/edit form.
  18. 'name' => 'Generic Link',
  19. // The function used to generate the URL to be linked to.
  20. // This function will have full access to the blast hit and database
  21. // prefix information and is expected to return a URL.
  22. 'process function' => 'tripal_blast_generate_linkout_link',
  23. );
  24. $types['gbrowse'] = array(
  25. 'name' => 'GBrowse',
  26. 'process function' => 'tripal_blast_generate_linkout_gbrowse',
  27. );
  28. $types['jbrowse'] = array(
  29. 'name' => 'JBrowse',
  30. 'process function' => 'tripal_blast_generate_linkout_jbrowse',
  31. );
  32. return $types;
  33. }
  34. /**
  35. * Generate a basic link-out for a given hit.
  36. *
  37. * Essentially, concatenate the URL prefix with the extracted hit identifier
  38. * and return the URL to be displayed by the BLAST report template.
  39. *
  40. * @param $url_prefix
  41. * The URL prefix for the BLAST Database queried.
  42. * @param $hit
  43. * The blast XML hit object. This object has the following keys based on the
  44. * XML: Hit_num, Hit_id, Hit_def, Hit_accession, Hit_len and Hit_hsps.
  45. * Furthermore, a linkout_id key has beek added that contains the part of the
  46. * Hit_def extracted using a regex provided when the blastdb node was created.
  47. * @param $info
  48. * Additional information that may be useful in creating a link-out. Includes:
  49. * - query_name: the name of the query sequence.
  50. * - score: the score of the blast hit.
  51. * - e-value: the e-value of the blast hit.
  52. * @param $options
  53. * Any additional options needed to determine the type of link-out. None are
  54. * supported by this particular link-out type.
  55. *
  56. * @return
  57. * The URL string to be linked to.
  58. */
  59. function tripal_blast_generate_linkout_link($url_prefix, $hit, $info, $options = array()) {
  60. if (isset($hit->{'linkout_id'})) {
  61. return $url_prefix . $hit->{'linkout_id'};
  62. }
  63. else {
  64. return FALSE;
  65. }
  66. }
  67. /**
  68. * Generate a GBrowse link-out with location information for a given hit.
  69. *
  70. * NOTE: Assumes the hit is a backbone feature in the GBrowse linked to.
  71. * Otherwise, the basic link can be used.
  72. *
  73. * @param $url_prefix
  74. * The URL prefix for the BLAST Database queried.
  75. * @param $hit
  76. * The blast XML hit object. This object has the following keys based on the
  77. * XML: Hit_num, Hit_id, Hit_def, Hit_accession, Hit_len and Hit_hsps.
  78. * Furthermore, a linkout_id key has beek added that contains the part of the
  79. * Hit_def extracted using a regex provided when the blastdb node was created.
  80. * @param $info
  81. * Additional information that may be useful in creating a link-out. Includes:
  82. * - query_name: the name of the query sequence.
  83. * - score: the score of the blast hit.
  84. * - e-value: the e-value of the blast hit.
  85. * @param $options
  86. * Any additional options needed to determine the type of link-out. None are
  87. * supported by this particular link-out type.
  88. *
  89. * @return
  90. * The URL string to be linked to.
  91. */
  92. function tripal_blast_generate_linkout_gbrowse($url_prefix, $hit, $info, $options = array()) {
  93. $ranges = array();
  94. $coords = array();
  95. foreach($info['HSPs'] as $hsp) {
  96. array_push($ranges,$hsp['Hsp_hit-from'] . '..' . $hsp['Hsp_hit-to'] );
  97. array_push($coords,$hsp['Hsp_hit-from'] , $hsp['Hsp_hit-to'] );
  98. }
  99. $min = min($coords);
  100. $max = max($coords);
  101. $joined_ranges = join ("," , $ranges);
  102. $url_postfix = '&start=' . $min . '&stop=' . $max . '&add=' . $hit->{'hit_name'} . '+BLAST+' . $hit->{'hit_name'} . '_' . $info['query_name'] . '_' . $info['e-value'] . '+' . $joined_ranges ;
  103. return $url_prefix . $url_postfix;
  104. }
  105. /**
  106. * Generate a JBrowse link-out with location information for a given hit.
  107. *
  108. * NOTE: Assumes the hit is a backbone feature in the JBrowse linked to.
  109. * Otherwise, the basic link can be used.
  110. *
  111. * @param $url_prefix
  112. * The URL prefix for the BLAST Database queried.
  113. * @param $hit
  114. * The blast XML hit object. This object has the following keys based on the
  115. * XML: Hit_num, Hit_id, Hit_def, Hit_accession, Hit_len and Hit_hsps.
  116. * Furthermore, the following keys have been added:
  117. * -linkout_id: the part of the Hit_def extracted using a regex provided
  118. * when the blastdb node was created.
  119. * -hit_name: the name of the hit extracted in the template.
  120. * @param $info
  121. * Additional information that may be useful in creating a link-out. Includes:
  122. * - query_name: the name of the query sequence.
  123. * - score: the score of the blast hit.
  124. * - e-value: the e-value of the blast hit.
  125. * @param $options
  126. * Any additional options needed to determine the type of link-out. None are
  127. * supported by this particular link-out type.
  128. *
  129. * @return
  130. * The URL string to be linked to.
  131. */
  132. function tripal_blast_generate_linkout_jbrowse($url_prefix, $hit, $info, $options = array()) {
  133. $ranges = array();
  134. $coords = array();
  135. $hsps = array();
  136. foreach($info['HSPs'] as $hsp) {
  137. $hsp_start = $hsp['Hsp_hit-from'];
  138. $hsp_end = $hsp['Hsp_hit-to'] ;
  139. array_push($coords,$hsp['Hsp_hit-from'] , $hsp['Hsp_hit-to'] );
  140. array_push($ranges, '{"start":'.$hsp_start.',"end":'.$hsp_end.',"type":"match_part"}');
  141. }
  142. $min = min($coords);
  143. $max = max($coords);
  144. $url_postfix = '&addFeatures=[{"seq_id":"'.$hit->{'hit_name'}.'","score":"'.$info['e-value'].'","start":'.$min.',"end":'.$max.',"type":"match","name":"MyBLASTHit","subfeatures":[';
  145. $joined_ranges = join ("," , $ranges);
  146. $url_postfix = $url_postfix . $joined_ranges . ']}]&addTracks=[{"label":"BLAST","type":"JBrowse/View/Track/HTMLFeatures","store":"url"}]&loc='.$hit->{'hit_name'}.'&tracks=DNA%2CBLAST&highlight=';
  147. return $url_prefix . $url_postfix;
  148. }