blast_ui.module 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. /**
  10. *
  11. * Implements hook_menu()
  12. *
  13. */
  14. function blast_ui_menu() {
  15. $items['blast'] = array(
  16. 'title' => 'BLAST',
  17. 'page callback' => 'drupal_get_form',
  18. 'page arguments' => array('blast_nucleotide_form'),
  19. 'access arguments' => array('access content'),
  20. 'type' => MENU_NORMAL_ITEM,
  21. 'expanded' => TRUE,
  22. );
  23. $items['blast/report/%'] = array(
  24. 'title' => 'Nucleotide BLAST result:',
  25. 'page callback' => 'show_blast_output',
  26. 'page arguments' => array(2),
  27. 'access arguments' => array('access content'),
  28. 'type' => MENU_CALLBACK,
  29. );
  30. $items['blast/blastn'] = array(
  31. 'title' => 'Nucleotide BLAST',
  32. 'page callback' => 'drupal_get_form',
  33. 'page arguments' => array('blast_nucleotide_form'),
  34. 'access arguments' => array('access content'),
  35. 'type' => MENU_NORMAL_ITEM
  36. );
  37. // $items['blast/blastp'] = array(
  38. // 'title' => 'Protein BLAST',
  39. // 'page callback' => 'drupal_get_form',
  40. // 'page arguments' => array('blast_protein_form'),
  41. // 'access arguments' => array('access content'),
  42. // 'type' => MENU_NORMAL_ITEM
  43. // );
  44. return $items;
  45. }
  46. /**
  47. * Facilitate presenting the result of the blast search
  48. *
  49. * @param $args
  50. * A string containing name of the blast output file.
  51. *
  52. * @return $result
  53. * Return a string containing the blast search output. A link is also provided to let users download the output file.
  54. *
  55. */
  56. function show_blast_output($args = 'all') {
  57. if (preg_match('/^[^\/]*/',$args)) {
  58. // Since the blast results are in the files directory we can use public:// to get around hard-coding the full path
  59. $full_path_filename = 'public://'.$args;
  60. if (file_exists($full_path_filename)) {
  61. $result = t('<br /><h3>BLAST Results: <a href="@url" target="_blank">HTML</a></h3>', array('@url' => url('sites/default/files/' . $args)));
  62. $result .= check_markup(file_get_contents($full_path_filename), 'full_html');
  63. $result = str_replace('<script src="blastResult.js"></script>','',$result);
  64. }
  65. else {
  66. tripal_report_error(
  67. 'blast_ui',
  68. TRIPAL_ERROR,
  69. 'Unable to open blast results file (%file)',
  70. array('%file' => $full_path_filename)
  71. );
  72. $result = '<p>An error was encountered while trying to process your blast results</p>';
  73. }
  74. }
  75. else {
  76. $result = '<p>An error was encountered while trying to process your blast results</p>';
  77. }
  78. return $result;
  79. }