blast_ui.module 8.4 KB

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