blast_ui.form_per_program.inc 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. <?php
  2. /**
  3. * @file
  4. * Forms in the file provide a per BLAST program interface to submitting BLASTs.
  5. *
  6. * In other words, it provides a form for blastn, one for blastp, etc. It does
  7. * this using a single form function for code reusability and depending upon
  8. * the $type passed in, it will execute additional hooks allowing for program
  9. * specific modifications & advanced options.
  10. */
  11. /**
  12. * This single form definition provides 4 different program-specific forms.
  13. */
  14. function blast_ui_per_blast_program_form($form, $form_state) {
  15. // Add a warning, if need be (to be used for temporary messages like down-for-maintanence)
  16. $form['warning'] = array(
  17. '#markup' => t(''),
  18. );
  19. // CSS support to the form
  20. $form['#attached']['css'] = array(
  21. drupal_get_path('module', 'blast_ui') . '/theme/css/form.css',
  22. );
  23. // We are going to lay out this form as two choices: either look at a recent blast
  24. // or execute a new one. We want to theme accordingly so set a class to aid us in such.
  25. $form['#attributes'] = array('class' => array('blast-choice-form'));
  26. // Determine some defaults.
  27. $defaults = array(
  28. 'FASTA' => NULL,
  29. 'SELECT_DB' => NULL,
  30. );
  31. // Edit and Resubmit functionality.
  32. // We want to pull up the details from a previous blast and fill them in as defaults
  33. // for this blast.
  34. // @todo: handle file uploads better; currently for the query we put the file contents
  35. // in the text area causing reupload and we simply do not support re-using of an uploaded target.
  36. if (isset($_GET['resubmit'])) {
  37. $prev_blast = get_BLAST_job(blast_ui_reveal_secret($_GET['resubmit']));
  38. // First of all warn if the uploaded their search target last time
  39. // since we don't support that now.
  40. if (!isset($prev_blast->blastdb->nid)) {
  41. drupal_set_message('You will need to re-upload your <em>Search Target</em> database.','warning');
  42. }
  43. // And if they didn't upload a target then set a default for the select list.
  44. else {
  45. $defaults['SELECT_DB'] = $prev_blast->blastdb->nid;
  46. }
  47. // Finally set a default for the query. Since we don't support defaults for file uploads,
  48. // we need to get the contents of the file and put them in our textarea.
  49. if (is_readable($prev_blast->files->query)) {
  50. $defaults['FASTA'] = file_get_contents($prev_blast->files->query);
  51. }
  52. // There should always be a query file (both if uploaded or not) so if we cant find it
  53. // then it must have been cleaned up :-( -- warn the user.
  54. else {
  55. drupal_set_message('Unable to retrieve previous query sequence; please re-upload it.', 'error');
  56. }
  57. // Finally save the previous blast details for use by the advanced option forms.
  58. $form_state['prev_blast'] = $prev_blast;
  59. }
  60. // Determine the BLAST program.
  61. $query_type = $form_state['build_info']['args'][0];
  62. $db_type = $form_state['build_info']['args'][1];
  63. if ($query_type == 'nucleotide') {
  64. if ($db_type == 'nucleotide') {
  65. $blast_program = 'blastn';
  66. }
  67. elseif ($db_type == 'protein') {
  68. $blast_program = 'blastx';
  69. }
  70. }
  71. elseif ($query_type == 'protein') {
  72. if ($db_type == 'nucleotide') {
  73. $blast_program = 'tblastn';
  74. }
  75. elseif ($db_type == 'protein') {
  76. $blast_program = 'blastp';
  77. }
  78. }
  79. // Set the title to be more Researcher friendly.
  80. drupal_set_title(t(
  81. '@query to @db BLAST (@program)',
  82. array(
  83. '@query' => ucfirst($query_type),
  84. '@db' => ucfirst($db_type),
  85. '@program' => $blast_program
  86. )
  87. ));
  88. // Add the details about the specific BLAST choosen.
  89. $form['query_type'] = array(
  90. '#type' => 'hidden',
  91. '#value' => $query_type
  92. );
  93. $form['db_type'] = array(
  94. '#type' => 'hidden',
  95. '#value' => $db_type
  96. );
  97. $form['blast_program'] = array(
  98. '#type' => 'hidden',
  99. '#value' => $blast_program
  100. );
  101. // CHOOSE RECENT BLAST RESULTS
  102. //-----------------------------------
  103. // If there are recent jobs then show a table of them.
  104. if (get_number_of_recent_jobs()) {
  105. $form['A'] = array(
  106. '#type' => 'fieldset',
  107. '#title' => 'See Results from a Recent BLAST',
  108. '#attributes' => array('class' => array('blast-choice')),
  109. '#collapsible' => TRUE,
  110. '#collapsed' => TRUE
  111. );
  112. $form['A']['job_table'] = array(
  113. '#type' => 'markup',
  114. '#markup' => theme('blast_recent_jobs', array($blast_program)),
  115. );
  116. }
  117. // REQUEST A NEW BLAST
  118. //-----------------------------------
  119. $form['B'] = array(
  120. '#type' => 'fieldset',
  121. '#title' => 'Request a New BLAST',
  122. '#attributes' => array('class' => array('blast-choice')),
  123. '#collapsible' => TRUE,
  124. );
  125. // NUCLEOTIDE QUERY
  126. //.........................
  127. $form['B']['query'] = array(
  128. '#type' => 'fieldset',
  129. '#title' => t('Enter %type Query Sequence',
  130. array('%type' => ucfirst($query_type))),
  131. '#description' => t('Enter one or more queries in the top text box or use '
  132. . 'the browse button to upload a file from your local disk. The file may '
  133. . 'contain a single sequence or a list of sequences. In both cases, the '
  134. . 'data must be in <a href="@formaturl" target="_blank">FASTA format</a>.',
  135. array(
  136. '@formaturl' => 'http://www.ncbi.nlm.nih.gov/BLAST/blastcgihelp.shtml'
  137. )
  138. ),
  139. '#collapsible' => TRUE,
  140. '#collapsed' => FALSE,
  141. );
  142. // Checkbox to show an example.
  143. $form['B']['query']['example_sequence'] = array(
  144. '#type' => 'checkbox',
  145. '#title' => t('Show an Example Sequence'),
  146. '#prefix' => '<span style="float: right;">',
  147. '#suffix' => '</span>',
  148. '#ajax' => array(
  149. 'callback' => 'ajax_blast_ui_perprogram_example_sequence_callback',
  150. 'wrapper' => 'fasta-textarea',
  151. 'method' => 'replace',
  152. 'effect' => 'fade',
  153. ),
  154. );
  155. // Textfield for submitting a mult-FASTA query
  156. $form['B']['query']['FASTA'] = array(
  157. '#type' => 'textarea',
  158. '#title' => t('Enter FASTA sequence(s)'),
  159. '#description'=>t('Enter query sequence(s) in the text area.'),
  160. '#default_value' => $defaults['FASTA'],
  161. '#prefix' => '<div id="fasta-textarea">',
  162. '#suffix' => '</div>',
  163. );
  164. if (variable_get('blast_ui_allow_query_upload', TRUE)) {
  165. // Upload a file as an alternative to enter a query sequence
  166. $form['#attributes']['enctype'] = 'multipart/form-data';
  167. $form['B']['query']['UPLOAD'] = array(
  168. '#title' => 'Or upload your own query FASTA: ',
  169. '#type' => 'managed_file',
  170. '#description' => t('The file should be a plain-text FASTA
  171. (.fasta, .fna, .fa, .fas) file. In other words, it cannot have formatting as is the
  172. case with MS Word (.doc, .docx) or Rich Text Format (.rtf). It cannot be greater
  173. than %max_size in size. <strong>Don\'t forget to press the Upload button before
  174. attempting to submit your BLAST.</strong>',
  175. array(
  176. '%max_size' => round(file_upload_max_size() / 1024 / 1024,1) . 'MB'
  177. )
  178. ),
  179. '#upload_validators' => array(
  180. 'file_validate_extensions' => array('fasta fna fa fas'),
  181. 'file_validate_size' => array(file_upload_max_size()),
  182. ),
  183. );
  184. }
  185. // BLAST DATABASE
  186. //.........................
  187. $target_upload_text = '';
  188. if (variable_get('blast_ui_allow_target_upload', FALSE)) {
  189. $target_upload_text = 'You can also use the browse button to upload a '
  190. . 'file from your local disk. The file may contain '
  191. . 'a single sequence or a list of sequences. ';
  192. }
  193. $form['B']['DB'] = array(
  194. '#type' => 'fieldset',
  195. '#title' => t('Choose Search Target'),
  196. '#description' => t('Choose from one of the %type BLAST databases listed '
  197. . 'below. ' . $target_upload_text,
  198. array('%type' => $db_type)),
  199. '#collapsible' => TRUE,
  200. '#collapsed' => FALSE,
  201. );
  202. $options = get_blast_database_options($db_type);
  203. $form['B']['DB']['SELECT_DB'] = array(
  204. '#type' => 'select',
  205. '#title' => t('%type BLAST Databases:', array('%type' => ucfirst($db_type))),
  206. '#options' => $options,
  207. '#empty_option' => t('Select a Dataset'),
  208. '#default_value' => $defaults['SELECT_DB'],
  209. );
  210. if (variable_get('blast_ui_allow_target_upload', FALSE)) {
  211. // Upload a file as an alternative to selecting an existing BLAST database
  212. $form['#attributes']['enctype'] = 'multipart/form-data';
  213. $form['B']['DB']['DBUPLOAD'] = array(
  214. '#title' => 'Or upload your own dataset: ',
  215. '#type' => 'managed_file',
  216. '#description' => t('The file should be a plain-text FASTA
  217. (.fasta, .fna, .fa) file. In other words, it cannot have formatting as is the
  218. case with MS Word (.doc, .docx) or Rich Text Format (.rtf). It cannot be greater
  219. than %max_size in size. <strong>Don\'t forget to press the Upload button before
  220. attempting to submit your BLAST.</strong>',
  221. array(
  222. '%max_size' => round(file_upload_max_size() / 1024 / 1024,1) . 'MB'
  223. )
  224. ),
  225. '#default_value' => variable_get($db_file_id, ''),
  226. '#upload_validators' => array(
  227. 'file_validate_extensions' => array('fasta fna fa'),
  228. 'file_validate_size' => array(file_upload_max_size()),
  229. ),
  230. );
  231. }
  232. // Advanced Options
  233. //.........................
  234. // These options will be different depending upon the program selected.
  235. // Therefore, allow for program-specific callbacks to populate these options.
  236. $form['B']['ALG'] = array(
  237. '#type' => 'fieldset',
  238. '#title' => t('Advanced Options'),
  239. '#collapsible' => TRUE,
  240. '#collapsed' => TRUE,
  241. );
  242. $advanced_options_form = 'blast_ui_' . $blast_program . '_advanced_options_form';
  243. if (function_exists($advanced_options_form)) {
  244. call_user_func_array($advanced_options_form, array(&$form, $form_state));
  245. }
  246. $form['B']['ALG'] = array_merge($form['B']['ALG'], $form['ALG']);
  247. unset($form['ALG']);
  248. // Submit
  249. //.........................
  250. $form['B']['submit'] = array(
  251. '#type' => 'submit',
  252. '#default_value' => ' BLAST ',
  253. );
  254. return $form;
  255. }
  256. /**
  257. * Validate the user options submitted via the above form.
  258. *
  259. * @see blast_ui_per_blast_program_form().
  260. */
  261. function blast_ui_per_blast_program_form_validate($form, &$form_state) {
  262. $blast_program = $form_state['values']['blast_program'];
  263. $type = $form_state['values']['query_type'];
  264. if ($type == 'nucleotide') {
  265. $molecule_type = 'nucleotides';
  266. }
  267. else {
  268. $molecule_type = 'amino acid residues';
  269. }
  270. // Validate Query
  271. //----------------
  272. // @todo: We are currently not validating uploaded files are valid FASTA.
  273. // First check to see if we have an upload & if so then validate it.
  274. $file = null;
  275. if(isset($form_state['values']['UPLOAD'])) {
  276. $file = file_load($form_state['values']['UPLOAD']);
  277. }
  278. // If the $file is populated then this is a newly uploaded, temporary file.
  279. if (is_object($file)) {
  280. $form_state['qFlag'] = 'upQuery';
  281. $form_state['upQuery_path'] = drupal_realpath($file->uri);
  282. }
  283. // Otherwise there was no file uploaded.
  284. // Check if there was a query sequence entered in the texfield.
  285. elseif (!empty($form_state['input']['FASTA'])) {
  286. // Check to ensure that the query sequence entered is valid FASTA.
  287. if (!validate_fasta_sequence($type, $form_state['input']['FASTA'])){
  288. form_set_error('query', t('You need to provide a valid %molecule-type FASTA sequence '
  289. . 'for the query. For more information see the '
  290. . '<a href="@url" target="_blank">NCBI FASTA Specification</a>.',
  291. array(
  292. '%molecule-type' => $molecule_type,
  293. '@url' => 'http://www.ncbi.nlm.nih.gov/BLAST/blastcgihelp.shtml'
  294. )));
  295. }
  296. else {
  297. $form_state['qFlag'] = 'seqQuery';
  298. }
  299. }
  300. // Otherwise they didn't enter a query!!
  301. else {
  302. form_set_error('query', t('No query sequence given. Only raw sequence or '
  303. . 'sequence of type FASTA can be read. Enter sequence in the box provided '
  304. . 'or upload a plain text file.'));
  305. }
  306. // Validate Database
  307. //-------------------
  308. // @todo: We are currently not validating uploaded files are valid FASTA.
  309. // First check to see if we have an upload & if so then validate it.
  310. if (isset($form_state['values']['DBUPLOAD'])) {
  311. $file = file_load($form_state['values']['DBUPLOAD']);
  312. // If the $file is populated then this is a newly uploaded, temporary file.
  313. if (is_object($file)) {
  314. $form_state['dbFlag'] = 'upDB';
  315. $form_state['upDB_path'] = drupal_realpath($file->uri);
  316. }
  317. // Otherwise there was no file uploaded
  318. // Check if there was a database choosen from the list instead
  319. elseif (!empty($form_state['values']['SELECT_DB'])) {
  320. $form_state['dbFlag'] = 'blastdb';
  321. }
  322. // Otherwise they didn't select a database!!
  323. else {
  324. form_set_error('DB', t('No database selected. Either choose a database '
  325. . 'from the list or upload one of your own.'));
  326. }
  327. }
  328. // Otherwise there was no file uploaded
  329. // Check if there was a database choosen from the list instead
  330. elseif (!empty($form_state['values']['SELECT_DB'])) {
  331. $form_state['dbFlag'] = 'blastdb';
  332. }
  333. // Otherwise they didn't select a database!!
  334. else {
  335. form_set_error('DB', t('No database selected. Either choose a database '
  336. . 'from the list or upload one of your own.'));
  337. }
  338. // Validate Advanced Options
  339. //---------------------------
  340. $advanced_options_form_validate = 'blast_ui_' . $blast_program . '_advanced_options_form_validate';
  341. if (function_exists($advanced_options_form_validate)) {
  342. call_user_func_array(
  343. $advanced_options_form_validate,
  344. array(&$form, $form_state)
  345. );
  346. }
  347. }//blast_ui_per_blast_program_form_validate
  348. /**
  349. * Process the user options submitted via the blast program form.
  350. *
  351. * @see blast_ui_per_blast_program_form().
  352. */
  353. function blast_ui_per_blast_program_form_submit($form, &$form_state) {
  354. $error = FALSE;
  355. $blast_program = $form_state['values']['blast_program'];
  356. if ($form_state['values']['db_type'] == 'nucleotide') {
  357. $mdb_type = 'nucl';
  358. }
  359. else {
  360. $mdb_type = 'prot';
  361. }
  362. // We want to save information about the blast job to the database for recent jobs &
  363. // edit and resubmit functionality.
  364. // First set defaults.
  365. $blastjob = array(
  366. 'job_id' => NULL,
  367. 'blast_program' => $form_state['values']['blast_program'],
  368. 'target_blastdb' => (isset($form_state['values']['SELECT_DB'])) ? $form_state['values']['SELECT_DB'] : NULL,
  369. 'target_file' => NULL,
  370. 'query_file' => NULL,
  371. 'result_filestub' => NULL,
  372. 'options' => serialize(array())
  373. );
  374. // QUERY
  375. //-------------------------
  376. // BLAST can only take the query as a file;
  377. // therefore, if it was submitted via the textfield we need to create a file containing
  378. // the submitted sequence.
  379. if (isset($form_state['qFlag'])) {
  380. if ($form_state['qFlag'] == 'seqQuery') {
  381. $seq_content = $form_state['values']['FASTA'];
  382. $blastjob['query_file'] = variable_get('file_temporary_path', file_directory_temp()) . '/' . date('YMd_His') . '_query.fasta';
  383. file_put_contents ($blastjob['query_file'], $seq_content);
  384. }
  385. elseif ($form_state['qFlag'] == 'upQuery') {
  386. $blastjob['query_file'] = $form_state['upQuery_path'];
  387. }
  388. }
  389. // TARGET
  390. //-------------------------
  391. // If the BLAST database was uploaded then we need to format it to make it compatible with blast.
  392. if ($form_state['dbFlag'] == 'upDB') {
  393. // Since we only support using the -db flag (not -subject) we need to create a
  394. // blast database for the FASTA uploaded.
  395. // NOTE: We can't support subject because we need to generate the ASN.1+ format
  396. // to provide multiple download type options from the same BLAST
  397. $blastdb_with_path = $form_state['upDB_path'];
  398. $result = NULL;
  399. exec('makeblastdb -in ' . escapeshellarg($blastdb_with_path) . ' -dbtype ' . escapeshellarg($mdb_type) . ' -parse_seqids 2>&1', $result);
  400. // Check that the BLAST database was made correctly.
  401. $result = implode('<br />', $result);
  402. if (preg_match('/Error/', $result)) {
  403. drupal_set_message(t('Unable to generate a BLAST database from your uploaded FASTA '
  404. .'sequence. Please check that your file is a valid FASTA file '
  405. .'and that if your sequence headers include pipes (i.e.: | ) '
  406. .' they adhere to ')
  407. .l('NCBI standards.',
  408. 'http://www.ncbi.nlm.nih.gov/books/NBK21097/table/A632/?report=objectonly',
  409. array('attributes' => array('target' => '_blank'))
  410. ),
  411. 'error'
  412. );
  413. $error = TRUE;
  414. }
  415. }
  416. // Otherwise, we are using one of the website provided BLAST databases so form the
  417. // BLAST command accordingly
  418. elseif ($form_state['dbFlag'] == 'blastdb') {
  419. $selected_db = $form_state['values']['SELECT_DB'];
  420. $blastdb_node = node_load($selected_db);
  421. $blastdb_name = $blastdb_node->db_name;
  422. $blastdb_with_path = $blastdb_node->db_path;
  423. }
  424. $blastjob['target_file'] = $blastdb_with_path;
  425. // Determine the path to the blast database with extension.
  426. if ($mdb_type == 'nucl' && (preg_match('/\.[pn]al/', $blastdb_with_path) == 0)) {
  427. // Suffix may be .nsq or .nal
  428. if (is_readable("$blastdb_with_path.nsq")) {
  429. $blastdb_with_suffix = "$blastdb_with_path.nsq";
  430. }
  431. else if (is_readable("$blastdb_with_path.nal")) {
  432. $blastdb_with_suffix = "$blastdb_with_path.nal";
  433. }
  434. }
  435. else if ($mdb_type == 'prot' && (preg_match('/\.[pn]al/', $blastdb_with_path) == 0)) {
  436. // Suffix may be .psq or .pal
  437. if (is_readable("$blastdb_with_path.psq")) {
  438. $blastdb_with_suffix = "$blastdb_with_path.psq";
  439. }
  440. else if (is_readable("$blastdb_with_path.pal")) {
  441. $blastdb_with_suffix = "$blastdb_with_path.pal";
  442. }
  443. }
  444. else {
  445. $blastdb_with_suffix = $blastdb_with_path;
  446. }
  447. if (!is_readable($blastdb_with_suffix)) {
  448. $error = TRUE;
  449. $dbfile_uploaded_msg = ($form_state['dbFlag'] == 'upDB')
  450. ? 'The BLAST database was submitted via user upload.'
  451. : 'Existing BLAST Database was chosen.';
  452. tripal_report_error(
  453. 'blast_ui',
  454. TRIPAL_ERROR,
  455. "BLAST database %db unaccessible. %msg",
  456. array('%db' => $blastdb_with_path, '%msg' => $dbfile_uploaded_msg)
  457. );
  458. $msg = "$dbfile_uploaded_msg BLAST database '$blastdb_with_path' is unaccessible. ";
  459. $msg .= "Please contact the site administrator.";
  460. drupal_set_message($msg, 'error');
  461. }
  462. // ADVANCED OPTIONS
  463. //-------------------------
  464. // Now let each program process its own advanced options.
  465. $advanced_options = array();
  466. $advanced_options_form_submit = 'blast_ui_' . $blast_program . '_advanced_options_form_submit';
  467. if (function_exists($advanced_options_form_submit)) {
  468. $advanced_options = call_user_func_array(
  469. $advanced_options_form_submit,
  470. array($form['B'], $form_state)
  471. );
  472. }
  473. else {
  474. $advanced_options = array('none' => 0);
  475. }
  476. $blastjob['options'] = serialize($advanced_options);
  477. // SUBMIT JOB TO TRIPAL
  478. //-------------------------
  479. // Actually submit the BLAST Tripal Job
  480. if (!$error) {
  481. // BLAST target exists.
  482. global $user;
  483. // We want to save all result files (.asn, .xml, .tsv, .html) in the public files directory.
  484. // Usually [drupal root]/sites/default/files.
  485. $output_dir = tripal_get_files_dir('tripal_blast');
  486. $output_filestub = $output_dir . DIRECTORY_SEPARATOR . date('YMd_His') . '.blast';
  487. $job_args = array(
  488. 'program' => $blast_program,
  489. 'query' => $blastjob['query_file'],
  490. 'database' => $blastdb_with_path,
  491. 'output_filename' => $output_filestub,
  492. 'options' => $advanced_options
  493. );
  494. $job_id = tripal_add_job(
  495. t('BLAST (@program): @query', array('@program' => $blast_program, '@query' => $blastjob['query_file'])),
  496. 'blast_job',
  497. 'run_BLAST_tripal_job',
  498. $job_args,
  499. $user->uid
  500. );
  501. $blastjob['result_filestub'] = $output_filestub;
  502. $blastjob['job_id'] = $job_id;
  503. // SAVE JOB INFO
  504. //-------------------------
  505. drupal_write_record('blastjob', $blastjob);
  506. //Encode the job_id
  507. $job_encode_id = blast_ui_make_secret($job_id);
  508. // RECENT JOBS
  509. //-------------------------
  510. if (!isset($_SESSION['blast_jobs'])) {
  511. $_SESSION['blast_jobs'] = array();
  512. }
  513. $_SESSION['blast_jobs'][] = $job_encode_id;
  514. // NOTE: Originally there was a call to tripal_launch_jobs() here. That should
  515. // NEVER be done since it runs possibly long jobs in the page load causing time-out
  516. // issues. If you do not want to run tripal jobs manually, look into installing
  517. // Tripal daemon which will run jobs as they're submitted or set up a cron job to
  518. // launch the tripal jobs on a specified schedule.
  519. // Redirect to the BLAST results page
  520. drupal_goto("blast/report/$job_encode_id");
  521. }
  522. }
  523. /**
  524. * AJAX: Replace the sequence textarea with one containing an example.
  525. */
  526. function ajax_blast_ui_perprogram_example_sequence_callback($form, $form_state) {
  527. $sequence_type = $form_state['values']['query_type'];
  528. // Choose the example sequence based on the sequence type of the query.
  529. if ($sequence_type == 'nucleotide') {
  530. $example_sequence = variable_get('blast_ui_nucleotide_example_sequence', 'sample');
  531. if ($example_sequence == 'sample') {
  532. $example_sequence = '>partial lipoxygenase Glyma15g03040
  533. TTTCGTATGA GATTAAAATG TGTGAAATTT TGTTTGATAG GACATGGGAA
  534. AGGAAAAGTT GGAAAGGCTA CAAATTTAAG AGGACAAGTG TCGTTACCAA
  535. CCTTGGGAGC TGGCGAAGAT GCATACGATG TTCATTTTGA ATGGGACAGT
  536. GACTTCGGAA TTCCCGGTGC ATTTTACATT AAGAACTTCA TGCAAGTTGA
  537. GTTCTATCTC AAGTCTCTAA CTCTCGAAGA CATTCCAAAC CACGGAACCA
  538. TTCACTTCGT ATGCAACTCC TGGGTTTACA ACTCAAAATC CTACCATTCT
  539. GATCGCATTT TCTTTGCCAA CAATGTAAGC TACTTAAATA CTGTTATACA
  540. TTGTCTAACA TCTTGTTAGA GTCTTGCATG ATGTGTACCG TTTATTGTTG
  541. TTGTTGAACT TTACCACATG GCATGGATGC AAAAGTTGTT ATACACATAA
  542. ATTATAATGC AGACATATCT TCCAAGCGAG ACACCGGCTC CACTTGTCAA
  543. GTACAGAGAA GAAGAATTGA AGAATGTAAG AGGGGATGGA ACTGGTGAGC
  544. GCAAGGAATG GGATAGGATC TATGATTATG ATGTCTACAA TGACTTGGGC
  545. GATCCAGATA AGGGTGAAAA GTATGCACGC CCCGTTCTTG GAGGTTCTGC
  546. CTTACCTTAC CCTCGCAGAG GAAGAACCGG AAGAGGAAAA ACTAGAAAAG
  547. GTTTCTCACT AGTCACTAAT TTATTACTTT TTAATGTTTG TTTTTAGGCA
  548. TCTTTTCTGA TGAAATGTAT ACTTTTGATG TTTTTTTGTT TTAGCATAAC
  549. TGAATTAGTA AAGTGTGTTG TGTTCCTTAG AAGTTAGAAA AGTACTAAGT
  550. ATAAGGTCTT TGAGTTGTCG TCTTTATCTT AACAGATCCC AACAGTGAGA
  551. AGCCCAGTGA TTTTGTTTAC CTTCCGAGAG ATGAAGCATT TGGTCACTTG
  552. AAGTCATCAG ATTTTCTCGT TTATGGAATC AAATCAGTGG CTCAAGACGT
  553. CTTGCCCGTG TTGACTGATG CGTTTGATGG CAATCTTTTG AGCCTTGAGT
  554. TTGATAACTT TGCTGAAGTG CGCAAACTCT ATGAAGGTGG AGTTACACTA
  555. CCTACAAACT TTCTTAGCAA GATCGCCCCT ATACCAGTGG TCAAGGAAAT
  556. TTTTCGAACT GATGGCGAAC AGTTCCTCAA GTATCCACCA CCTAAAGTGA
  557. TGCAGGGTAT GCTACATATT TTGAATATGT AGAATATTAT CAATATACTC
  558. CTGTTTTTAT TCAACATATT TAATCACATG GATGAATTTT TGAACTGTTA';
  559. tripal_set_message(t('You can set the example sequence through the administrative interface: <a href="@url" target="_blank">Admin Toolbar > Tripal > Extensions > Tripal BLAST User Interface</a>',
  560. array('@url' => url('admin/tripal/extension/tripal_blast'))));
  561. }
  562. }
  563. elseif ($sequence_type == 'protein') {
  564. $example_sequence = variable_get('blast_ui_protein_example_sequence', 'sample');
  565. if ($example_sequence == 'sample') {
  566. $example_sequence = '>gi|166477|gb|AAA96434.1| resveratrol synthase [Arachis hypogaea]
  567. MVSVSGIRKVQRAEGPATVLAIGTANPPNCIDQSTYADYYFRVTNSEHMTDLKKKFQRICERTQIKNRHM
  568. YLTEEILKENPNMCAYKAPSLDAREDMMIREVPRVGKEAATKAIKEWGQPMSKITHLIFCTTSGVALPGV
  569. DYELIVLLGLDPCVKRYMMYHQGCFAGGTVLRLAKDLAENNKDARVLIVCSENTAVTFRGPSETDMDSLV
  570. GQALFADGAAAIIIGSDPVPEVEKPIFELVSTDQKLVPGSHGAIGGLLREVGLTFYLNKSVPDIISQNIN
  571. DALNKAFDPLGISDYNSIFWIAHPGGRAILDQVEQKVNLKPEKMKATRDVLSNYGNMSSACVFFIMDLMR
  572. KRSLEEGLKTTGEGLDWGVLFGFGPGLTIETVVLRSVAI';
  573. tripal_set_message(t('You can set the example sequence through the administrative interface: <a href="@url" target="_blank">Admin Toolbar > Tripal > Extensions > Tripal BLAST User Interface</a>',
  574. array('@url' => url('admin/tripal/extension/tripal_blast'))));
  575. }
  576. }
  577. else {
  578. $example_sequence = 'unknown query type';
  579. }
  580. // If the Show Example checkbox is true then put the example in the textfield
  581. if ($form_state['values']['example_sequence']) {
  582. // Set the value to be the example sequence (set in the admin form).
  583. $form['B']['query']['FASTA']['#value'] = $example_sequence;
  584. }
  585. // Otherwise we want to remove the already displayed example.
  586. else {
  587. $form['B']['query']['FASTA']['#value'] = '';
  588. }
  589. return $form['B']['query']['FASTA'];
  590. }