blast_ui.module 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <?php
  2. /**
  3. * @file
  4. * The main file for the blast UI module.
  5. */
  6. // BLAST Submission Forms
  7. require_once 'includes/blast_ui.form_common.inc';
  8. require_once 'includes/blast_ui.form_advanced_options.inc';
  9. // NOTE: The forms themeselves are included using hook_menu to ensure they
  10. // are only included when needed.
  11. // BLAST DB Node functionality
  12. require_once 'includes/blast_ui.node.inc';
  13. // BLAST Link-out functionality.
  14. require_once 'includes/blast_ui.linkouts.inc';
  15. // Functions specific to themeing (ie: preprocess)
  16. require_once 'theme/blast_ui.theme.inc';
  17. // Application Programmers Interface
  18. require_once 'api/blast_ui.api.inc';
  19. // Administration
  20. require_once 'includes/blast_ui.admin.inc';
  21. /**
  22. * Implements hook_menu().
  23. */
  24. function blast_ui_menu() {
  25. // BLAST DB Node
  26. $items['node__blastdb'] = array(
  27. 'template' => 'node--blastdb',
  28. 'render element' => 'node',
  29. 'base hook' => 'node',
  30. 'path' => 'theme',
  31. );
  32. // Single All-in-One BLAST submission form
  33. $items['blast'] = array(
  34. 'title' => 'BLAST',
  35. 'page callback' => 'drupal_get_form',
  36. 'page arguments' => array('blast_ui_all_in_one_form'),
  37. 'access arguments' => array('access content'),
  38. 'file' => 'includes/blast_ui.form_single.inc',
  39. 'type' => MENU_NORMAL_ITEM,
  40. 'expanded' => TRUE,
  41. );
  42. // Per Query Type BLAST submission forms
  43. $items['blast/nucleotide'] = array(
  44. 'title' => 'Nucleotide Query',
  45. 'page callback' => 'drupal_get_form',
  46. 'page arguments' => array('blast_ui_per_query_type_form', 1, 2),
  47. 'access arguments' => array('access content'),
  48. 'file' => 'includes/blast_ui.form_per_query_type.inc',
  49. 'type' => MENU_NORMAL_ITEM,
  50. 'expanded' => TRUE,
  51. );
  52. $items['blast/protein'] = array(
  53. 'title' => 'Protein Query',
  54. 'page callback' => 'drupal_get_form',
  55. 'page arguments' => array('blast_ui_per_query_type_form', 1),
  56. 'access arguments' => array('access content'),
  57. 'file' => 'includes/blast_ui.form_per_query_type.inc',
  58. 'type' => MENU_NORMAL_ITEM,
  59. 'expanded' => TRUE,
  60. );
  61. // Per BLAST-program submission forms
  62. $items['blast/nucleotide/nucleotide'] = array(
  63. 'title' => 'BLASTn',
  64. 'page callback' => 'drupal_get_form',
  65. 'page arguments' => array('blast_ui_per_blast_program_form', 1, 2),
  66. 'access arguments' => array('access content'),
  67. 'file' => 'includes/blast_ui.form_per_program.inc',
  68. 'type' => MENU_NORMAL_ITEM
  69. );
  70. $items['blast/nucleotide/protein'] = array(
  71. 'title' => 'BLASTx',
  72. 'page callback' => 'drupal_get_form',
  73. 'page arguments' => array('blast_ui_per_blast_program_form', 1, 2),
  74. 'access arguments' => array('access content'),
  75. 'file' => 'includes/blast_ui.form_per_program.inc',
  76. 'type' => MENU_NORMAL_ITEM
  77. );
  78. $items['blast/protein/nucleotide'] = array(
  79. 'title' => 'tBLASTn',
  80. 'page callback' => 'drupal_get_form',
  81. 'page arguments' => array('blast_ui_per_blast_program_form', 1, 2),
  82. 'access arguments' => array('access content'),
  83. 'file' => 'includes/blast_ui.form_per_program.inc',
  84. 'type' => MENU_NORMAL_ITEM
  85. );
  86. $items['blast/protein/protein'] = array(
  87. 'title' => 'BLASTp',
  88. 'page callback' => 'drupal_get_form',
  89. 'page arguments' => array('blast_ui_per_blast_program_form', 1, 2),
  90. 'access arguments' => array('access content'),
  91. 'file' => 'includes/blast_ui.form_per_program.inc',
  92. 'type' => MENU_NORMAL_ITEM
  93. );
  94. // BLAST Results page
  95. $items['blast/report/%'] = array(
  96. 'title' => 'BLAST Results',
  97. 'page callback' => 'show_blast_output',
  98. 'page arguments' => array(2),
  99. 'access arguments' => array('access content'),
  100. 'type' => MENU_CALLBACK,
  101. );
  102. // BLAST Admin
  103. $items['admin/tripal/extension/tripal_blast'] = array(
  104. 'title' => 'Tripal BLAST User Interface',
  105. 'description' => 'Provides an interface allowing users to execute their own BLASTs.',
  106. 'page callback' => 'drupal_get_form',
  107. 'page arguments' => array('blast_ui_admin_form'),
  108. 'access arguments' => array('administer tripal'),
  109. 'type' => MENU_NORMAL_ITEM,
  110. );
  111. $items['admin/tripal/extension/tripal_blast/blast_ui'] = array(
  112. 'title' => 'BLAST UI',
  113. 'type' => MENU_DEFAULT_LOCAL_TASK,
  114. );
  115. $items['admin/tripal/extension/tripal_blast/help'] = array(
  116. 'title' => 'Help',
  117. 'page callback' => 'theme',
  118. 'page arguments' => array('blast_help'),
  119. 'access arguments' => array('administer tripal'),
  120. 'type' => MENU_LOCAL_TASK,
  121. );
  122. return $items;
  123. }
  124. /**
  125. * Implements hook_theme().
  126. */
  127. function blast_ui_theme() {
  128. $items = array();
  129. $path = drupal_get_path('module', 'blast_ui');
  130. // Displays the BLAST results for each job
  131. $items['show_blast_report'] = array(
  132. 'template' => 'blast_report',
  133. 'path' => "$path/theme",
  134. );
  135. // Displays the BLAST results for each job
  136. $items['blast_report_pending'] = array(
  137. 'template' => 'blast_report_pending',
  138. 'path' => "$path/theme",
  139. );
  140. // Themes the alignments in a BLAST result display
  141. $items['blast_report_alignment_row'] = array(
  142. 'template' => 'blast_report_alignment_row',
  143. 'variables' => array('hsps' => NULL),
  144. 'path' => "$path/theme",
  145. );
  146. // Lists the recent blast jobs for a given user/session.
  147. $items['blast_recent_jobs'] = array(
  148. 'template' => 'blast_recent_jobs',
  149. 'variables' => array('programs' => NULL),
  150. 'path' => "$path/theme",
  151. );
  152. // Module Help
  153. $items['blast_help'] = array(
  154. 'template' => 'blast_help',
  155. 'path' => "$path/theme",
  156. );
  157. // Menu Information Pages
  158. // These are only seen if the user has disabled the all-in-one
  159. // or by query type forms.
  160. $items['blast_user_menupage'] = array(
  161. 'template' => 'blast_user_menupage',
  162. 'path' => "$path/theme",
  163. );
  164. $items['blast_nucleotide_user_menupage'] = array(
  165. 'template' => 'blast_nucleotide_user_menupage',
  166. 'path' => "$path/theme",
  167. );
  168. $items['blast_protein_user_menupage'] = array(
  169. 'template' => 'blast_protein_user_menupage',
  170. 'path' => "$path/theme",
  171. );
  172. return $items;
  173. }
  174. /**
  175. * Implements hook_help().
  176. */
  177. function blast_ui_help($path, $arg) {
  178. if ($path == 'admin/help#blast_ui') {
  179. return theme('blast_help');
  180. }
  181. }
  182. /**
  183. * Implements hook_libraries_info().
  184. */
  185. function blast_ui_libraries_info() {
  186. // Tell the libraries API about CViTjs
  187. $libraries['cvitjs'] = array(
  188. 'name' => 'CViTjs',
  189. 'vendor url' => 'https://github.com/awilkey/cvitjs',
  190. 'version' => '0.0.1',
  191. 'download url' => 'https://github.com/awilkey/cvitjs/archive/master.zip',
  192. );
  193. return $libraries;
  194. }
  195. /**
  196. * Facilitate presenting the result of the blast search
  197. *
  198. * @param $job_id
  199. * The tripal job_id of the BLAST job previously submitted
  200. *
  201. * @return $result
  202. * Return HTML output of the BLAST results to be displayed to the user
  203. *
  204. */
  205. function show_blast_output($job_string) {
  206. // BLASTs are run as a Tripal job. As such we need to determine whether the current
  207. // BLAST is in the queue, running or complete in order to determine what to show the user
  208. //decode the job_id
  209. $job_id = blast_ui_reveal_secret($job_string);
  210. $job = tripal_get_job($job_id);
  211. // 1) Job is in the Queue
  212. if ($job->start_time === NULL AND $job->end_time == NULL) {
  213. return theme('blast_report_pending', array('status_code' => 0, 'status' => 'Pending'));
  214. }
  215. // 2) Job has been Cancelled
  216. elseif ($job->status == 'Cancelled') {
  217. return theme('blast_report_pending', array('status_code' => 999, 'status' => 'Cancelled'));
  218. }
  219. // 3) Job is Complete
  220. elseif ($job->end_time !== NULL) {
  221. // Return the Results :)
  222. return theme('show_blast_report', array('job_id' => $job_id));
  223. }
  224. // 4) Job is in Progress
  225. else {
  226. return theme('blast_report_pending', array('status_code' => 1, 'status' => 'Running'));
  227. }
  228. return '';
  229. }
  230. /**
  231. * Enable web services API
  232. *
  233. * @param $owner
  234. *
  235. * @param $api
  236. *
  237. * @return $result
  238. *
  239. */
  240. function blast_ui_ctools_plugin_api($owner, $api) {
  241. if ($owner == 'services' && $api == 'services') {
  242. return array(
  243. 'version' => 3,
  244. 'file' => 'includes/blast_ui.services.inc'
  245. );
  246. }
  247. }