blast_ui.form_per_program.inc 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  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. '#upload_validators' => array(
  230. 'file_validate_extensions' => array('fasta fna fa'),
  231. 'file_validate_size' => array(file_upload_max_size()),
  232. ),
  233. );
  234. }
  235. // Advanced Options
  236. //.........................
  237. // These options will be different depending upon the program selected.
  238. // Therefore, allow for program-specific callbacks to populate these options.
  239. $form['B']['ALG'] = array(
  240. '#type' => 'fieldset',
  241. '#title' => t('Advanced Options'),
  242. '#collapsible' => TRUE,
  243. '#collapsed' => TRUE,
  244. );
  245. $advanced_options_form = 'blast_ui_' . $blast_program . '_advanced_options_form';
  246. if (function_exists($advanced_options_form)) {
  247. call_user_func_array($advanced_options_form, array(&$form, $form_state));
  248. }
  249. $form['B']['ALG'] = array_merge($form['B']['ALG'], $form['ALG']);
  250. unset($form['ALG']);
  251. // Submit
  252. //.........................
  253. $form['B']['submit'] = array(
  254. '#type' => 'submit',
  255. '#default_value' => ' BLAST ',
  256. );
  257. return $form;
  258. }
  259. /**
  260. * Validate the user options submitted via the above form.
  261. *
  262. * @see blast_ui_per_blast_program_form().
  263. */
  264. function blast_ui_per_blast_program_form_validate($form, &$form_state) {
  265. $blast_program = $form_state['values']['blast_program'];
  266. $type = $form_state['values']['query_type'];
  267. if ($type == 'nucleotide') {
  268. $molecule_type = 'nucleotides';
  269. }
  270. else {
  271. $molecule_type = 'amino acid residues';
  272. }
  273. // Validate Query
  274. //----------------
  275. // @todo: We are currently not validating uploaded files are valid FASTA.
  276. // First check to see if we have an upload & if so then validate it.
  277. $file = null;
  278. if(isset($form_state['values']['UPLOAD'])) {
  279. $file = file_load($form_state['values']['UPLOAD']);
  280. }
  281. // If the $file is populated then this is a newly uploaded, temporary file.
  282. if (is_object($file)) {
  283. $form_state['qFlag'] = 'upQuery';
  284. $form_state['upQuery_path'] = drupal_realpath($file->uri);
  285. }
  286. // Otherwise there was no file uploaded.
  287. // Check if there was a query sequence entered in the texfield.
  288. elseif (!empty($form_state['input']['FASTA'])) {
  289. // Check to ensure that the query sequence entered is valid FASTA.
  290. if (!validate_fasta_sequence($type, $form_state['input']['FASTA'])){
  291. form_set_error('query', t('You need to provide a valid %molecule-type FASTA sequence '
  292. . 'for the query. For more information see the '
  293. . '<a href="@url" target="_blank">NCBI FASTA Specification</a>.',
  294. array(
  295. '%molecule-type' => $molecule_type,
  296. '@url' => 'http://www.ncbi.nlm.nih.gov/BLAST/blastcgihelp.shtml'
  297. )));
  298. }
  299. else {
  300. $form_state['qFlag'] = 'seqQuery';
  301. }
  302. }
  303. // Otherwise they didn't enter a query!!
  304. else {
  305. form_set_error('query', t('No query sequence given. Only raw sequence or '
  306. . 'sequence of type FASTA can be read. Enter sequence in the box provided '
  307. . 'or upload a plain text file.'));
  308. }
  309. // Validate Database
  310. //-------------------
  311. // @todo: We are currently not validating uploaded files are valid FASTA.
  312. // First check to see if we have an upload & if so then validate it.
  313. if (isset($form_state['values']['DBUPLOAD'])) {
  314. $file = file_load($form_state['values']['DBUPLOAD']);
  315. // If the $file is populated then this is a newly uploaded, temporary file.
  316. if (is_object($file)) {
  317. $form_state['dbFlag'] = 'upDB';
  318. $form_state['upDB_path'] = drupal_realpath($file->uri);
  319. }
  320. // Otherwise there was no file uploaded
  321. // Check if there was a database choosen from the list instead
  322. elseif (!empty($form_state['values']['SELECT_DB'])) {
  323. $form_state['dbFlag'] = 'blastdb';
  324. }
  325. // Otherwise they didn't select a database!!
  326. else {
  327. form_set_error('DB', t('No database selected. Either choose a database '
  328. . 'from the list or upload one of your own.'));
  329. }
  330. }
  331. // Otherwise there was no file uploaded
  332. // Check if there was a database choosen from the list instead
  333. elseif (!empty($form_state['values']['SELECT_DB'])) {
  334. $form_state['dbFlag'] = 'blastdb';
  335. }
  336. // Otherwise they didn't select a database!!
  337. else {
  338. form_set_error('DB', t('No database selected. Either choose a database '
  339. . 'from the list or upload one of your own.'));
  340. }
  341. // Validate Advanced Options
  342. //---------------------------
  343. $advanced_options_form_validate = 'blast_ui_' . $blast_program . '_advanced_options_form_validate';
  344. if (function_exists($advanced_options_form_validate)) {
  345. call_user_func_array(
  346. $advanced_options_form_validate,
  347. array(&$form, $form_state)
  348. );
  349. }
  350. }//blast_ui_per_blast_program_form_validate
  351. /**
  352. * Process the user options submitted via the blast program form.
  353. *
  354. * @see blast_ui_per_blast_program_form().
  355. */
  356. function blast_ui_per_blast_program_form_submit($form, &$form_state) {
  357. $error = FALSE;
  358. $blast_program = $form_state['values']['blast_program'];
  359. if ($form_state['values']['db_type'] == 'nucleotide') {
  360. $mdb_type = 'nucl';
  361. }
  362. else {
  363. $mdb_type = 'prot';
  364. }
  365. // We want to save information about the blast job to the database for recent jobs &
  366. // edit and resubmit functionality.
  367. // First set defaults.
  368. $blastjob = array(
  369. 'job_id' => NULL,
  370. 'blast_program' => $form_state['values']['blast_program'],
  371. 'target_blastdb' => (isset($form_state['values']['SELECT_DB'])) ? $form_state['values']['SELECT_DB'] : NULL,
  372. 'target_file' => NULL,
  373. 'query_file' => NULL,
  374. 'result_filestub' => NULL,
  375. 'options' => serialize(array())
  376. );
  377. // QUERY
  378. //-------------------------
  379. // BLAST can only take the query as a file;
  380. // therefore, if it was submitted via the textfield we need to create a file containing
  381. // the submitted sequence.
  382. if (isset($form_state['qFlag'])) {
  383. if ($form_state['qFlag'] == 'seqQuery') {
  384. $seq_content = $form_state['values']['FASTA'];
  385. $blastjob['query_file'] = variable_get('file_temporary_path', file_directory_temp()) . '/' . date('YMd_His') . '_query.fasta';
  386. file_put_contents ($blastjob['query_file'], $seq_content);
  387. }
  388. elseif ($form_state['qFlag'] == 'upQuery') {
  389. $blastjob['query_file'] = $form_state['upQuery_path'];
  390. }
  391. }
  392. // TARGET
  393. //-------------------------
  394. // If the BLAST database was uploaded then we need to format it to make it compatible with blast.
  395. if ($form_state['dbFlag'] == 'upDB') {
  396. // Since we only support using the -db flag (not -subject) we need to create a
  397. // blast database for the FASTA uploaded.
  398. // NOTE: We can't support subject because we need to generate the ASN.1+ format
  399. // to provide multiple download type options from the same BLAST
  400. $blastdb_with_path = $form_state['upDB_path'];
  401. $blast_path = variable_get('blast_path', '');
  402. $makeblast_db = $blast_path . 'makeblastdb';
  403. $result = NULL;
  404. exec(escapeshellarg($makeblast_db) . ' -in ' . escapeshellarg($blastdb_with_path) . ' -dbtype ' . escapeshellarg($mdb_type) . ' -parse_seqids 2>&1', $result);
  405. // Check that the BLAST database was made correctly.
  406. $result = implode('<br />', $result);
  407. if (preg_match('/Error/', $result)) {
  408. drupal_set_message(t('Unable to generate a BLAST database from your uploaded FASTA '
  409. .'sequence. Please check that your file is a valid FASTA file '
  410. .'and that if your sequence headers include pipes (i.e.: | ) '
  411. .' they adhere to ')
  412. .l('NCBI standards.',
  413. 'http://www.ncbi.nlm.nih.gov/books/NBK21097/table/A632/?report=objectonly',
  414. array('attributes' => array('target' => '_blank'))
  415. ),
  416. 'error'
  417. );
  418. $error = TRUE;
  419. }
  420. }
  421. // Otherwise, we are using one of the website provided BLAST databases so form the
  422. // BLAST command accordingly
  423. elseif ($form_state['dbFlag'] == 'blastdb') {
  424. $selected_db = $form_state['values']['SELECT_DB'];
  425. $blastdb_node = node_load($selected_db);
  426. $blastdb_name = $blastdb_node->db_name;
  427. $blastdb_with_path = $blastdb_node->db_path;
  428. }
  429. $blastjob['target_file'] = $blastdb_with_path;
  430. // Determine the path to the blast database with extension.
  431. $blastdb_with_suffix = $blastdb_with_path;
  432. if ($mdb_type == 'nucl') {
  433. // Suffix may be .nsq or .nal
  434. if (is_readable("$blastdb_with_path.nsq")) {
  435. $blastdb_with_suffix = "$blastdb_with_path.nsq";
  436. }
  437. elseif (is_readable("$blastdb_with_path.nal")) {
  438. $blastdb_with_suffix = "$blastdb_with_path.nal";
  439. }
  440. }
  441. elseif ($mdb_type == 'prot') {
  442. // Suffix may be .psq or .pal
  443. if (is_readable("$blastdb_with_path.psq")) {
  444. $blastdb_with_suffix = "$blastdb_with_path.psq";
  445. }
  446. else if (is_readable("$blastdb_with_path.pal")) {
  447. $blastdb_with_suffix = "$blastdb_with_path.pal";
  448. }
  449. }
  450. if (!is_readable($blastdb_with_suffix)) {
  451. $error = TRUE;
  452. $dbfile_uploaded_msg = ($form_state['dbFlag'] == 'upDB')
  453. ? 'The BLAST database was submitted via user upload.'
  454. : 'Existing BLAST Database was chosen.';
  455. tripal_report_error(
  456. 'blast_ui',
  457. TRIPAL_ERROR,
  458. "BLAST database %db unaccessible. %msg",
  459. array('%db' => $blastdb_with_path, '%msg' => $dbfile_uploaded_msg)
  460. );
  461. $msg = "$dbfile_uploaded_msg BLAST database '$blastdb_with_path' is unaccessible. ";
  462. $msg .= "Please contact the site administrator.";
  463. drupal_set_message($msg, 'error');
  464. }
  465. // ADVANCED OPTIONS
  466. //-------------------------
  467. // Now let each program process its own advanced options.
  468. $advanced_options = array();
  469. $advanced_options_form_submit = 'blast_ui_' . $blast_program . '_advanced_options_form_submit';
  470. if (function_exists($advanced_options_form_submit)) {
  471. $advanced_options = call_user_func_array(
  472. $advanced_options_form_submit,
  473. array($form['B'], $form_state)
  474. );
  475. }
  476. else {
  477. $advanced_options = array('none' => 0);
  478. }
  479. $blastjob['options'] = serialize($advanced_options);
  480. // SUBMIT JOB TO TRIPAL
  481. //-------------------------
  482. // Actually submit the BLAST Tripal Job
  483. if (!$error) {
  484. // BLAST target exists.
  485. global $user;
  486. // We want to save all result files (.asn, .xml, .tsv, .html) in the public files directory.
  487. // Usually [drupal root]/sites/default/files.
  488. $output_dir = tripal_get_files_dir('tripal_blast');
  489. $output_filestub = $output_dir . DIRECTORY_SEPARATOR . date('YMd_His') . '.blast';
  490. $job_args = array(
  491. 'program' => $blast_program,
  492. 'query' => $blastjob['query_file'],
  493. 'database' => $blastdb_with_path,
  494. 'output_filename' => $output_filestub,
  495. 'options' => $advanced_options
  496. );
  497. $job_id = tripal_add_job(
  498. t('BLAST (@program): @query', array('@program' => $blast_program, '@query' => $blastjob['query_file'])),
  499. 'blast_job',
  500. 'run_BLAST_tripal_job',
  501. $job_args,
  502. $user->uid
  503. );
  504. $blastjob['result_filestub'] = $output_filestub;
  505. $blastjob['job_id'] = $job_id;
  506. // SAVE JOB INFO
  507. //-------------------------
  508. drupal_write_record('blastjob', $blastjob);
  509. //Encode the job_id
  510. $job_encode_id = blast_ui_make_secret($job_id);
  511. // RECENT JOBS
  512. //-------------------------
  513. if (!isset($_SESSION['blast_jobs'])) {
  514. $_SESSION['blast_jobs'] = array();
  515. }
  516. $_SESSION['blast_jobs'][] = $job_encode_id;
  517. // NOTE: Originally there was a call to tripal_launch_jobs() here. That should
  518. // NEVER be done since it runs possibly long jobs in the page load causing time-out
  519. // issues. If you do not want to run tripal jobs manually, look into installing
  520. // Tripal daemon which will run jobs as they're submitted or set up a cron job to
  521. // launch the tripal jobs on a specified schedule.
  522. // Redirect to the BLAST results page
  523. drupal_goto("blast/report/$job_encode_id");
  524. }
  525. }
  526. /**
  527. * AJAX: Replace the sequence textarea with one containing an example.
  528. */
  529. function ajax_blast_ui_perprogram_example_sequence_callback($form, $form_state) {
  530. $sequence_type = $form_state['values']['query_type'];
  531. // Choose the example sequence based on the sequence type of the query.
  532. if ($sequence_type == 'nucleotide') {
  533. $example_sequence = variable_get('blast_ui_nucleotide_example_sequence', 'sample');
  534. if ($example_sequence == 'sample') {
  535. $example_sequence = '>partial lipoxygenase Glyma15g03040
  536. TTTCGTATGA GATTAAAATG TGTGAAATTT TGTTTGATAG GACATGGGAA
  537. AGGAAAAGTT GGAAAGGCTA CAAATTTAAG AGGACAAGTG TCGTTACCAA
  538. CCTTGGGAGC TGGCGAAGAT GCATACGATG TTCATTTTGA ATGGGACAGT
  539. GACTTCGGAA TTCCCGGTGC ATTTTACATT AAGAACTTCA TGCAAGTTGA
  540. GTTCTATCTC AAGTCTCTAA CTCTCGAAGA CATTCCAAAC CACGGAACCA
  541. TTCACTTCGT ATGCAACTCC TGGGTTTACA ACTCAAAATC CTACCATTCT
  542. GATCGCATTT TCTTTGCCAA CAATGTAAGC TACTTAAATA CTGTTATACA
  543. TTGTCTAACA TCTTGTTAGA GTCTTGCATG ATGTGTACCG TTTATTGTTG
  544. TTGTTGAACT TTACCACATG GCATGGATGC AAAAGTTGTT ATACACATAA
  545. ATTATAATGC AGACATATCT TCCAAGCGAG ACACCGGCTC CACTTGTCAA
  546. GTACAGAGAA GAAGAATTGA AGAATGTAAG AGGGGATGGA ACTGGTGAGC
  547. GCAAGGAATG GGATAGGATC TATGATTATG ATGTCTACAA TGACTTGGGC
  548. GATCCAGATA AGGGTGAAAA GTATGCACGC CCCGTTCTTG GAGGTTCTGC
  549. CTTACCTTAC CCTCGCAGAG GAAGAACCGG AAGAGGAAAA ACTAGAAAAG
  550. GTTTCTCACT AGTCACTAAT TTATTACTTT TTAATGTTTG TTTTTAGGCA
  551. TCTTTTCTGA TGAAATGTAT ACTTTTGATG TTTTTTTGTT TTAGCATAAC
  552. TGAATTAGTA AAGTGTGTTG TGTTCCTTAG AAGTTAGAAA AGTACTAAGT
  553. ATAAGGTCTT TGAGTTGTCG TCTTTATCTT AACAGATCCC AACAGTGAGA
  554. AGCCCAGTGA TTTTGTTTAC CTTCCGAGAG ATGAAGCATT TGGTCACTTG
  555. AAGTCATCAG ATTTTCTCGT TTATGGAATC AAATCAGTGG CTCAAGACGT
  556. CTTGCCCGTG TTGACTGATG CGTTTGATGG CAATCTTTTG AGCCTTGAGT
  557. TTGATAACTT TGCTGAAGTG CGCAAACTCT ATGAAGGTGG AGTTACACTA
  558. CCTACAAACT TTCTTAGCAA GATCGCCCCT ATACCAGTGG TCAAGGAAAT
  559. TTTTCGAACT GATGGCGAAC AGTTCCTCAA GTATCCACCA CCTAAAGTGA
  560. TGCAGGGTAT GCTACATATT TTGAATATGT AGAATATTAT CAATATACTC
  561. CTGTTTTTAT TCAACATATT TAATCACATG GATGAATTTT TGAACTGTTA';
  562. 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>',
  563. array('@url' => url('admin/tripal/extension/tripal_blast'))));
  564. }
  565. }
  566. elseif ($sequence_type == 'protein') {
  567. $example_sequence = variable_get('blast_ui_protein_example_sequence', 'sample');
  568. if ($example_sequence == 'sample') {
  569. $example_sequence = '>gi|166477|gb|AAA96434.1| resveratrol synthase [Arachis hypogaea]
  570. MVSVSGIRKVQRAEGPATVLAIGTANPPNCIDQSTYADYYFRVTNSEHMTDLKKKFQRICERTQIKNRHM
  571. YLTEEILKENPNMCAYKAPSLDAREDMMIREVPRVGKEAATKAIKEWGQPMSKITHLIFCTTSGVALPGV
  572. DYELIVLLGLDPCVKRYMMYHQGCFAGGTVLRLAKDLAENNKDARVLIVCSENTAVTFRGPSETDMDSLV
  573. GQALFADGAAAIIIGSDPVPEVEKPIFELVSTDQKLVPGSHGAIGGLLREVGLTFYLNKSVPDIISQNIN
  574. DALNKAFDPLGISDYNSIFWIAHPGGRAILDQVEQKVNLKPEKMKATRDVLSNYGNMSSACVFFIMDLMR
  575. KRSLEEGLKTTGEGLDWGVLFGFGPGLTIETVVLRSVAI';
  576. 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>',
  577. array('@url' => url('admin/tripal/extension/tripal_blast'))));
  578. }
  579. }
  580. else {
  581. $example_sequence = 'unknown query type';
  582. }
  583. // If the Show Example checkbox is true then put the example in the textfield
  584. if ($form_state['values']['example_sequence']) {
  585. // Set the value to be the example sequence (set in the admin form).
  586. $form['B']['query']['FASTA']['#value'] = $example_sequence;
  587. }
  588. // Otherwise we want to remove the already displayed example.
  589. else {
  590. $form['B']['query']['FASTA']['#value'] = '';
  591. }
  592. return $form['B']['query']['FASTA'];
  593. }