BlastJobTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace Tests;
  3. use StatonLab\TripalTestSuite\DBTransaction;
  4. use StatonLab\TripalTestSuite\TripalTestCase;
  5. use Faker\Factory;
  6. /**
  7. * Tests running BLAST jobs. Specifically, run_BLAST_tripal_job().
  8. */
  9. class BlastJobTest extends TripalTestCase {
  10. use DBTransaction;
  11. /**
  12. * Tests BLASTN
  13. */
  14. public function testBLASTn() {
  15. $faker = Factory::create();
  16. // Test we have access to the NCBI Blast commands.
  17. // Setting the default to where it is on Travis CI: /usr/local/bin.
  18. $blast_path = variable_get('blast_path', '/usr/local/bin/');
  19. $this->assertFileExists($blast_path . 'blastn', 'NCBI blastn command not found. Expecting it here: '.$blast_path.'blastn');
  20. $this->assertFileExists($blast_path . 'blast_formatter', 'NCBI blast_formatter command not found. Expecting it here: '.$blast_path.'blast_formatter');
  21. // Make sure the path to blast is set!
  22. if ($blast_path == '/usr/local/bin/') {
  23. variable_set('blast_path', '/usr/local/bin/');
  24. }
  25. // Retrieve paths to files.
  26. $module_path = DRUPAL_ROOT . '/' . drupal_get_path('module','blast_ui');
  27. $file_path = DRUPAL_ROOT . '/' . variable_get('file_public_path', conf_path() . '/files');
  28. // Set parameters for run_BLAST_tripal_job().
  29. $program = 'blastn';
  30. $query = $module_path . '/tests/test_files/Citrus_sinensis-orange1.1g015632m.g.fasta';
  31. $database = $module_path . '/tests/test_files/Citrus_sinensis-scaffold00001';
  32. $output_filestub = $file_path . '/tripal/tripal_blast/' . $faker->word;
  33. // Quick check that the output file doesnt already exists ;-).
  34. $this->assertFileNotExists($output_filestub . '.asn', "Result File, $output_file, already exists before the command is run.");
  35. // We start the test with no options.
  36. $options = array();
  37. // Supress output and tripal errors.
  38. // NOTE: silent() didn't work for some reason.
  39. putenv("TRIPAL_SUPPRESS_ERRORS=TRUE");
  40. ob_start();
  41. run_BLAST_tripal_job($program, $query, $database, $output_filestub, $options);
  42. // Clean the buffer and unset tripal errors suppression.
  43. ob_end_clean();
  44. putenv("TRIPAL_SUPPRESS_ERRORS");
  45. // Loop through each expected output file...
  46. $files_to_check = array();
  47. $files_to_check[] = $output_filestub . '.asn';
  48. $files_to_check[] = $output_filestub . '.xml';
  49. $files_to_check[] = $output_filestub . '.tsv';
  50. $files_to_check[] = $output_filestub . '.html';
  51. $files_to_check[] = $output_filestub . '.gff';
  52. foreach($files_to_check as $output_file) {
  53. // Check that the file exists.
  54. $this->assertFileExists($output_file, "Result File, $output_file, doesn't exist.");
  55. // Check that the file is not empty.
  56. $this->assertNotEquals(0, filesize($output_file), "The Result File, $output_file, is empty.");
  57. // Clean-up by removing the file.
  58. unlink($output_file);
  59. }
  60. }
  61. }