blast_ui.module 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /**
  3. * @file
  4. * The main file for the blast UI module.
  5. */
  6. // Type-specific BLAST functionality
  7. require_once 'includes/blast_ui.blastn.inc';
  8. require_once 'includes/blast_ui.blastp.inc';
  9. // BLAST DB Node functionality
  10. require_once 'includes/blast_ui.node.inc';
  11. // Functions specific to themeing (ie: preprocess)
  12. require_once 'theme/blast_ui.theme.inc';
  13. /**
  14. * Implements hook_menu().
  15. */
  16. function blast_ui_menu() {
  17. // Parent menu-item for BLAST submission
  18. $items['blast'] = array(
  19. 'title' => 'BLAST',
  20. 'page callback' => 'drupal_get_form',
  21. 'page arguments' => array('blast_nucleotide_form'),
  22. 'access arguments' => array('access content'),
  23. 'type' => MENU_NORMAL_ITEM,
  24. 'expanded' => TRUE,
  25. );
  26. // Nucleotide BLAST submission form
  27. $items['blast/blastn'] = array(
  28. 'title' => 'Nucleotide BLAST',
  29. 'page callback' => 'drupal_get_form',
  30. 'page arguments' => array('blast_nucleotide_form'),
  31. 'access arguments' => array('access content'),
  32. 'type' => MENU_NORMAL_ITEM
  33. );
  34. // Protein BLAST submission form
  35. $items['blast/blastp'] = array(
  36. 'title' => 'Protein BLAST',
  37. 'page callback' => 'drupal_get_form',
  38. 'page arguments' => array('blast_protein_form'),
  39. 'access arguments' => array('access content'),
  40. 'type' => MENU_NORMAL_ITEM
  41. );
  42. // BLAST Results page
  43. $items['blast/report/%'] = array(
  44. 'title' => 'BLAST result:',
  45. 'page callback' => 'show_blast_output',
  46. 'page arguments' => array(2),
  47. 'access arguments' => array('access content'),
  48. 'type' => MENU_CALLBACK,
  49. );
  50. return $items;
  51. }
  52. /**
  53. * Implements hook_theme().
  54. */
  55. function blast_ui_theme() {
  56. $items = array();
  57. $path = drupal_get_path('module', 'blast_ui');
  58. // Displays the BLAST results for each job
  59. $items['show_blast_report'] = array(
  60. 'template' => 'blast_report',
  61. 'path' => "$path/theme",
  62. );
  63. // Themes the alignments in a BLAST result display
  64. $items['blast_report_alignment_row'] = array(
  65. 'template' => 'blast_report_alignment_row',
  66. 'variables' => array('hsps' => NULL),
  67. 'path' => "$path/theme",
  68. );
  69. return $items;
  70. }
  71. /**
  72. * Facilitate presenting the result of the blast search
  73. *
  74. * @param $args
  75. * A string containing name of the blast output file.
  76. *
  77. * @return $result
  78. * Return HTML output of the BLAST results to be displayed to the user
  79. *
  80. */
  81. function show_blast_output($args = 'all') {
  82. // Double-check that there are no directory slashes in the path since this could be used
  83. // present a security risk (ie: if the path contained ../../../etc/someconfig.file this
  84. // we don't want to process or display anything.
  85. if (preg_match('/^[^\/]*$/',$args)) {
  86. // Since the blast results are in the files directory
  87. // we can use public:// to get around hard-coding the full path
  88. $full_path_filename = 'public://'.$args;
  89. // check that the XML file exists before trying to display results
  90. if (file_exists($full_path_filename)) {
  91. // Use the show_blast_output.tpl.php to generate the HTML
  92. $result = theme('show_blast_report');
  93. }
  94. else {
  95. // If the file doesn't exist then throw a tripal error
  96. // as well as displaying an error to the user
  97. tripal_report_error(
  98. 'blast_ui',
  99. TRIPAL_ERROR,
  100. 'Unable to open blast results file (%file)',
  101. array('%file' => $full_path_filename)
  102. );
  103. $result = '<p>An error was encountered while trying to process your blast results</p>';
  104. }
  105. }
  106. else {
  107. // If there are directory slashes in the path then just display an error to the user
  108. // rather than risk the security of the server
  109. $result = '<p>An error was encountered while trying to process your blast results</p>';
  110. }
  111. return $result;
  112. }