blast_ui.module 6.7 KB

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