FASTAImporterTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace Tests;
  3. use StatonLab\TripalTestSuite\DBTransaction;
  4. use StatonLab\TripalTestSuite\TripalTestCase;
  5. class FASTAImporterTest extends TripalTestCase {
  6. // Uncomment to auto start and rollback db transactions per test method.
  7. use DBTransaction;
  8. /**
  9. * Basic test example.
  10. * Tests must begin with the word "test".
  11. * See https://phpunit.readthedocs.io/en/latest/ for more information.
  12. */
  13. /**
  14. * @group fasta
  15. * @group chado
  16. */
  17. public function testImporterAssociatesParentWithoutRegexp() {
  18. module_load_include('inc', 'tripal_chado', 'includes/TripalImporter/FASTAImporter');
  19. $importer = new \FASTAImporter();
  20. //this test will first create an organism and mrna features with the same name as devseed proteins.
  21. //It will then load the devseed protein fasta via the importer.
  22. //Finally it will ensure feature_relationships exist with the test mrna.
  23. $organism = factory('chado.organism')->create();
  24. $mrna_term = chado_get_cvterm(['id' => 'SO:0000234']);
  25. $analysis = factory('chado.analysis')->create();
  26. $mrna_1 = factory('chado.feature')->create([
  27. 'type_id' => $mrna_term->cvterm_id,
  28. 'organism_id' => $organism->organism_id,
  29. 'name' => 'FRAEX38873_v2_000000010.1',
  30. 'uniquename' => 'FRAEX38873_v2_000000010.1',
  31. ]);
  32. $mrna_2 = factory('chado.feature')->create([
  33. 'type_id' => $mrna_term->cvterm_id,
  34. 'organism_id' => $organism->organism_id,
  35. 'name' => 'FRAEX38873_v2_000000010.2',
  36. 'uniquename' => 'FRAEX38873_v2_000000010.2',
  37. ]);
  38. $file = ['file_local' => __DIR__ . '/../data/two_prots.fasta'];
  39. $run_args = [
  40. 'analysis_id' => $analysis->analysis_id,
  41. 'organism_id' => $organism->organism_id,
  42. 'seqtype' => 'polypeptide',
  43. 'parent_type' => "mRNA",
  44. 'rel_type' => "derives_from",
  45. 'method' => '2',
  46. 'match_type' => '1',
  47. 're_name' => "",
  48. 're_uname' => "",
  49. 're_accession' => "",
  50. 'db_id' => "",
  51. 're_subject' => "",
  52. 'match_type' => "1",
  53. ];
  54. $importer->create($run_args, $file);
  55. $importer->prepareFiles();
  56. $importer->run();
  57. $result = db_select('chado.feature', 'f')
  58. ->fields('f')
  59. ->condition('f.organism_id', $organism->organism_id)
  60. ->execute()
  61. ->fetchAll();
  62. $this->assertNotEquals(2, count($result), 'The child features were not loaded when a regexp was not provided.');
  63. $query = db_select('chado.feature_relationship', 'fr')
  64. ->fields('fr')
  65. ->condition('fr.object_id', $mrna_1->feature_id);
  66. $query->join('chado.feature', 'f', 'f.feature_id = fr.subject_id');
  67. $result = $query->execute()
  68. ->fetchObject();
  69. $this->assertNotFalse($result, 'relationship was not added to parente feature when regexp not provided (same parent/child name).');
  70. }
  71. }