blast_ui.module 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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 inlcuded 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. // Module Help
  147. $items['blast_help'] = array(
  148. 'template' => 'blast_help',
  149. 'path' => "$path/theme",
  150. );
  151. // Menu Information Pages
  152. // These are only seen if the user has disabled the all-in-one
  153. // or by query type forms.
  154. $items['blast_user_menupage'] = array(
  155. 'template' => 'blast_user_menupage',
  156. 'path' => "$path/theme",
  157. );
  158. $items['blast_nucleotide_user_menupage'] = array(
  159. 'template' => 'blast_nucleotide_user_menupage',
  160. 'path' => "$path/theme",
  161. );
  162. $items['blast_protein_user_menupage'] = array(
  163. 'template' => 'blast_protein_user_menupage',
  164. 'path' => "$path/theme",
  165. );
  166. return $items;
  167. }
  168. /**
  169. * Implements hook_help().
  170. */
  171. function blast_ui_help($path, $arg) {
  172. if ($path == 'admin/help#blast_ui') {
  173. return theme('blast_help');
  174. }
  175. }
  176. /**
  177. * Facilitate presenting the result of the blast search
  178. *
  179. * @param $job_id
  180. * The tripal job_id of the BLAST job previously submitted
  181. *
  182. * @return $result
  183. * Return HTML output of the BLAST results to be displayed to the user
  184. *
  185. */
  186. function show_blast_output($job_id) {
  187. // BLASTs are run as a Tripal job. As such we need to determine whether the current
  188. // BLAST is in the queue, running or complete in order to determine what to show the user
  189. $job = tripal_get_job($job_id);
  190. // 1) Job is in the Queue
  191. if ($job->start_time === NULL AND $job->end_time == NULL) {
  192. return theme('blast_report_pending', array('status_code' => 0, 'status' => 'Pending'));
  193. }
  194. // 2) Job has been Cancelled
  195. elseif ($job->status == 'Cancelled') {
  196. return theme('blast_report_pending', array('status_code' => 999, 'status' => 'Cancelled'));
  197. }
  198. // 3) Job is Complete
  199. elseif ($job->end_time !== NULL) {
  200. // Return the Results :)
  201. return theme('show_blast_report', array('job_id' => $job_id));
  202. }
  203. // 4) Job is in Progress
  204. else {
  205. return theme('blast_report_pending', array('status_code' => 1, 'status' => 'Running'));
  206. }
  207. return '';
  208. }
  209. /**
  210. *
  211. */
  212. function ajax_blast_ui_example_sequence_callback($form, $form_state) {
  213. // First, set a default example sequence in case administrators have not yet
  214. // bothered to set their own.
  215. $sequence_type = $form_state['values']['query_type'];
  216. if ($sequence_type == 'nucleotide') {
  217. $default_example_sequence = '>partial lipoxygenase Glyma15g03040
  218. TTTCGTATGA GATTAAAATG TGTGAAATTT TGTTTGATAG GACATGGGAA
  219. AGGAAAAGTT GGAAAGGCTA CAAATTTAAG AGGACAAGTG TCGTTACCAA
  220. CCTTGGGAGC TGGCGAAGAT GCATACGATG TTCATTTTGA ATGGGACAGT
  221. GACTTCGGAA TTCCCGGTGC ATTTTACATT AAGAACTTCA TGCAAGTTGA
  222. GTTCTATCTC AAGTCTCTAA CTCTCGAAGA CATTCCAAAC CACGGAACCA
  223. TTCACTTCGT ATGCAACTCC TGGGTTTACA ACTCAAAATC CTACCATTCT
  224. GATCGCATTT TCTTTGCCAA CAATGTAAGC TACTTAAATA CTGTTATACA
  225. TTGTCTAACA TCTTGTTAGA GTCTTGCATG ATGTGTACCG TTTATTGTTG
  226. TTGTTGAACT TTACCACATG GCATGGATGC AAAAGTTGTT ATACACATAA
  227. ATTATAATGC AGACATATCT TCCAAGCGAG ACACCGGCTC CACTTGTCAA
  228. GTACAGAGAA GAAGAATTGA AGAATGTAAG AGGGGATGGA ACTGGTGAGC
  229. GCAAGGAATG GGATAGGATC TATGATTATG ATGTCTACAA TGACTTGGGC
  230. GATCCAGATA AGGGTGAAAA GTATGCACGC CCCGTTCTTG GAGGTTCTGC
  231. CTTACCTTAC CCTCGCAGAG GAAGAACCGG AAGAGGAAAA ACTAGAAAAG
  232. GTTTCTCACT AGTCACTAAT TTATTACTTT TTAATGTTTG TTTTTAGGCA
  233. TCTTTTCTGA TGAAATGTAT ACTTTTGATG TTTTTTTGTT TTAGCATAAC
  234. TGAATTAGTA AAGTGTGTTG TGTTCCTTAG AAGTTAGAAA AGTACTAAGT
  235. ATAAGGTCTT TGAGTTGTCG TCTTTATCTT AACAGATCCC AACAGTGAGA
  236. AGCCCAGTGA TTTTGTTTAC CTTCCGAGAG ATGAAGCATT TGGTCACTTG
  237. AAGTCATCAG ATTTTCTCGT TTATGGAATC AAATCAGTGG CTCAAGACGT
  238. CTTGCCCGTG TTGACTGATG CGTTTGATGG CAATCTTTTG AGCCTTGAGT
  239. TTGATAACTT TGCTGAAGTG CGCAAACTCT ATGAAGGTGG AGTTACACTA
  240. CCTACAAACT TTCTTAGCAA GATCGCCCCT ATACCAGTGG TCAAGGAAAT
  241. TTTTCGAACT GATGGCGAAC AGTTCCTCAA GTATCCACCA CCTAAAGTGA
  242. TGCAGGGTAT GCTACATATT TTGAATATGT AGAATATTAT CAATATACTC
  243. CTGTTTTTAT TCAACATATT TAATCACATG GATGAATTTT TGAACTGTTA';
  244. }
  245. elseif ($sequence_type == 'protein') {
  246. $default_example_sequence = '>gi|166477|gb|AAA96434.1| resveratrol synthase [Arachis hypogaea]
  247. MVSVSGIRKVQRAEGPATVLAIGTANPPNCIDQSTYADYYFRVTNSEHMTDLKKKFQRICERTQIKNRHM
  248. YLTEEILKENPNMCAYKAPSLDAREDMMIREVPRVGKEAATKAIKEWGQPMSKITHLIFCTTSGVALPGV
  249. DYELIVLLGLDPCVKRYMMYHQGCFAGGTVLRLAKDLAENNKDARVLIVCSENTAVTFRGPSETDMDSLV
  250. GQALFADGAAAIIIGSDPVPEVEKPIFELVSTDQKLVPGSHGAIGGLLREVGLTFYLNKSVPDIISQNIN
  251. DALNKAFDPLGISDYNSIFWIAHPGGRAILDQVEQKVNLKPEKMKATRDVLSNYGNMSSACVFFIMDLMR
  252. KRSLEEGLKTTGEGLDWGVLFGFGPGLTIETVVLRSVAI';
  253. }
  254. else {
  255. $default_example_sequence = '';
  256. }
  257. // If the Show Example checkbox is true then put the example in the textfield
  258. if ($form_state['values']['example_sequence']) {
  259. // Set the value to be the example sequence (either set by the administrator
  260. // or the default set above).
  261. $form['query']['FASTA']['#value'] = variable_get(
  262. 'blast_ui_' . $sequence_type . '_example_sequence',
  263. $default_example_sequence
  264. );
  265. }
  266. // Otherwise we want to remove the already displayed example.
  267. else {
  268. $form['query']['FASTA']['#value'] = '';
  269. }
  270. return $form['query']['FASTA'];
  271. }