blast_ui.module 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. // Application Programmers Interface
  14. require_once 'api/blast_ui.api.inc';
  15. /**
  16. * Implements hook_menu().
  17. */
  18. function blast_ui_menu() {
  19. // Parent menu-item for BLAST submission
  20. $items['blast'] = array(
  21. 'title' => 'BLAST',
  22. 'page callback' => 'drupal_get_form',
  23. 'page arguments' => array('blast_nucleotide_form'),
  24. 'access arguments' => array('access content'),
  25. 'type' => MENU_NORMAL_ITEM,
  26. 'expanded' => TRUE,
  27. );
  28. // Nucleotide BLAST submission form
  29. $items['blast/blastn'] = array(
  30. 'title' => 'Nucleotide BLAST',
  31. 'page callback' => 'drupal_get_form',
  32. 'page arguments' => array('blast_nucleotide_form'),
  33. 'access arguments' => array('access content'),
  34. 'type' => MENU_NORMAL_ITEM
  35. );
  36. // Protein BLAST submission form
  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. // BLAST Results page
  45. $items['blast/report/%'] = array(
  46. 'title' => 'BLAST Results',
  47. 'page callback' => 'show_blast_output',
  48. 'page arguments' => array(2),
  49. 'access arguments' => array('access content'),
  50. 'type' => MENU_CALLBACK,
  51. );
  52. return $items;
  53. }
  54. /**
  55. * Implements hook_theme().
  56. */
  57. function blast_ui_theme() {
  58. $items = array();
  59. $path = drupal_get_path('module', 'blast_ui');
  60. // Displays the BLAST results for each job
  61. $items['show_blast_report'] = array(
  62. 'template' => 'blast_report',
  63. 'path' => "$path/theme",
  64. );
  65. // Displays the BLAST results for each job
  66. $items['blast_report_pending'] = array(
  67. 'template' => 'blast_report_pending',
  68. 'path' => "$path/theme",
  69. );
  70. // Themes the alignments in a BLAST result display
  71. $items['blast_report_alignment_row'] = array(
  72. 'template' => 'blast_report_alignment_row',
  73. 'variables' => array('hsps' => NULL),
  74. 'path' => "$path/theme",
  75. );
  76. return $items;
  77. }
  78. /**
  79. * Facilitate presenting the result of the blast search
  80. *
  81. * @param $job_id
  82. * The tripal job_id of the BLAST job previously submitted
  83. *
  84. * @return $result
  85. * Return HTML output of the BLAST results to be displayed to the user
  86. *
  87. */
  88. function show_blast_output($job_id) {
  89. // BLASTs are run as a Tripal job. As such we need to determine whether the current
  90. // BLAST is in the queue, running or complete in order to determine what to show the user
  91. $job = tripal_get_job($job_id);
  92. // 1) Job is in the Queue
  93. if ($job->start_time === NULL AND $job->end_time == NULL) {
  94. return theme('blast_report_pending', array('status_code' => 0, 'status' => 'Pending'));
  95. }
  96. // 2) Job has been Cancelled
  97. elseif ($job->status == 'Cancelled') {
  98. return theme('blast_report_pending', array('status_code' => 999, 'status' => 'Cancelled'));
  99. }
  100. // 3) Job is Complete
  101. elseif ($job->end_time !== NULL) {
  102. // Return the Results :)
  103. return theme('show_blast_report', array('job_id' => $job_id));
  104. }
  105. // 4) Job is in Progress
  106. else {
  107. return theme('blast_report_pending', array('status_code' => 1, 'status' => 'Running'));
  108. }
  109. return '';
  110. }