blast_ui.api.inc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * @file
  4. * Contains more generally applicable functions as well as some meant to help developers
  5. * Plug-in to the BLAST UI functionality
  6. */
  7. /**
  8. * Returns a list BLAST DATABASE options
  9. *
  10. * @param $type
  11. * The type of BLAST dabases to restrict the list to (ie: n: nucleotide or p: protein)
  12. *
  13. * @return
  14. * An array where the nid is the key and the value is the human-readable name of the option
  15. */
  16. function get_blast_database_options($type) {
  17. // Get all BlastDB nodes
  18. $nodes = node_load_multiple(array(), array('type'=> 'blastdb'));
  19. $options = array();
  20. foreach ($nodes as $node) {
  21. if ( isset($node) && isset($node->db_dbtype) ) {
  22. if ( ($node->db_dbtype == $type) ) {
  23. $options[$node->nid] = $node->db_name;
  24. }
  25. }
  26. }
  27. asort($options);
  28. $options[0] = 'Select a Dataset';
  29. return $options;
  30. }
  31. /**
  32. * Run BLAST (should be called from the command-line)
  33. *
  34. * @param $program
  35. * Which BLAST program to run (ie: 'blastn', 'tblastn', tblastx', 'blastp','blastx')
  36. * @param $query
  37. * The full path and filename of the query FASTA file
  38. * @param $database
  39. * The full path and filename prefix (excluding .nhr, .nin, .nsq, etc.)
  40. * @param $output_filename
  41. * The filename (not including path) to give the results
  42. * @param $options
  43. * An array of additional option where the key is the name of the option used by
  44. * BLAST (ie: 'num_alignments') and the value is relates to this particular
  45. * BLAST job (ie: 250)
  46. */
  47. function run_BLAST_tripal_job($program, $query, $database, $output_file, $options, $job_id = NULL) {
  48. $output_file = 'sites/default/files/' . $output_file;
  49. print "\nExecuting $program\n\n";
  50. print "Query: $query\n";
  51. print "Database: $database\n";
  52. print "Results File: $output_file\n";
  53. print "Options:\n";
  54. $blast_cmd = "$program -query $query -db $database -out $output_file -outfmt=5";
  55. if (!empty($options)) {
  56. foreach ($options as $opt => $val) {
  57. print "\t$opt: $val\n";
  58. $blast_cmd .= " -$opt $val";
  59. }
  60. }
  61. print "\nExecuting the following BLAST command:\n" . $blast_cmd . "\n";
  62. system($blast_cmd);
  63. print "\nDone!\n";
  64. }