blast_ui.admin.inc 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <?php
  2. /**
  3. * @file
  4. * Administrative interface for the BLAST UI
  5. */
  6. /**
  7. *
  8. */
  9. function blast_ui_admin_form($form, $form_state) {
  10. $form['general'] = array(
  11. '#type' => 'fieldset',
  12. '#title' => 'General'
  13. );
  14. $form['general']['blast_path']= array(
  15. '#type' => 'textfield',
  16. '#title' => t('Enter the path of the BLAST program'),
  17. '#description' => t('You can ignore if your $PATH variable is set. Otherwise, enter the absoulte path to bin folder. For example, /opt/blast/2.2.29+/bin/'),
  18. '#default_value' => variable_get('blast_path', ''),
  19. );
  20. $form['general']['blast_threads']= array(
  21. '#type' => 'textfield',
  22. '#title' => t('Enter the number of CPU threads to use in blast search.'),
  23. '#description' => t('You can increase the number to reduce the search time. Before you increase, please check your hardware configurations . A value of one(1) can result in a slower search for some programs eg. tblastn.'),
  24. '#default_value' => variable_get('blast_threads', 1),
  25. );
  26. $form['general']['eVal']= array(
  27. '#type' => 'textfield',
  28. '#title' => t('Default e-value (Expected Threshold)'),
  29. '#description' => t('Expected number of chance matches in a random model. This number should be give in a decimal format.'),
  30. '#default_value' => variable_get('eVal', 0.001),
  31. //'#default_value' => variable_get('blast_threads', 1),
  32. );
  33. $form['general']['qRange']= array(
  34. '#type' => 'textfield',
  35. '#title' => t('Default max matches in a query range'),
  36. '#description' => t('Limit the number of matches to a query range. This option is useful if many strong matches to one part of a query may prevent BLAST from presenting weaker matches to another part of the query.'),
  37. '#default_value' => variable_get('qRange', 0),
  38. );
  39. $form['file_upload'] = array(
  40. '#type' => 'fieldset',
  41. '#collapsible' => true,
  42. '#collapsed' => true,
  43. '#title' => 'Allow File Upload',
  44. '#description' => 'The following options allow you to control whether your users can
  45. upload files for the query or target respectively. The ability to upload files allows
  46. them to more conviently BLAST large sets of sequences. However, the size of the
  47. files could be problematic, storage-wise, on your server.<br />'
  48. );
  49. $form['file_upload']['query_upload'] = array(
  50. '#type' => 'checkbox',
  51. '#title' => 'Enable Query Sequence Upload',
  52. '#description' => 'When checked, a query file upload field will be available on BLAST request forms.',
  53. '#default_value' => FALSE,
  54. '#default_value' => variable_get('blast_ui_allow_query_upload', TRUE)
  55. );
  56. $form['file_upload']['target_upload'] = array(
  57. '#type' => 'checkbox',
  58. '#title' => 'Enable Target Sequence Upload',
  59. '#description' => 'When checked, a target file upload field will be available on BLAST request forms.',
  60. '#default_value' => FALSE,
  61. '#default_value' => variable_get('blast_ui_allow_target_upload', FALSE)
  62. );
  63. $form['example_sequence'] = array(
  64. '#type' => 'fieldset',
  65. '#collapsible' => true,
  66. '#collapsed' => true,
  67. '#title' => 'Set Example Sequences',
  68. '#description' => 'There is the ability to show example sequences built-in to the various BLAST forms. Use the following fields to set these example sequences. This allows you to provide more relevant examples to your users.'
  69. );
  70. $nucleotide_default = '>partial lipoxygenase Glyma15g03040
  71. TTTCGTATGA GATTAAAATG TGTGAAATTT TGTTTGATAG GACATGGGAA
  72. AGGAAAAGTT GGAAAGGCTA CAAATTTAAG AGGACAAGTG TCGTTACCAA
  73. CCTTGGGAGC TGGCGAAGAT GCATACGATG TTCATTTTGA ATGGGACAGT
  74. GACTTCGGAA TTCCCGGTGC ATTTTACATT AAGAACTTCA TGCAAGTTGA
  75. GTTCTATCTC AAGTCTCTAA CTCTCGAAGA CATTCCAAAC CACGGAACCA
  76. TTCACTTCGT ATGCAACTCC TGGGTTTACA ACTCAAAATC CTACCATTCT
  77. GATCGCATTT TCTTTGCCAA CAATGTAAGC TACTTAAATA CTGTTATACA
  78. TTGTCTAACA TCTTGTTAGA GTCTTGCATG ATGTGTACCG TTTATTGTTG
  79. TTGTTGAACT TTACCACATG GCATGGATGC AAAAGTTGTT ATACACATAA
  80. ATTATAATGC AGACATATCT TCCAAGCGAG ACACCGGCTC CACTTGTCAA
  81. GTACAGAGAA GAAGAATTGA AGAATGTAAG AGGGGATGGA ACTGGTGAGC
  82. GCAAGGAATG GGATAGGATC TATGATTATG ATGTCTACAA TGACTTGGGC
  83. GATCCAGATA AGGGTGAAAA GTATGCACGC CCCGTTCTTG GAGGTTCTGC
  84. CTTACCTTAC CCTCGCAGAG GAAGAACCGG AAGAGGAAAA ACTAGAAAAG
  85. GTTTCTCACT AGTCACTAAT TTATTACTTT TTAATGTTTG TTTTTAGGCA
  86. TCTTTTCTGA TGAAATGTAT ACTTTTGATG TTTTTTTGTT TTAGCATAAC
  87. TGAATTAGTA AAGTGTGTTG TGTTCCTTAG AAGTTAGAAA AGTACTAAGT
  88. ATAAGGTCTT TGAGTTGTCG TCTTTATCTT AACAGATCCC AACAGTGAGA
  89. AGCCCAGTGA TTTTGTTTAC CTTCCGAGAG ATGAAGCATT TGGTCACTTG
  90. AAGTCATCAG ATTTTCTCGT TTATGGAATC AAATCAGTGG CTCAAGACGT
  91. CTTGCCCGTG TTGACTGATG CGTTTGATGG CAATCTTTTG AGCCTTGAGT
  92. TTGATAACTT TGCTGAAGTG CGCAAACTCT ATGAAGGTGG AGTTACACTA
  93. CCTACAAACT TTCTTAGCAA GATCGCCCCT ATACCAGTGG TCAAGGAAAT
  94. TTTTCGAACT GATGGCGAAC AGTTCCTCAA GTATCCACCA CCTAAAGTGA
  95. TGCAGGGTAT GCTACATATT TTGAATATGT AGAATATTAT CAATATACTC
  96. CTGTTTTTAT TCAACATATT TAATCACATG GATGAATTTT TGAACTGTTA';
  97. $form['example_sequence']['nucleotide_example'] = array(
  98. '#type' => 'textarea',
  99. '#title' => 'Nucleotide Example',
  100. '#description' => t('Enter a complete nucleotide FASTA record including the header. More information: <a href="@fasta-format-url" target="_blank">FASTA format</a>.',
  101. array('@fasta-format-url' => 'https://www.ncbi.nlm.nih.gov/BLAST/blastcgihelp.shtml')),
  102. '#default_value' => variable_get(
  103. 'blast_ui_nucleotide_example_sequence',
  104. $nucleotide_default
  105. )
  106. );
  107. $protein_default = '>gi|166477|gb|AAA96434.1| resveratrol synthase [Arachis hypogaea]
  108. MVSVSGIRKVQRAEGPATVLAIGTANPPNCIDQSTYADYYFRVTNSEHMTDLKKKFQRICERTQIKNRHM
  109. YLTEEILKENPNMCAYKAPSLDAREDMMIREVPRVGKEAATKAIKEWGQPMSKITHLIFCTTSGVALPGV
  110. DYELIVLLGLDPCVKRYMMYHQGCFAGGTVLRLAKDLAENNKDARVLIVCSENTAVTFRGPSETDMDSLV
  111. GQALFADGAAAIIIGSDPVPEVEKPIFELVSTDQKLVPGSHGAIGGLLREVGLTFYLNKSVPDIISQNIN
  112. DALNKAFDPLGISDYNSIFWIAHPGGRAILDQVEQKVNLKPEKMKATRDVLSNYGNMSSACVFFIMDLMR
  113. KRSLEEGLKTTGEGLDWGVLFGFGPGLTIETVVLRSVAI';
  114. $form['example_sequence']['protein_example'] = array(
  115. '#type' => 'textarea',
  116. '#title' => 'Protein Example',
  117. '#description' => t('Enter a complete protein FASTA record including the header. More information: <a href="@fasta-format-url" target="_blank">FASTA format</a>.',
  118. array('@fasta-format-url' => 'https://www.ncbi.nlm.nih.gov/BLAST/blastcgihelp.shtml')),
  119. '#default_value' => variable_get(
  120. 'blast_ui_protein_example_sequence',
  121. $protein_default
  122. )
  123. );
  124. // PROTECTION
  125. $form['protection'] = array(
  126. '#type' => 'fieldset',
  127. '#collapsible' => true,
  128. '#collapsed' => true,
  129. '#title' => 'Protect against large jobs',
  130. '#description' => 'Depending on the size and nature of your target databases, you may wish to constrain use of this module.',
  131. );
  132. $form['protection']['max_results_displayed'] = array(
  133. '#type' => 'textfield',
  134. '#title' => 'Maximum number of results to show on report page',
  135. '#description' => 'If there are more hits that this, the user is able to download but not visualize the results.',
  136. '#default_value' => variable_get('blast_ui_max_results_displayed', 500)
  137. );
  138. // CVITJS
  139. $cvitjs_enabled = variable_get('blast_ui_cvitjs_enabled', FALSE);
  140. $description = 'The JavaScript program CViTjs enables users to see BLAST hits on an '
  141. . 'entire genome assembly. See the help tab for information on how to '
  142. . 'download and set up CViTjs.';
  143. $form['cvitjs'] = array(
  144. '#type' => 'fieldset',
  145. '#collapsible' => true,
  146. '#collapsed' => !$cvitjs_enabled,
  147. '#title' => 'Enable and configure genome visualization',
  148. '#description' => $description,
  149. );
  150. $absolute_cvitjs_data_path = DRUPAL_ROOT . '/sites/all/libraries/cvitjs/data';
  151. $description = '<div class ="messages warning">CViTjs is only applicable for genome BLAST targets. After it is '
  152. . 'enabled here, CViTjs will need to be enabled for each applicable BLAST '
  153. . 'target node.</div>'
  154. . '<div class="messages status"><strong>CViTjs Data Location: '.$absolute_cvitjs_data_path.'</strong>'
  155. . '<br />The GFF3 and Genome Target-specific CViTjs configuration files should be located '
  156. . 'at the above system path. Feel free to organize this directory further. '
  157. . 'See the "Help" tab for more information.</div>';
  158. $form['cvitjs']['explanation'] = array(
  159. '#markup' => t($description),
  160. );
  161. $form['cvitjs']['cvitjs_enabled'] = array(
  162. '#type' => 'checkbox',
  163. '#title' => 'Enable CViTjs',
  164. '#description' => 'When checked, CViTjs will be enabled.',
  165. '#default_value' => $cvitjs_enabled,
  166. );
  167. // Get CViTjs confuration text, if possible.
  168. if (!$default_value = blast_ui_get_cvit_conf_text()) {
  169. $default_value = 'Unable to get CViTjs configuration information. '
  170. . 'You will need to enable CViTjs and set and save the '
  171. . 'path to CViTjs before you can edit the CViTjs configuration text.';
  172. $disabled = true;
  173. }
  174. else {
  175. $disabled = false;
  176. }
  177. $description = 'This is the contents of the file that defines data directories and '
  178. . 'backbone GFF files for each genome assembly target. It is named '
  179. . 'cvit.conf and is in the root directory for the CViTjs javascript code. '
  180. . 'This is NOT the config file that is used to build the display for each '
  181. . 'individual genome. See the help tab for more information about '
  182. . 'configuration files.';
  183. $form['cvitjs']['cvitjs_config'] = array(
  184. '#type' => 'textarea',
  185. '#title' => 'CViTjs configuration',
  186. '#description' => $description,
  187. '#default_value' => $default_value,
  188. '#rows' => 10,
  189. '#disabled' => $disabled,
  190. );
  191. //eksc:
  192. // WARNING
  193. $description = 'This permits display of a temporary warning message at the top of the
  194. BLAST input form. Text can include HTML tags. Remember to remove the
  195. message when it is no longer relevant.';
  196. $form['warning'] = array(
  197. '#type' => 'fieldset',
  198. '#collapsible' => true,
  199. '#collapsed' => true,
  200. '#title' => 'Show warning text',
  201. '#description' => $description,
  202. );
  203. $form['warning']['warning_text'] = array(
  204. '#type' => 'textarea',
  205. '#title' => 'Text to be displayed',
  206. '#description' => $description,
  207. '#default_value' => variable_get('blast_ui_warning_text', ''),
  208. '#rows' => 10,
  209. );
  210. // SUBMIT
  211. $form['submit'] = array(
  212. '#type' => 'submit',
  213. '#value' => 'Save Configuration'
  214. );
  215. return $form;
  216. }
  217. /**
  218. * Validate the Admin/Settings form.
  219. */
  220. function blast_ui_admin_form_validate($form, &$form_state) {
  221. // Check path to BLAST executables
  222. $blast_path = $form_state['values']['blast_path'];
  223. $blast_path .= 'blastn';
  224. if(!empty($form_state['values']['blast_path'])) {
  225. if(file_exists($blast_path) ) {
  226. variable_set('blast_path', $form_state['values']['blast_path']);
  227. }
  228. else {
  229. form_set_error('blast_path', t('Please enter a valid path not including the name of the blast program (ie: /usr/bin/). You can leave this blank if you have your $PATH variable set appropriately.'));
  230. }
  231. }
  232. // Check path to CViTjs executable and make sure cvit.conf is writable
  233. if ($form_state['values']['cvitjs_enabled']) {
  234. $cvit_path = blast_ui_get_cvit_conf();
  235. if (!$cvit_path || !file_exists($cvit_path)) {
  236. $msg = "The CViTjs configuration file, cvit.conf, does not exist at the path given ("
  237. . $form_state['values']['cvitjs_location']
  238. . "). Please check your path. "
  239. . "If you have not yet downloaded CViTjs, see the help tab for more information.";
  240. form_set_error('cvitjs_location', t($msg));
  241. }
  242. if (!is_writable($cvit_path)) {
  243. $msg = "The file $cvit_path is not writable by this page. "
  244. . "Please enable write access for apache then try saving these settings again.";
  245. form_set_error('cvitjs_location', t($msg));
  246. }
  247. }
  248. // Empty contents of cvitjs_config textarea if it is disabled
  249. if ($form['cvitjs']['cvitjs_config']['#disabled']) {
  250. $form_state['values']['cvitjs_config'] = '';
  251. }
  252. // Check CViTjs configuration text
  253. if ($form_state['values']['cvitjs_config']
  254. && !preg_match('/\[general\]\s*\ndata_default =.*/m',
  255. $form_state['values']['cvitjs_config'])) {
  256. $msg = "The CViTjs configuration text looks incorrect. "
  257. . "It should contain a [general] section. "
  258. . "See the help tab for more information.";
  259. form_set_error('cvitjs_config', t($msg));
  260. }
  261. if ($form_state['values']['cvitjs_config']
  262. && !preg_match('/\[.*\]\s*\nconf = .*\ndefaultData =.*/m',
  263. $form_state['values']['cvitjs_config'])) {
  264. $msg = "The CViTjs configuration text looks incorrect. "
  265. . "It should contain one section for each genome target. "
  266. . "See the help tab for more information.";
  267. form_set_error('cvitjs_config', t($msg));
  268. }
  269. }
  270. /**
  271. * Submit the Admin/settings form.
  272. */
  273. function blast_ui_admin_form_submit($form, $form_state) {
  274. //General
  275. variable_set('blast_path', $form_state['values']['blast_path']);
  276. variable_set('blast_threads', $form_state['values']['blast_threads']);
  277. variable_set('eVal', $form_state['values']['eVal']);
  278. variable_set('qRange', $form_state['values']['qRange']);
  279. // Uploads
  280. variable_set('blast_ui_allow_query_upload', $form_state['values']['query_upload']);
  281. variable_set('blast_ui_allow_target_upload', $form_state['values']['target_upload']);
  282. // Example sequence
  283. variable_set('blast_ui_nucleotide_example_sequence', $form_state['values']['nucleotide_example']);
  284. variable_set('blast_ui_protein_example_sequence', $form_state['values']['protein_example']);
  285. // Protect against large result sets
  286. variable_set('blast_ui_max_results_displayed', $form_state['values']['max_results_displayed']);
  287. // Whole genome visualization - CViTjs
  288. variable_set('blast_ui_cvitjs_enabled', $form_state['values']['cvitjs_enabled']);
  289. if ($form_state['values']['cvitjs_enabled'] && $form_state['values']['cvitjs_config']) {
  290. // Need absolute path to conf file to write
  291. $cvit_conf_path = getcwd() . DIRECTORY_SEPARATOR
  292. . blast_ui_get_cvit_conf($form_state['values']['cvitjs_location']);
  293. if ($fh = fopen($cvit_conf_path, 'w')) {
  294. fwrite($fh, $form_state['values']['cvitjs_config']);
  295. fclose($fh);
  296. }
  297. else {
  298. drupal_set_message("Unable to open CViTjs conf file for writing: <pre>" . print_r(error_get_last(),true) . "</pre>");
  299. }
  300. }
  301. //eksc:
  302. // Warning text
  303. variable_set('blast_ui_warning_text', $form_state['values']['warning_text']);
  304. }