TripalChadoFeatureAPITest.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace Tests\tripal_chado\api;
  3. use StatonLab\TripalTestSuite\DBTransaction;
  4. use StatonLab\TripalTestSuite\TripalTestCase;
  5. class TripalChadoFeatureAPITest extends TripalTestCase {
  6. // Uncomment to auto start and rollback db transactions per test method.
  7. use DBTransaction;
  8. /**
  9. * Tests chado_get_feature_sequences().
  10. *
  11. * @group tripal_chado_api
  12. * @group feature-module
  13. */
  14. public function testChadoGetFeatureSeqs() {
  15. // Preparation... Create the features.
  16. $base_seq = 'GGG' . str_repeat('A', 25) . str_repeat('G', 10) . str_repeat('C', 50) . 'GGG';
  17. $base_feature = factory('chado.feature')->create([
  18. 'residues' => $base_seq,
  19. ]);
  20. // Create two derived features matching the region of AAA's.
  21. $mRNA_feature = factory('chado.feature')->create([
  22. 'residues' => '',
  23. ]);
  24. chado_insert_record('featureloc', [
  25. 'feature_id' => $mRNA_feature->feature_id,
  26. 'srcfeature_id' => $base_feature->feature_id,
  27. 'fmin' => 3,
  28. 'fmax' => (3 + 25),
  29. 'strand' => 1,
  30. 'rank' => 0,
  31. ]);
  32. chado_insert_record('featureloc', [
  33. 'feature_id' => $mRNA_feature->feature_id,
  34. 'srcfeature_id' => $base_feature->feature_id,
  35. 'fmin' => (3 + 25 + 10),
  36. 'fmax' => (3 + 25 + 10 + 50),
  37. 'strand' => 1,
  38. 'rank' => 1,
  39. ]);
  40. // Make sure we can retrieve the correct sequence for the base feature.
  41. $returned_seq_results = chado_get_feature_sequences([
  42. 'feature_id' => $base_feature->feature_id
  43. ], ['is_html' => FALSE, 'width' => 100]);
  44. $this->assertCount(1, $returned_seq_results, "There should only be the base sequence returned.");
  45. $returned_seq = $returned_seq_results[0]['residues'];
  46. $this->assertEquals($base_seq, $returned_seq, "The returned sequence did not match the base sequence we created the feature with.");
  47. // Now check we can get the derived sequence based using the mRNA.
  48. $returned_seq_results = chado_get_feature_sequences([
  49. 'feature_id' => $mRNA_feature->feature_id
  50. ], ['is_html' => FALSE, 'width' => 100, 'derive_from_parent' => 1]);
  51. $this->assertCount(2, $returned_seq_results, 'We added two locations therefore we should have two returned sequences.');
  52. $this->assertEquals(
  53. str_repeat('A', 25),
  54. $returned_seq_results[0]['residues'],
  55. 'The first region located on the base was not returned correctly.'
  56. );
  57. $this->assertEquals(
  58. str_repeat('C', 50),
  59. $returned_seq_results[1]['residues'],
  60. 'The second region located on the base was not returned correctly.'
  61. );
  62. // Now change our featurelocs to be on the negative strand.
  63. // Note: fmin/fmax do not change because they are always the leftmost not
  64. // necessarily the start or 5' end.
  65. chado_delete_record('featureloc',
  66. ['srcfeature_id' => $base_feature->feature_id]);
  67. chado_insert_record('featureloc', [
  68. 'feature_id' => $mRNA_feature->feature_id,
  69. 'srcfeature_id' => $base_feature->feature_id,
  70. 'fmin' => 3,
  71. 'fmax' => (3 + 25),
  72. 'strand' => -1,
  73. 'rank' => 0,
  74. ]);
  75. chado_insert_record('featureloc', [
  76. 'feature_id' => $mRNA_feature->feature_id,
  77. 'srcfeature_id' => $base_feature->feature_id,
  78. 'fmin' => (3 + 25 + 10),
  79. 'fmax' => (3 + 25 + 10 + 50),
  80. 'strand' => -1,
  81. 'rank' => 1,
  82. ]);
  83. // Now check we can get the derived sequence based using the negative mRNA.
  84. $returned_seq_results = chado_get_feature_sequences([
  85. 'feature_id' => $mRNA_feature->feature_id
  86. ], ['is_html' => FALSE, 'width' => 100, 'derive_from_parent' => 1]);
  87. $this->assertCount(2, $returned_seq_results, 'We added two locations therefore we should have two returned sequences.');
  88. $this->assertEquals(
  89. str_repeat('G', 50),
  90. $returned_seq_results[0]['residues'],
  91. 'The first region located on the base was not returned correctly.'
  92. );
  93. $this->assertEquals(
  94. str_repeat('T', 25),
  95. $returned_seq_results[1]['residues'],
  96. 'The second region located on the base was not returned correctly.'
  97. );
  98. }
  99. }