blast_ui.form_per_program.inc 24 KB

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