custom_linkouts.rst 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. Custom Link-outs
  2. =================
  3. In Tripal BLAST "Linkouts" refer to changing the hit name in the BLAST results table to a link. This link usually gives the user additional information and may link to pages in your Tripal site, external websites or genome browsers. You can configure link-outs per BLAST Database and depending on the type, many link-outs support regular expression for extracting parts of the name. The types provided by Tripal BLAST also require you select a Tripal Database (Tripal > Chado Modules > Databases) which contains the URL information for the link. If the link-out types supplied by Tripal BLAST do not fit your needs you can create a custom type using the documentation below.
  4. To create custom link-outs for Tripal BLAST you need to first create your own Drupal module. If you are unfamiliar with this process there are a number of good tutorial available in addition to the Drupal Documentation.
  5. Once you have a custom module you need to implement hook_blast_linkout_info() to tell Tripal BLAST about your custom link-out. You do this by creating a function with the name of your module replacing the word "hook". For example:
  6. .. code-block:: php
  7. /**
  8. * Implements hook_blast_linkout_info().
  9. * Provides a custom link-out type for my institutes genome browser.
  10. */
  11. function mymodule_blast_linkout_info() {
  12. $types = array();
  13. $types['mybrowser'] = array(
  14. // Human-readable Type name to display to users in the BLAST Database
  15. // create/edit form.
  16. 'name' => 'UofS Browser',
  17. // The function used to generate the URL to be linked to.
  18. // This function will have full access to the blast hit and database
  19. // prefix information and is expected to return a URL.
  20. 'process function' => 'mymodule_generate_linkout_mybrowser',
  21. // Help text to show in the BLAST Database create/edit form so that
  22. // users will know how to use this link-out type. Specifically, info
  23. // about your assumptions for the URL prefix are very helpful.
  24. // HTML is aloud but do not enclose in <p>.
  25. 'help' => 'This type assumes your blast database is the reference for one
  26. of the University of Saskatchewan Genome Browsers and that you have selected
  27. the Tripal Database referencing that browser below.',
  28. // Whether or not the link-out requires additional fields from the nodes.
  29. 'require_regex' => TRUE,
  30. 'require_db' => TRUE,
  31. );
  32. return $types;
  33. }
  34. Next you need to implement the process function that you indicated. This function is given a number of variables providing information about the hit, etc. and is expected to generate a fully rendered link based on that information. For example,
  35. .. code-block:: php
  36. /**
  37. * Generate a link to the UofS Genome Browser for a given hit.
  38. *
  39. * @param $url_prefix
  40. * The URL prefix for the BLAST Database queried.
  41. * @param $hit
  42. * The blast XML hit object. This object has the following keys based on the
  43. * XML: Hit_num, Hit_id, Hit_def, Hit_accession, Hit_len and Hit_hsps.
  44. * Furthermore, a linkout_id key has beek added that contains the part of the
  45. * Hit_def extracted using a regex provided when the blastdb node was created.
  46. * @param $info
  47. * Additional information that may be useful in creating a link-out. Includes:
  48. * - query_name: the name of the query sequence.
  49. * - score: the score of the blast hit.
  50. * - e-value: the e-value of the blast hit.
  51. * @param $options
  52. * Any additional options needed to determine the type of link-out. None are
  53. * supported by this particular link-out type.
  54. *
  55. * @return
  56. * An html link.
  57. */
  58. function tripal_blast_generate_linkout_link($url_prefix, $hit, $info, $options = array()) {
  59. if (isset($hit->{'linkout_id'})) {
  60. // This is where you would generate your link. If your link requires query parameters
  61. // then we suggest you use l() $options['query'] to encode them rather than appending
  62. // them to the URL prefix directly.
  63. // This StackExchange question shows a good example:
  64. // http://drupal.stackexchange.com/questions/38663/how-to-add-additional-url-parameters
  65. $hit_url = $url_prefix . $hit->{'linkout_id'};
  66. // See the documentation for l():
  67. // https://api.drupal.org/api/drupal/includes%21common.inc/function/l/7
  68. return l(
  69. $hit->{'linkout_id'},
  70. $hit_url,
  71. array('attributes' => array('target' => '_blank'))
  72. );
  73. }
  74. else {
  75. return FALSE;
  76. }
  77. }