blast_ui.module 8.9 KB

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