blast_ui.form_per_program.inc 24 KB

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