blast_ui.module 9.9 KB

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