blast_ui.module 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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/tripal_blast'] = array(
  102. 'title' => 'Tripal 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. $items['admin/tripal/extension/tripal_blast/blast_ui'] = array(
  110. 'title' => 'BLAST UI',
  111. 'type' => MENU_DEFAULT_LOCAL_TASK,
  112. );
  113. $items['admin/tripal/extension/tripal_blast/help'] = array(
  114. 'title' => 'Help',
  115. 'page callback' => 'theme',
  116. 'page arguments' => array('blast_help'),
  117. 'access arguments' => array('administer tripal'),
  118. 'type' => MENU_LOCAL_TASK,
  119. );
  120. return $items;
  121. }
  122. /**
  123. * Implements hook_theme().
  124. */
  125. function blast_ui_theme() {
  126. $items = array();
  127. $path = drupal_get_path('module', 'blast_ui');
  128. // Displays the BLAST results for each job
  129. $items['show_blast_report'] = array(
  130. 'template' => 'blast_report',
  131. 'path' => "$path/theme",
  132. );
  133. // Displays the BLAST results for each job
  134. $items['blast_report_pending'] = array(
  135. 'template' => 'blast_report_pending',
  136. 'path' => "$path/theme",
  137. );
  138. // Themes the alignments in a BLAST result display
  139. $items['blast_report_alignment_row'] = array(
  140. 'template' => 'blast_report_alignment_row',
  141. 'variables' => array('hsps' => NULL),
  142. 'path' => "$path/theme",
  143. );
  144. // Module Help
  145. $items['blast_help'] = array(
  146. 'template' => 'blast_help',
  147. 'path' => "$path/theme",
  148. );
  149. // Menu Information Pages
  150. // These are only seen if the user has disabled the all-in-one
  151. // or by query type forms.
  152. $items['blast_user_menupage'] = array(
  153. 'template' => 'blast_user_menupage',
  154. 'path' => "$path/theme",
  155. );
  156. $items['blast_nucleotide_user_menupage'] = array(
  157. 'template' => 'blast_nucleotide_user_menupage',
  158. 'path' => "$path/theme",
  159. );
  160. $items['blast_protein_user_menupage'] = array(
  161. 'template' => 'blast_protein_user_menupage',
  162. 'path' => "$path/theme",
  163. );
  164. return $items;
  165. }
  166. /**
  167. * Implements hook_help().
  168. */
  169. function blast_ui_help($path, $arg) {
  170. if ($path == 'admin/help#blast_ui') {
  171. return theme('blast_help');
  172. }
  173. }
  174. /**
  175. * Facilitate presenting the result of the blast search
  176. *
  177. * @param $job_id
  178. * The tripal job_id of the BLAST job previously submitted
  179. *
  180. * @return $result
  181. * Return HTML output of the BLAST results to be displayed to the user
  182. *
  183. */
  184. function show_blast_output($job_id) {
  185. // BLASTs are run as a Tripal job. As such we need to determine whether the current
  186. // BLAST is in the queue, running or complete in order to determine what to show the user
  187. $job = tripal_get_job($job_id);
  188. // 1) Job is in the Queue
  189. if ($job->start_time === NULL AND $job->end_time == NULL) {
  190. return theme('blast_report_pending', array('status_code' => 0, 'status' => 'Pending'));
  191. }
  192. // 2) Job has been Cancelled
  193. elseif ($job->status == 'Cancelled') {
  194. return theme('blast_report_pending', array('status_code' => 999, 'status' => 'Cancelled'));
  195. }
  196. // 3) Job is Complete
  197. elseif ($job->end_time !== NULL) {
  198. // Return the Results :)
  199. return theme('show_blast_report', array('job_id' => $job_id));
  200. }
  201. // 4) Job is in Progress
  202. else {
  203. return theme('blast_report_pending', array('status_code' => 1, 'status' => 'Running'));
  204. }
  205. return '';
  206. }
  207. /**
  208. *
  209. */
  210. function ajax_blast_ui_example_sequence_callback($form, $form_state) {
  211. // First, set a default example sequence in case administrators have not yet
  212. // bothered to set their own.
  213. $sequence_type = $form_state['values']['query_type'];
  214. if ($sequence_type == 'nucleotide') {
  215. $default_example_sequence = '>partial lipoxygenase Glyma15g03040
  216. TTTCGTATGA GATTAAAATG TGTGAAATTT TGTTTGATAG GACATGGGAA
  217. AGGAAAAGTT GGAAAGGCTA CAAATTTAAG AGGACAAGTG TCGTTACCAA
  218. CCTTGGGAGC TGGCGAAGAT GCATACGATG TTCATTTTGA ATGGGACAGT
  219. GACTTCGGAA TTCCCGGTGC ATTTTACATT AAGAACTTCA TGCAAGTTGA
  220. GTTCTATCTC AAGTCTCTAA CTCTCGAAGA CATTCCAAAC CACGGAACCA
  221. TTCACTTCGT ATGCAACTCC TGGGTTTACA ACTCAAAATC CTACCATTCT
  222. GATCGCATTT TCTTTGCCAA CAATGTAAGC TACTTAAATA CTGTTATACA
  223. TTGTCTAACA TCTTGTTAGA GTCTTGCATG ATGTGTACCG TTTATTGTTG
  224. TTGTTGAACT TTACCACATG GCATGGATGC AAAAGTTGTT ATACACATAA
  225. ATTATAATGC AGACATATCT TCCAAGCGAG ACACCGGCTC CACTTGTCAA
  226. GTACAGAGAA GAAGAATTGA AGAATGTAAG AGGGGATGGA ACTGGTGAGC
  227. GCAAGGAATG GGATAGGATC TATGATTATG ATGTCTACAA TGACTTGGGC
  228. GATCCAGATA AGGGTGAAAA GTATGCACGC CCCGTTCTTG GAGGTTCTGC
  229. CTTACCTTAC CCTCGCAGAG GAAGAACCGG AAGAGGAAAA ACTAGAAAAG
  230. GTTTCTCACT AGTCACTAAT TTATTACTTT TTAATGTTTG TTTTTAGGCA
  231. TCTTTTCTGA TGAAATGTAT ACTTTTGATG TTTTTTTGTT TTAGCATAAC
  232. TGAATTAGTA AAGTGTGTTG TGTTCCTTAG AAGTTAGAAA AGTACTAAGT
  233. ATAAGGTCTT TGAGTTGTCG TCTTTATCTT AACAGATCCC AACAGTGAGA
  234. AGCCCAGTGA TTTTGTTTAC CTTCCGAGAG ATGAAGCATT TGGTCACTTG
  235. AAGTCATCAG ATTTTCTCGT TTATGGAATC AAATCAGTGG CTCAAGACGT
  236. CTTGCCCGTG TTGACTGATG CGTTTGATGG CAATCTTTTG AGCCTTGAGT
  237. TTGATAACTT TGCTGAAGTG CGCAAACTCT ATGAAGGTGG AGTTACACTA
  238. CCTACAAACT TTCTTAGCAA GATCGCCCCT ATACCAGTGG TCAAGGAAAT
  239. TTTTCGAACT GATGGCGAAC AGTTCCTCAA GTATCCACCA CCTAAAGTGA
  240. TGCAGGGTAT GCTACATATT TTGAATATGT AGAATATTAT CAATATACTC
  241. CTGTTTTTAT TCAACATATT TAATCACATG GATGAATTTT TGAACTGTTA';
  242. }
  243. elseif ($sequence_type == 'protein') {
  244. $default_example_sequence = '>gi|166477|gb|AAA96434.1| resveratrol synthase [Arachis hypogaea]
  245. MVSVSGIRKVQRAEGPATVLAIGTANPPNCIDQSTYADYYFRVTNSEHMTDLKKKFQRICERTQIKNRHM
  246. YLTEEILKENPNMCAYKAPSLDAREDMMIREVPRVGKEAATKAIKEWGQPMSKITHLIFCTTSGVALPGV
  247. DYELIVLLGLDPCVKRYMMYHQGCFAGGTVLRLAKDLAENNKDARVLIVCSENTAVTFRGPSETDMDSLV
  248. GQALFADGAAAIIIGSDPVPEVEKPIFELVSTDQKLVPGSHGAIGGLLREVGLTFYLNKSVPDIISQNIN
  249. DALNKAFDPLGISDYNSIFWIAHPGGRAILDQVEQKVNLKPEKMKATRDVLSNYGNMSSACVFFIMDLMR
  250. KRSLEEGLKTTGEGLDWGVLFGFGPGLTIETVVLRSVAI';
  251. }
  252. else {
  253. $default_example_sequence = '';
  254. }
  255. // If the Show Example checkbox is true then put the example in the textfield
  256. if ($form_state['values']['example_sequence']) {
  257. // Set the value to be the example sequence (either set by the administrator
  258. // or the default set above).
  259. $form['query']['FASTA']['#value'] = variable_get(
  260. 'blast_ui_' . $sequence_type . '_example_sequence',
  261. $default_example_sequence
  262. );
  263. }
  264. // Otherwise we want to remove the already displayed example.
  265. else {
  266. $form['query']['FASTA']['#value'] = '';
  267. }
  268. return $form['query']['FASTA'];
  269. }