blast_ui.module 6.8 KB

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