blast_ui.module 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. // Functions specific to themeing (ie: preprocess)
  14. require_once 'theme/blast_ui.theme.inc';
  15. // Application Programmers Interface
  16. require_once 'api/blast_ui.api.inc';
  17. // Administration
  18. require_once 'includes/blast_ui.admin.inc';
  19. /**
  20. * Implements hook_menu().
  21. */
  22. function blast_ui_menu() {
  23. // BLAST DB Node
  24. $items['node__blastdb'] = array(
  25. 'template' => 'node--blastdb',
  26. 'render element' => 'node',
  27. 'base hook' => 'node',
  28. 'path' => 'theme',
  29. );
  30. // Single All-in-One BLAST submission form
  31. $items['blast'] = array(
  32. 'title' => 'BLAST',
  33. 'page callback' => 'drupal_get_form',
  34. 'page arguments' => array('blast_ui_all_in_one_form'),
  35. 'access arguments' => array('access content'),
  36. 'file' => 'includes/blast_ui.form_single.inc',
  37. 'type' => MENU_NORMAL_ITEM,
  38. 'expanded' => TRUE,
  39. );
  40. // Per Query Type BLAST submission forms
  41. $items['blast/nucleotide'] = array(
  42. 'title' => 'Nucleotide Query',
  43. 'page callback' => 'drupal_get_form',
  44. 'page arguments' => array('blast_ui_per_query_type_form', 1, 2),
  45. 'access arguments' => array('access content'),
  46. 'file' => 'includes/blast_ui.form_per_query_type.inc',
  47. 'type' => MENU_NORMAL_ITEM,
  48. 'expanded' => TRUE,
  49. );
  50. $items['blast/protein'] = array(
  51. 'title' => 'Protein Query',
  52. 'page callback' => 'drupal_get_form',
  53. 'page arguments' => array('blast_ui_per_query_type_form', 1),
  54. 'access arguments' => array('access content'),
  55. 'file' => 'includes/blast_ui.form_per_query_type.inc',
  56. 'type' => MENU_NORMAL_ITEM,
  57. 'expanded' => TRUE,
  58. );
  59. // Per BLAST-program submission forms
  60. $items['blast/nucleotide/nucleotide'] = array(
  61. 'title' => 'BLASTn',
  62. 'page callback' => 'drupal_get_form',
  63. 'page arguments' => array('blast_ui_per_blast_program_form', 1, 2),
  64. 'access arguments' => array('access content'),
  65. 'file' => 'includes/blast_ui.form_per_program.inc',
  66. 'type' => MENU_NORMAL_ITEM
  67. );
  68. $items['blast/nucleotide/protein'] = array(
  69. 'title' => 'BLASTx',
  70. 'page callback' => 'drupal_get_form',
  71. 'page arguments' => array('blast_ui_per_blast_program_form', 1, 2),
  72. 'access arguments' => array('access content'),
  73. 'file' => 'includes/blast_ui.form_per_program.inc',
  74. 'type' => MENU_NORMAL_ITEM
  75. );
  76. $items['blast/protein/nucleotide'] = array(
  77. 'title' => 'tBLASTn',
  78. 'page callback' => 'drupal_get_form',
  79. 'page arguments' => array('blast_ui_per_blast_program_form', 1, 2),
  80. 'access arguments' => array('access content'),
  81. 'file' => 'includes/blast_ui.form_per_program.inc',
  82. 'type' => MENU_NORMAL_ITEM
  83. );
  84. $items['blast/protein/protein'] = array(
  85. 'title' => 'BLASTp',
  86. 'page callback' => 'drupal_get_form',
  87. 'page arguments' => array('blast_ui_per_blast_program_form', 1, 2),
  88. 'access arguments' => array('access content'),
  89. 'file' => 'includes/blast_ui.form_per_program.inc',
  90. 'type' => MENU_NORMAL_ITEM
  91. );
  92. // BLAST Results page
  93. $items['blast/report/%'] = array(
  94. 'title' => 'BLAST Results',
  95. 'page callback' => 'show_blast_output',
  96. 'page arguments' => array(2),
  97. 'access arguments' => array('access content'),
  98. 'type' => MENU_CALLBACK,
  99. );
  100. // BLAST Admin
  101. $items['admin/tripal/extension/blast_ui'] = array(
  102. 'title' => 'BLAST User Interface',
  103. 'description' => 'Provides an interface allowing users to execute their own BLASTs.',
  104. 'page callback' => 'drupal_get_form',
  105. 'page arguments' => array('blast_ui_admin_form'),
  106. 'access arguments' => array('administer tripal'),
  107. 'type' => MENU_NORMAL_ITEM,
  108. );
  109. return $items;
  110. }
  111. /**
  112. * Implements hook_theme().
  113. */
  114. function blast_ui_theme() {
  115. $items = array();
  116. $path = drupal_get_path('module', 'blast_ui');
  117. // Displays the BLAST results for each job
  118. $items['show_blast_report'] = array(
  119. 'template' => 'blast_report',
  120. 'path' => "$path/theme",
  121. );
  122. // Displays the BLAST results for each job
  123. $items['blast_report_pending'] = array(
  124. 'template' => 'blast_report_pending',
  125. 'path' => "$path/theme",
  126. );
  127. // Themes the alignments in a BLAST result display
  128. $items['blast_report_alignment_row'] = array(
  129. 'template' => 'blast_report_alignment_row',
  130. 'variables' => array('hsps' => NULL),
  131. 'path' => "$path/theme",
  132. );
  133. // Menu Information Pages
  134. // These are only seen if the user has disabled the all-in-one
  135. // or by query type forms.
  136. $items['blast_user_menupage'] = array(
  137. 'template' => 'blast_user_menupage',
  138. 'path' => "$path/theme",
  139. );
  140. $items['blast_nucleotide_user_menupage'] = array(
  141. 'template' => 'blast_nucleotide_user_menupage',
  142. 'path' => "$path/theme",
  143. );
  144. $items['blast_protein_user_menupage'] = array(
  145. 'template' => 'blast_protein_user_menupage',
  146. 'path' => "$path/theme",
  147. );
  148. return $items;
  149. }
  150. /**
  151. * Facilitate presenting the result of the blast search
  152. *
  153. * @param $job_id
  154. * The tripal job_id of the BLAST job previously submitted
  155. *
  156. * @return $result
  157. * Return HTML output of the BLAST results to be displayed to the user
  158. *
  159. */
  160. function show_blast_output($job_id) {
  161. // BLASTs are run as a Tripal job. As such we need to determine whether the current
  162. // BLAST is in the queue, running or complete in order to determine what to show the user
  163. $job = tripal_get_job($job_id);
  164. // 1) Job is in the Queue
  165. if ($job->start_time === NULL AND $job->end_time == NULL) {
  166. return theme('blast_report_pending', array('status_code' => 0, 'status' => 'Pending'));
  167. }
  168. // 2) Job has been Cancelled
  169. elseif ($job->status == 'Cancelled') {
  170. return theme('blast_report_pending', array('status_code' => 999, 'status' => 'Cancelled'));
  171. }
  172. // 3) Job is Complete
  173. elseif ($job->end_time !== NULL) {
  174. // Return the Results :)
  175. return theme('show_blast_report', array('job_id' => $job_id));
  176. }
  177. // 4) Job is in Progress
  178. else {
  179. return theme('blast_report_pending', array('status_code' => 1, 'status' => 'Running'));
  180. }
  181. return '';
  182. }
  183. /**
  184. *
  185. */
  186. function ajax_blast_ui_example_sequence_callback($form, $form_state) {
  187. // First, set a default example sequence in case administrators have not yet
  188. // bothered to set their own.
  189. $sequence_type = $form_state['values']['query_type'];
  190. if ($sequence_type == 'nucleotide') {
  191. $default_example_sequence = '>partial lipoxygenase Glyma15g03040
  192. TTTCGTATGA GATTAAAATG TGTGAAATTT TGTTTGATAG GACATGGGAA
  193. AGGAAAAGTT GGAAAGGCTA CAAATTTAAG AGGACAAGTG TCGTTACCAA
  194. CCTTGGGAGC TGGCGAAGAT GCATACGATG TTCATTTTGA ATGGGACAGT
  195. GACTTCGGAA TTCCCGGTGC ATTTTACATT AAGAACTTCA TGCAAGTTGA
  196. GTTCTATCTC AAGTCTCTAA CTCTCGAAGA CATTCCAAAC CACGGAACCA
  197. TTCACTTCGT ATGCAACTCC TGGGTTTACA ACTCAAAATC CTACCATTCT
  198. GATCGCATTT TCTTTGCCAA CAATGTAAGC TACTTAAATA CTGTTATACA
  199. TTGTCTAACA TCTTGTTAGA GTCTTGCATG ATGTGTACCG TTTATTGTTG
  200. TTGTTGAACT TTACCACATG GCATGGATGC AAAAGTTGTT ATACACATAA
  201. ATTATAATGC AGACATATCT TCCAAGCGAG ACACCGGCTC CACTTGTCAA
  202. GTACAGAGAA GAAGAATTGA AGAATGTAAG AGGGGATGGA ACTGGTGAGC
  203. GCAAGGAATG GGATAGGATC TATGATTATG ATGTCTACAA TGACTTGGGC
  204. GATCCAGATA AGGGTGAAAA GTATGCACGC CCCGTTCTTG GAGGTTCTGC
  205. CTTACCTTAC CCTCGCAGAG GAAGAACCGG AAGAGGAAAA ACTAGAAAAG
  206. GTTTCTCACT AGTCACTAAT TTATTACTTT TTAATGTTTG TTTTTAGGCA
  207. TCTTTTCTGA TGAAATGTAT ACTTTTGATG TTTTTTTGTT TTAGCATAAC
  208. TGAATTAGTA AAGTGTGTTG TGTTCCTTAG AAGTTAGAAA AGTACTAAGT
  209. ATAAGGTCTT TGAGTTGTCG TCTTTATCTT AACAGATCCC AACAGTGAGA
  210. AGCCCAGTGA TTTTGTTTAC CTTCCGAGAG ATGAAGCATT TGGTCACTTG
  211. AAGTCATCAG ATTTTCTCGT TTATGGAATC AAATCAGTGG CTCAAGACGT
  212. CTTGCCCGTG TTGACTGATG CGTTTGATGG CAATCTTTTG AGCCTTGAGT
  213. TTGATAACTT TGCTGAAGTG CGCAAACTCT ATGAAGGTGG AGTTACACTA
  214. CCTACAAACT TTCTTAGCAA GATCGCCCCT ATACCAGTGG TCAAGGAAAT
  215. TTTTCGAACT GATGGCGAAC AGTTCCTCAA GTATCCACCA CCTAAAGTGA
  216. TGCAGGGTAT GCTACATATT TTGAATATGT AGAATATTAT CAATATACTC
  217. CTGTTTTTAT TCAACATATT TAATCACATG GATGAATTTT TGAACTGTTA';
  218. }
  219. elseif ($sequence_type == 'protein') {
  220. $default_example_sequence = '>gi|166477|gb|AAA96434.1| resveratrol synthase [Arachis hypogaea]
  221. MVSVSGIRKVQRAEGPATVLAIGTANPPNCIDQSTYADYYFRVTNSEHMTDLKKKFQRICERTQIKNRHM
  222. YLTEEILKENPNMCAYKAPSLDAREDMMIREVPRVGKEAATKAIKEWGQPMSKITHLIFCTTSGVALPGV
  223. DYELIVLLGLDPCVKRYMMYHQGCFAGGTVLRLAKDLAENNKDARVLIVCSENTAVTFRGPSETDMDSLV
  224. GQALFADGAAAIIIGSDPVPEVEKPIFELVSTDQKLVPGSHGAIGGLLREVGLTFYLNKSVPDIISQNIN
  225. DALNKAFDPLGISDYNSIFWIAHPGGRAILDQVEQKVNLKPEKMKATRDVLSNYGNMSSACVFFIMDLMR
  226. KRSLEEGLKTTGEGLDWGVLFGFGPGLTIETVVLRSVAI';
  227. }
  228. else {
  229. $default_example_sequence = '';
  230. }
  231. // If the Show Example checkbox is true then put the example in the textfield
  232. if ($form_state['values']['example_sequence']) {
  233. // Set the value to be the example sequence (either set by the administrator
  234. // or the default set above).
  235. $form['query']['FASTA']['#value'] = variable_get(
  236. 'blast_ui_' . $sequence_type . '_example_sequence',
  237. $default_example_sequence
  238. );
  239. }
  240. // Otherwise we want to remove the already displayed example.
  241. else {
  242. $form['query']['FASTA']['#value'] = '';
  243. }
  244. return $form['query']['FASTA'];
  245. }