blast_ui.module 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * @file
  4. * Contains all functions for the blast module
  5. */
  6. require_once 'includes/blast_ui.blastn.inc';
  7. require_once 'includes/blast_ui.blastp.inc';
  8. require_once 'includes/blast_ui.node.inc';
  9. require_once 'theme/blast_ui.theme.inc';
  10. /**
  11. *
  12. * Implements hook_theme()
  13. *
  14. */
  15. function blast_ui_theme() {
  16. $items = array();
  17. $path = drupal_get_path('module', 'blast_ui');
  18. $items['show_blast_report'] = array(
  19. 'template' => 'blast_report',
  20. 'path' => "$path/theme",
  21. );
  22. $items['blast_report_alignment_row'] = array(
  23. 'template' => 'blast_report_alignment_row',
  24. 'variables' => array('hsps' => NULL),
  25. 'path' => "$path/theme",
  26. );
  27. return $items;
  28. }
  29. /**
  30. *
  31. * Implements hook_menu()
  32. *
  33. */
  34. function blast_ui_menu() {
  35. $items['blast'] = array(
  36. 'title' => 'BLAST',
  37. 'page callback' => 'drupal_get_form',
  38. 'page arguments' => array('blast_nucleotide_form'),
  39. 'access arguments' => array('access content'),
  40. 'type' => MENU_NORMAL_ITEM,
  41. 'expanded' => TRUE,
  42. );
  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. $items['blast/blastn'] = array(
  51. 'title' => 'Nucleotide BLAST',
  52. 'page callback' => 'drupal_get_form',
  53. 'page arguments' => array('blast_nucleotide_form'),
  54. 'access arguments' => array('access content'),
  55. 'type' => MENU_NORMAL_ITEM
  56. );
  57. $items['blast/blastp'] = array(
  58. 'title' => 'Protein BLAST',
  59. 'page callback' => 'drupal_get_form',
  60. 'page arguments' => array('blast_protein_form'),
  61. 'access arguments' => array('access content'),
  62. 'type' => MENU_NORMAL_ITEM
  63. );
  64. return $items;
  65. }
  66. /**
  67. * Facilitate presenting the result of the blast search
  68. *
  69. * @param $args
  70. * A string containing name of the blast output file.
  71. *
  72. * @return $result
  73. * Return a string containing the blast search output. A link is also provided to let users download the output file.
  74. *
  75. */
  76. function show_blast_output($args = 'all') {
  77. if (preg_match('/^[^\/]*/',$args)) {
  78. // Since the blast results are in the files directory we can use public:// to get around hard-coding the full path
  79. $full_path_filename = 'public://'.$args;
  80. if (file_exists($full_path_filename)) {
  81. // $result = t('<br /><h3>BLAST Results: <a href="@url" target="_blank">HTML</a></h3>', array('@url' => url('sites/default/files/' . $args)));
  82. // $result .= check_markup(file_get_contents($full_path_filename), 'full_html');
  83. // $result = str_replace('<script src="blastResult.js"></script>','',$result);
  84. $result = theme('show_blast_report');
  85. }
  86. else {
  87. tripal_report_error(
  88. 'blast_ui',
  89. TRIPAL_ERROR,
  90. 'Unable to open blast results file (%file)',
  91. array('%file' => $full_path_filename)
  92. );
  93. $result = '<p>An error was encountered while trying to process your blast results</p>';
  94. }
  95. }
  96. else {
  97. $result = '<p>An error was encountered while trying to process your blast results</p>';
  98. }
  99. return $result;
  100. }