OBOImporterTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace Tests;
  3. use StatonLab\TripalTestSuite\DBTransaction;
  4. use StatonLab\TripalTestSuite\TripalTestCase;
  5. class OBOImporterTest extends TripalTestCase {
  6. // Uncomment to auto start and rollback db transactions per test method.
  7. use DBTransaction;
  8. /**
  9. * @group obo
  10. * @ticket 525
  11. */
  12. public function test_PTO_loads_colon_issue() {
  13. $name = 'core_test_PTO_mini';
  14. $path = __DIR__ . '/../example_files/pto_colon.obo';
  15. $this->load_obo($name, $path);
  16. $exists = db_select('chado.cv', 'c')
  17. ->fields('c', ['cv_id'])
  18. ->condition('name', 'core_test_PTO_mini')
  19. ->execute()
  20. ->fetchField();
  21. $this->assertNotFalse($exists);
  22. //hte colon splitting issue: a new CV will created named fatty acid 18
  23. $exists = db_select('chado.cv', 'c')
  24. ->fields('c', ['cv_id'])
  25. ->condition('name', 'fatty acid 18')
  26. ->execute()
  27. ->fetchField();
  28. $this->assertFalse($exists);
  29. }
  30. /**
  31. * @group obo
  32. */
  33. public function testGO_SLIM_load() {
  34. $name = 'core_test_goslim_plant';
  35. $path = 'http://www.geneontology.org/ontology/subsets/goslim_plant.obo';
  36. $this->load_obo($name, $path);
  37. $exists = db_select('chado.cv', 'c')
  38. ->fields('c', ['cv_id'])
  39. ->condition('name', 'core_test_goslim_plant')
  40. ->execute()
  41. ->fetchField();
  42. $this->assertNotFalse($exists);
  43. }
  44. private function load_obo($name,$path){
  45. $obo_id = db_select('public.tripal_cv_obo', 't')
  46. ->fields('t', ['obo_id'])
  47. ->condition('t.name', $name)
  48. ->execute()
  49. ->fetchField();
  50. if (!$obo_id) {
  51. $obo_id = db_insert('public.tripal_cv_obo')
  52. ->fields(['name' => $name, 'path' => $path])
  53. ->execute();
  54. }
  55. $run_args = ['obo_id' => $obo_id];
  56. module_load_include('inc', 'tripal_chado', 'includes/TripalImporter/OBOImporter');
  57. $importer = new \OBOImporter();
  58. $importer->create($run_args);
  59. $importer->prepareFiles();
  60. $importer->run();
  61. }
  62. /**
  63. * @throws \Exception
  64. * @group obo
  65. * @ticket 525
  66. */
  67. public function test_relationships_in_SO_exist() {
  68. // step 1: drop the SO CV and CASCADE.
  69. $result = chado_query("DELETE FROM {cv} WHERE name = 'sequence'");
  70. $result = chado_query("DELETE FROM {db} WHERE name = 'SO'");
  71. // step 2: re-add SO.
  72. $name = 'Sequence Ontology';
  73. $path = 'http://purl.obolibrary.org/obo/so.obo';
  74. $this->load_obo($name, $path);
  75. $sql = "SELECT CVT.name, CVTSYN.synonym
  76. FROM {cvterm} CVT
  77. INNER JOIN {dbxref} DBX on DBX.dbxref_id = CVT.dbxref_id
  78. INNER JOIN {db} on DB.db_id = DBX.db_id
  79. LEFT JOIN {cvtermsynonym} CVTSYN on CVTSYN.cvterm_id = CVT.cvterm_id
  80. WHERE DB.name = 'SO' and CVT.name = 'supercontig'
  81. ORDER BY DBX.accession";
  82. $results = chado_query($sql)->fetchAll();
  83. $result = $results[0];
  84. $this->assertNotNull($result);
  85. $this->assertNotEmpty($result);
  86. $this->assertEquals("scaffold", $result->synonym);
  87. }
  88. }