OBOImporterTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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', 'biological_process')
  40. ->execute()
  41. ->fetchField();
  42. $this->assertNotFalse($exists);
  43. $exists = db_select('chado.cv', 'c')
  44. ->fields('c', ['cv_id'])
  45. ->condition('name', 'cellular_component')
  46. ->execute()
  47. ->fetchField();
  48. $this->assertNotFalse($exists);
  49. $exists = db_select('chado.cv', 'c')
  50. ->fields('c', ['cv_id'])
  51. ->condition('name', 'molecular_function')
  52. ->execute()
  53. ->fetchField();
  54. $this->assertNotFalse($exists);
  55. $sql = "
  56. SELECT DISTINCT CVTP.value
  57. FROM {cvtermprop} CVTP
  58. INNER JOIN {cvterm} CVTPT on CVTPT.cvterm_id = CVTP.type_id
  59. INNER JOIN {cvterm} CVT on CVT.cvterm_id = CVTP.cvterm_id
  60. INNER JOIN {dbxref} DBX on CVT.dbxref_id = DBX.dbxref_id
  61. INNER JOIN {db} DB on DB.db_id = DBX.db_id
  62. WHERE CVTPT.name = 'Subgroup' and DB.name = 'GO' and CVTP.value = 'goslim_plant'
  63. ";
  64. $exists = chado_query($sql)->fetchField();
  65. $this->assertNotFalse($exists);
  66. }
  67. private function load_obo($name,$path){
  68. $obo_id = db_select('public.tripal_cv_obo', 't')
  69. ->fields('t', ['obo_id'])
  70. ->condition('t.name', $name)
  71. ->execute()
  72. ->fetchField();
  73. if (!$obo_id) {
  74. $obo_id = db_insert('public.tripal_cv_obo')
  75. ->fields(['name' => $name, 'path' => $path])
  76. ->execute();
  77. }
  78. $run_args = ['obo_id' => $obo_id];
  79. module_load_include('inc', 'tripal_chado', 'includes/TripalImporter/OBOImporter');
  80. $importer = new \OBOImporter();
  81. $importer->create($run_args);
  82. $importer->prepareFiles();
  83. $importer->run();
  84. }
  85. /**
  86. * @throws \Exception
  87. * @group obo
  88. * @ticket 525
  89. */
  90. public function test_relationships_in_SO_exist() {
  91. // step 1: drop the SO CV and CASCADE.
  92. $result = chado_query("DELETE FROM {cv} WHERE name = 'sequence'");
  93. $result = chado_query("DELETE FROM {db} WHERE name = 'SO'");
  94. // step 2: re-add SO.
  95. $name = 'Sequence Ontology';
  96. $path = 'http://purl.obolibrary.org/obo/so.obo';
  97. $this->load_obo($name, $path);
  98. $sql = "SELECT CVT.name, CVTSYN.synonym
  99. FROM {cvterm} CVT
  100. INNER JOIN {dbxref} DBX on DBX.dbxref_id = CVT.dbxref_id
  101. INNER JOIN {db} on DB.db_id = DBX.db_id
  102. LEFT JOIN {cvtermsynonym} CVTSYN on CVTSYN.cvterm_id = CVT.cvterm_id
  103. WHERE DB.name = 'SO' and CVT.name = 'supercontig'
  104. ORDER BY DBX.accession";
  105. $results = chado_query($sql)->fetchAll();
  106. $result = $results[0];
  107. $this->assertNotNull($result);
  108. $this->assertNotEmpty($result);
  109. $this->assertEquals("scaffold", $result->synonym);
  110. }
  111. }