blast_ui.module 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. return $items;
  126. }
  127. /**
  128. * Facilitate presenting the result of the blast search
  129. *
  130. * @param $job_id
  131. * The tripal job_id of the BLAST job previously submitted
  132. *
  133. * @return $result
  134. * Return HTML output of the BLAST results to be displayed to the user
  135. *
  136. */
  137. function show_blast_output($job_id) {
  138. // BLASTs are run as a Tripal job. As such we need to determine whether the current
  139. // BLAST is in the queue, running or complete in order to determine what to show the user
  140. $job = tripal_get_job($job_id);
  141. // 1) Job is in the Queue
  142. if ($job->start_time === NULL AND $job->end_time == NULL) {
  143. return theme('blast_report_pending', array('status_code' => 0, 'status' => 'Pending'));
  144. }
  145. // 2) Job has been Cancelled
  146. elseif ($job->status == 'Cancelled') {
  147. return theme('blast_report_pending', array('status_code' => 999, 'status' => 'Cancelled'));
  148. }
  149. // 3) Job is Complete
  150. elseif ($job->end_time !== NULL) {
  151. // Return the Results :)
  152. return theme('show_blast_report', array('job_id' => $job_id));
  153. }
  154. // 4) Job is in Progress
  155. else {
  156. return theme('blast_report_pending', array('status_code' => 1, 'status' => 'Running'));
  157. }
  158. return '';
  159. }
  160. /**
  161. *
  162. */
  163. function ajax_blast_ui_example_sequence_callback($form, $form_state) {
  164. // First, set a default example sequence in case administrators have not yet
  165. // bothered to set their own.
  166. $sequence_type = $form_state['values']['query_type'];
  167. if ($sequence_type == 'nucleotide') {
  168. $default_example_sequence = '>partial lipoxygenase Glyma15g03040
  169. TTTCGTATGA GATTAAAATG TGTGAAATTT TGTTTGATAG GACATGGGAA
  170. AGGAAAAGTT GGAAAGGCTA CAAATTTAAG AGGACAAGTG TCGTTACCAA
  171. CCTTGGGAGC TGGCGAAGAT GCATACGATG TTCATTTTGA ATGGGACAGT
  172. GACTTCGGAA TTCCCGGTGC ATTTTACATT AAGAACTTCA TGCAAGTTGA
  173. GTTCTATCTC AAGTCTCTAA CTCTCGAAGA CATTCCAAAC CACGGAACCA
  174. TTCACTTCGT ATGCAACTCC TGGGTTTACA ACTCAAAATC CTACCATTCT
  175. GATCGCATTT TCTTTGCCAA CAATGTAAGC TACTTAAATA CTGTTATACA
  176. TTGTCTAACA TCTTGTTAGA GTCTTGCATG ATGTGTACCG TTTATTGTTG
  177. TTGTTGAACT TTACCACATG GCATGGATGC AAAAGTTGTT ATACACATAA
  178. ATTATAATGC AGACATATCT TCCAAGCGAG ACACCGGCTC CACTTGTCAA
  179. GTACAGAGAA GAAGAATTGA AGAATGTAAG AGGGGATGGA ACTGGTGAGC
  180. GCAAGGAATG GGATAGGATC TATGATTATG ATGTCTACAA TGACTTGGGC
  181. GATCCAGATA AGGGTGAAAA GTATGCACGC CCCGTTCTTG GAGGTTCTGC
  182. CTTACCTTAC CCTCGCAGAG GAAGAACCGG AAGAGGAAAA ACTAGAAAAG
  183. GTTTCTCACT AGTCACTAAT TTATTACTTT TTAATGTTTG TTTTTAGGCA
  184. TCTTTTCTGA TGAAATGTAT ACTTTTGATG TTTTTTTGTT TTAGCATAAC
  185. TGAATTAGTA AAGTGTGTTG TGTTCCTTAG AAGTTAGAAA AGTACTAAGT
  186. ATAAGGTCTT TGAGTTGTCG TCTTTATCTT AACAGATCCC AACAGTGAGA
  187. AGCCCAGTGA TTTTGTTTAC CTTCCGAGAG ATGAAGCATT TGGTCACTTG
  188. AAGTCATCAG ATTTTCTCGT TTATGGAATC AAATCAGTGG CTCAAGACGT
  189. CTTGCCCGTG TTGACTGATG CGTTTGATGG CAATCTTTTG AGCCTTGAGT
  190. TTGATAACTT TGCTGAAGTG CGCAAACTCT ATGAAGGTGG AGTTACACTA
  191. CCTACAAACT TTCTTAGCAA GATCGCCCCT ATACCAGTGG TCAAGGAAAT
  192. TTTTCGAACT GATGGCGAAC AGTTCCTCAA GTATCCACCA CCTAAAGTGA
  193. TGCAGGGTAT GCTACATATT TTGAATATGT AGAATATTAT CAATATACTC
  194. CTGTTTTTAT TCAACATATT TAATCACATG GATGAATTTT TGAACTGTTA';
  195. }
  196. elseif ($sequence_type == 'protein') {
  197. $default_example_sequence = '>gi|166477|gb|AAA96434.1| resveratrol synthase [Arachis hypogaea]
  198. MVSVSGIRKVQRAEGPATVLAIGTANPPNCIDQSTYADYYFRVTNSEHMTDLKKKFQRICERTQIKNRHM
  199. YLTEEILKENPNMCAYKAPSLDAREDMMIREVPRVGKEAATKAIKEWGQPMSKITHLIFCTTSGVALPGV
  200. DYELIVLLGLDPCVKRYMMYHQGCFAGGTVLRLAKDLAENNKDARVLIVCSENTAVTFRGPSETDMDSLV
  201. GQALFADGAAAIIIGSDPVPEVEKPIFELVSTDQKLVPGSHGAIGGLLREVGLTFYLNKSVPDIISQNIN
  202. DALNKAFDPLGISDYNSIFWIAHPGGRAILDQVEQKVNLKPEKMKATRDVLSNYGNMSSACVFFIMDLMR
  203. KRSLEEGLKTTGEGLDWGVLFGFGPGLTIETVVLRSVAI';
  204. }
  205. else {
  206. $default_example_sequence = '';
  207. }
  208. // If the Show Example checkbox is true then put the example in the textfield
  209. if ($form_state['values']['example_sequence']) {
  210. // Set the value to be the example sequence (either set by the administrator
  211. // or the default set above).
  212. $form['query']['FASTA']['#value'] = variable_get(
  213. 'blast_ui_' . $sequence_type . '_example_sequence',
  214. $default_example_sequence
  215. );
  216. }
  217. // Otherwise we want to remove the already displayed example.
  218. else {
  219. $form['query']['FASTA']['#value'] = '';
  220. }
  221. return $form['query']['FASTA'];
  222. }