OBOImporterTest.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  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. * A helper function for loading any OBO.
  10. *
  11. * @param $name - ontology name. This goes in the tripal_cv_obo table.
  12. * @param $path - path to the OBO. this can be a file path or a URL.
  13. *
  14. * @throws \Exception
  15. */
  16. private function loadOBO($name, $path) {
  17. $obo_id = db_select('public.tripal_cv_obo', 't')
  18. ->fields('t', ['obo_id'])
  19. ->condition('t.name', $name)
  20. ->execute()
  21. ->fetchField();
  22. if (!$obo_id) {
  23. $obo_id = db_insert('public.tripal_cv_obo')
  24. ->fields(['name' => $name, 'path' => $path])
  25. ->execute();
  26. }
  27. $run_args = ['obo_id' => $obo_id];
  28. module_load_include('inc', 'tripal_chado', 'includes/TripalImporter/OBOImporter');
  29. $importer = new \OBOImporter();
  30. $importer->create($run_args);
  31. $importer->prepareFiles();
  32. $importer->run();
  33. }
  34. /**
  35. * Tests that an OBO from a remote URL can be loaded.
  36. *
  37. * For this test we will use the GO Plant Slim.
  38. *
  39. * @group obo
  40. */
  41. public function testRemoteOBO() {
  42. $name = 'core_test_goslim_plant';
  43. $path = 'http://www.geneontology.org/ontology/subsets/goslim_plant.obo';
  44. $this->loadOBO($name, $path);
  45. // Test that we get all three vocabularies added: biological_process,
  46. // cellular_component and molecular_function.
  47. $bp_cv_id = db_select('chado.cv', 'c')
  48. ->fields('c', ['cv_id'])
  49. ->condition('name', 'biological_process')
  50. ->execute()
  51. ->fetchField();
  52. $this->assertNotFalse($bp_cv_id,
  53. "Missing the 'biological_process' cv record after loading the GO plant slim.");
  54. $cc_cv_id = db_select('chado.cv', 'c')
  55. ->fields('c', ['cv_id'])
  56. ->condition('name', 'cellular_component')
  57. ->execute()
  58. ->fetchField();
  59. $this->assertNotFalse($cc_cv_id,
  60. "Missing the 'cellular_component' cv record after loading the GO plant slim.");
  61. $mf_cv_id = db_select('chado.cv', 'c')
  62. ->fields('c', ['cv_id'])
  63. ->condition('name', 'molecular_function')
  64. ->execute()
  65. ->fetchField();
  66. $this->assertNotFalse($mf_cv_id,
  67. "Missing the 'molecular_function' cv record after loading the GO plant slim.");
  68. // Make sure we have a proper database record.
  69. $go_db_id = db_select('chado.db', 'd')
  70. ->fields('d', ['db_id'])
  71. ->condition('name', 'GO')
  72. ->execute()
  73. ->fetchField();
  74. $this->assertNotFalse($go_db_id,
  75. "Missing the 'GO' database record after loading the GO plant slim.");
  76. }
  77. /**
  78. * Tests that an OBO from a local path can be loaded.
  79. *
  80. * For this test we will use a test ontology.
  81. *
  82. * @group obo
  83. */
  84. public function testLocalOBO() {
  85. $name = 'tripal_obo_test';
  86. $path = __DIR__ . '/../example_files/test.obo';
  87. $this->loadOBO($name, $path);
  88. // Make sure we have a proper vocabulary record.
  89. $tot_cv_id = db_select('chado.cv', 'c')
  90. ->fields('c', ['cv_id'])
  91. ->condition('name', 'tripal_obo_test')
  92. ->execute()
  93. ->fetchField();
  94. $this->assertNotFalse($tot_cv_id,
  95. "Missing the 'tripal_obo_test' cv record after loading the test.obo file");
  96. // Make sure we have a proper database record.
  97. $tot_db_id = db_select('chado.db', 'd')
  98. ->fields('d', ['db_id'])
  99. ->condition('name', 'TOT')
  100. ->execute()
  101. ->fetchField();
  102. $this->assertNotFalse($tot_db_id,
  103. "Missing the 'TOT' db record after loading the test.obo file");
  104. return [[$tot_cv_id, $tot_db_id]];
  105. }
  106. /**
  107. * Test that all nodes in our test OBO are loaded.
  108. *
  109. * @group obo
  110. * @dataProvider testLocalOBO
  111. */
  112. public function testCVterms($cv_id, $db_id) {
  113. // Our test OBO has 14 nodes.
  114. $nodes = [
  115. ['TOT:001' => 'node01'],
  116. ['TOT:002' => 'node02'],
  117. ['TOT:003' => 'node03'],
  118. ['TOT:004' => 'node04'],
  119. ['TOT:005' => 'node05'],
  120. ['TOT:006' => 'node06'],
  121. ['TOT:007' => 'node07'],
  122. ['TOT:008' => 'node08'],
  123. ['TOT:009' => 'node09'],
  124. ['TOT:010' => 'node10'],
  125. ['TOT:011' => 'node11'],
  126. ['TOT:012' => 'node12'],
  127. ['TOT:013' => 'node13'],
  128. ['TOT:014' => 'node14'],
  129. ];
  130. // Test that the proper records were added to identify the term.
  131. foreach ($nodes as $id => $node_name) {
  132. // Check that cvterm record is inserted.
  133. $cvterm_id = db_select('chado.cvterm', 'cvt')
  134. ->fields('cvt', ['cvterm_id'])
  135. ->condition('cvt.name', $node_name)
  136. ->condition('cvt.cv_id', $cv_id)
  137. ->execute()
  138. ->fetchField();
  139. $this->assertNotFalse($cvterm_id,
  140. "Missing the cvterm record with name, '$node' after loading the test.obo file");
  141. // Check that the dbxref record is inserted.
  142. $accession = preg_replace('/TOT:/', '', $id);
  143. $dbxref_id = db_select('chado.dbxref', 'dbx')
  144. ->fields('dbx', ['dbxref_id'])
  145. ->condition('accession', $accession)
  146. ->condition('db_id', $db_id);
  147. $this->assertNotFalse($cvterm_id,
  148. "Missing the dbxref record forid, '$id' after loading the test.obo file");
  149. }
  150. // Test node 11 to make sure the definition was inserted correctly.
  151. // The definition for node11 has an extra colon and a comment. The colon
  152. // should not throw off the insertion of the full definition and
  153. // the comment should be excluded.
  154. $def = db_select('chado.cvterm', 'cvt')
  155. ->fields('cvt', ['definition'])
  156. ->condition('cvt.name', 'node11')
  157. ->condition('cvt.cv_id', $cv_id)
  158. ->execute()
  159. ->fetchField();
  160. $this->assertNotFalse($def,
  161. "The definition for node11 was not added.");
  162. $this->assertEquals('This is node 11 : Yo', $def,
  163. "The definition for node11 is incorrect. it was stored as \"$def\" but should be \"def: This is node 11 : Yo\".");
  164. // Make sure that colons in term names don't screw up the term. This test
  165. // corresponds to the term with id CHEBI:132502 in the test.obo file.
  166. $exists = db_select('chado.cv', 'c')
  167. ->fields('c', ['cv_id'])
  168. ->condition('name', 'fatty acid 18')
  169. ->execute()
  170. ->fetchField();
  171. $this->assertFalse($exists);
  172. // Node14 should be marked as obsolete.
  173. $sql = "
  174. SELECT CVT.is_obsolete
  175. FROM {cvterm} CVT
  176. INNER JOIN {dbxref} DBX on DBX.dbxref_id = CVT.dbxref_id
  177. INNER JOIN {db} DB on DB.db_id = DBX.db_id
  178. WHERE DB.name = 'TOT' and DBX.accession = '014'
  179. ";
  180. $is_obsolete = chado_query($sql)->fetchField();
  181. $this->assertEquals(1, $is_obsolete,
  182. "The term, node14, should be marked as obsolete after loading of the test.obo file.");
  183. // Every vocabulary should have an is_a term added to support the is_a
  184. // relationships.
  185. $sql = "
  186. SELECT CVT.is_relationshiptype
  187. FROM {cvterm} CVT
  188. INNER JOIN {dbxref} DBX on DBX.dbxref_id = CVT.dbxref_id
  189. INNER JOIN {db} DB on DB.db_id = DBX.db_id
  190. WHERE CVT.name = 'is_a' and DB.name = 'TOT'
  191. ";
  192. $is_reltype = chado_query($sql)->fetchField();
  193. $this->assertNotFalse($is_reltype,
  194. "The cvterm record for, is_a, should have been added during loading of the test.obo file.");
  195. $this->assertEquals(1, $is_reltype,
  196. "The cvterm record, is_a, should be marked as a relationship type.");
  197. }
  198. /**
  199. * Test that insertion of synonyms works.
  200. *
  201. * The term 'node11' has a synonym:"crazy node" EXACT []
  202. *
  203. * @group obo
  204. * @dataProvider testLocalOBO
  205. */
  206. public function testSynonyms($cv_id, $db_id) {
  207. $query = db_select('chado.cvtermsynonym', 'cvts');
  208. $query->fields('cvts', ['synonym']);
  209. $query->join('chado.cvterm', 'cvt', 'cvts.cvterm_id = cvt.cvterm_id');
  210. $query->condition('cvt.name', 'node11');
  211. $synonym = $query->execute()->fetchField();
  212. $this->assertNotFalse($synonym,
  213. "Failed to find the 'crazy node' synonym record for node 11 after loading the test.obo file.");
  214. $this->assertEquals("crazy node", $synonym,
  215. "Failed to properly add the 'crazy node' synonym for node 11 instead the following was loaded: $synonym");
  216. }
  217. /**
  218. * Test that insertion of subset works.
  219. *
  220. * The term 'node11' belongs to the test_crazy subset. Everything else belongs
  221. * to the test_normal subset.
  222. *
  223. *
  224. * @group obo
  225. * @dataProvider testLocalOBO
  226. */
  227. public function testSubset($cv_id, $db_id) {
  228. $sql = "
  229. SELECT CVT.name
  230. FROM {cvtermprop} CVTP
  231. INNER JOIN {cvterm} CVTPT on CVTPT.cvterm_id = CVTP.type_id
  232. INNER JOIN {cvterm} CVT on CVT.cvterm_id = CVTP.cvterm_id
  233. INNER JOIN {dbxref} DBX on CVT.dbxref_id = DBX.dbxref_id
  234. INNER JOIN {db} DB on DB.db_id = DBX.db_id
  235. WHERE CVTPT.name = 'Subgroup' and DB.name = 'TOT' and CVTP.value = 'test_crazy'
  236. ";
  237. $term_name = chado_query($sql)->fetchField();
  238. $this->assertNotFalse($term_name,
  239. "This cvtermprop record for the subset 'test_crazy' is missing.");
  240. $this->assertEquals('node11', $term_name,
  241. "This cvtermprop record for the subset 'test_crazy' is assigned to term, $term_name, instead of node11.");
  242. $sql = "
  243. SELECT count(CVT.cvterm_id)
  244. FROM {cvtermprop} CVTP
  245. INNER JOIN {cvterm} CVTPT on CVTPT.cvterm_id = CVTP.type_id
  246. INNER JOIN {cvterm} CVT on CVT.cvterm_id = CVTP.cvterm_id
  247. INNER JOIN {dbxref} DBX on CVT.dbxref_id = DBX.dbxref_id
  248. INNER JOIN {db} DB on DB.db_id = DBX.db_id
  249. WHERE CVTPT.name = 'Subgroup' and DB.name = 'TOT' and CVTP.value = 'test_normal'
  250. ";
  251. $subset_count = chado_query($sql)->fetchField();
  252. $this->assertNotFalse($subset_count,
  253. "This cvtermprop record for the subset 'test_normal' are missing.");
  254. // There should be 12 terms that belong to subset 'test_normal' as node14
  255. // does not belong to a subset.
  256. $this->assertEquals(12, $subset_count,
  257. "There are $subset_count cvtermprop record for the subset 'test_normal' but there should be 13.");
  258. }
  259. /**
  260. * Test that the insertion of xref works.
  261. *
  262. * The term 'node11' belongs to the test_crazy subset. Everything else belongs
  263. * to the test_normal subset.
  264. *
  265. *
  266. * @group obo
  267. * @dataProvider testLocalOBO
  268. */
  269. public function testXref($cv_id, $db_id) {
  270. $sql = "
  271. SELECT concat(DB2.name, ':', DBX2.accession)
  272. FROM {cvterm} CVT
  273. INNER JOIN {dbxref} DBX on DBX.dbxref_id = CVT.dbxref_id
  274. INNER JOIN {db} on DB.db_id = DBX.db_id
  275. INNER JOIN {cvterm_dbxref} CVTDBX on CVTDBX.cvterm_id = CVT.cvterm_id
  276. INNER JOIN {dbxref} DBX2 on DBX2.dbxref_id = CVTDBX.dbxref_id
  277. INNER JOIN {db} DB2 on DB2.db_id = DBX2.db_id
  278. WHERE DB.name = 'TOT' and CVT.name = 'node11'
  279. ORDER BY DBX.accession
  280. ";
  281. $xref_id = chado_query($sql)->fetchField();
  282. $this->assertNotFalse($xref_id,
  283. "This cvterm_dbxref record for the xref 'GO:0043226' is missing for node11.");
  284. $this->assertEquals('GO:0043226', $xref_id,
  285. "This cvterm_dbxref record for node 11 is, $xref_id, instead of GO:0043226.");
  286. }
  287. /**
  288. * Test that the insertion of comments works.
  289. *
  290. * The term 'node11' contains a comment.
  291. *
  292. * @group obo
  293. * @dataProvider testLocalOBO
  294. */
  295. public function testComment($cv_id, $db_id) {
  296. $sql = "
  297. SELECT CVTP.value
  298. FROM {cvterm} CVT
  299. INNER JOIN {dbxref} DBX on DBX.dbxref_id = CVT.dbxref_id
  300. INNER JOIN {db} on DB.db_id = DBX.db_id
  301. INNER JOIN {cvtermprop} CVTP on CVTP.cvterm_id = CVT.cvterm_id
  302. INNER JOIN {cvterm} CVTPT on CVTPT.cvterm_id = CVTP.type_id
  303. WHERE DB.name = 'TOT' and CVTPT.name = 'comment' and CVT.name = 'node11'
  304. ORDER BY DBX.accession
  305. ";
  306. $comment = chado_query($sql)->fetchField();
  307. $this->assertNotFalse($xref_id,
  308. "This cvterm_dbxref record for the xref 'This is a crazy node' is missing for node11.");
  309. $this->assertEquals('This is a crazy node', $comment,
  310. "This cvterm_dbxref record for node11 is, \"$comment\", instead of \"This is a crazy node\".");
  311. }
  312. /**
  313. * Tests that the cvtermpath is properly loaded.
  314. *
  315. * @group obo
  316. * @dataProvider testLocalOBO
  317. */
  318. public function testRelationships($cv_id, $db_id) {
  319. $relationships = [
  320. ['node02', 'is_a', 'node01'],
  321. ['node03', 'is_a', 'node01'],
  322. ['node04', 'is_a', 'node01'],
  323. ['node04', 'has_part', 'node11'],
  324. ['node05', 'is_a', 'node01'],
  325. ['node06', 'is_a', 'node03'],
  326. ['node07', 'is_a', 'node03'],
  327. ['node08', 'is_a', 'node07'],
  328. ['node09', 'is_a', 'node04'],
  329. ['node09', 'is_a', 'node07'],
  330. ['node10', 'is_a', 'node05'],
  331. ['node11', 'is_a', 'node09'],
  332. ['node11', 'is_a', 'node10'],
  333. ['node12', 'is_a', 'node10'],
  334. ['node13', 'is_a', 'node11'],
  335. ];
  336. foreach ($relationships as $relationship) {
  337. $subject = $relationship[0];
  338. $type = $relationship[1];
  339. $object = $relationship[2];
  340. $sql = "
  341. SELECT CVTR.cvterm_relationship_id
  342. FROM {cvterm} CVT
  343. INNER JOIN {dbxref} DBX on DBX.dbxref_id = CVT.dbxref_id
  344. INNER JOIN {db} on DB.db_id = DBX.db_id
  345. INNER JOIN {cvterm_relationship} CVTR on CVTR.subject_id = CVT.cvterm_id
  346. INNER JOIN {cvterm} CVT2 on CVT2.cvterm_id = CVTR.object_id
  347. INNER JOIN {cvterm} CVT3 on CVT3.cvterm_id = CVTR.type_id
  348. WHERE DB.name = 'TOT' AND CVT2.name = :object AND
  349. CVT3.name = :type AND CVT.name = :subject
  350. ";
  351. $args = [':object' => $object, ':type' => $type, ':subject' => $subject];
  352. $rel_id = chado_query($sql, $args)->fetchField();
  353. $this->assertNotFalse($rel_id,
  354. "The following relationship could not be found: $subect $type $object.");
  355. }
  356. // Now make sure we have no more relationships than what we are supposed
  357. // to have.
  358. $sql = "
  359. SELECT count(CVTR.cvterm_relationship_id)
  360. FROM {cvterm} CVT
  361. INNER JOIN {dbxref} DBX on DBX.dbxref_id = CVT.dbxref_id
  362. INNER JOIN {db} on DB.db_id = DBX.db_id
  363. INNER JOIN {cvterm_relationship} CVTR on CVTR.object_id = CVT.cvterm_id
  364. WHERE DB.name = 'TOT' AND CVT.is_relationshiptype = 0
  365. ";
  366. $rel_count = chado_query($sql)->fetchField();
  367. $expected = count($relationships);
  368. $this->assertEquals($expected, $rel_count,
  369. "There are an incorrect number of relationships. There were $rel_count found but there should be $expected.");
  370. }
  371. /**
  372. * Tests that the cvtermpath is properly loaded.
  373. *
  374. * @group obo
  375. * @dataProvider testLocalOBO
  376. */
  377. public function testCVtermPath($cv_id, $db_id) {
  378. // For now we won't include distance or type in the check because depending
  379. // how the tree was loaded and if there are multiple paths to a node
  380. // then there's no guarantee we'll always get the same path. Therefore the
  381. // type and pathdistance may be different (althoug not incorrect).
  382. $relationships = [
  383. // Node01 as root: note that the root term always has a link to itself
  384. // in the cvtermpath table.
  385. ['node01', 'node01'],
  386. ['node01', 'node02'],
  387. ['node01', 'node03'],
  388. ['node01', 'node04'],
  389. ['node01', 'node05'],
  390. ['node01', 'node06'],
  391. ['node01', 'node07'],
  392. ['node01', 'node08'],
  393. ['node01', 'node09'],
  394. ['node01', 'node10'],
  395. ['node01', 'node11'],
  396. ['node01', 'node12'],
  397. ['node01', 'node13'],
  398. // Node03 as root.
  399. ['node03', 'node04'],
  400. ['node03', 'node06'],
  401. ['node03', 'node07'],
  402. ['node03', 'node08'],
  403. ['node03', 'node09'],
  404. ['node03', 'node11'],
  405. ['node03', 'node13'],
  406. // Node04 as root.
  407. ['node04', 'node09'],
  408. ['node04', 'node11'],
  409. ['node04', 'node13'],
  410. // Node05 as root.
  411. ['node05', 'node04'],
  412. ['node05', 'node09'],
  413. ['node05', 'node10'],
  414. ['node05', 'node11'],
  415. ['node05', 'node12'],
  416. ['node05', 'node13'],
  417. // Node07 as root.
  418. ['node07', 'node04'],
  419. ['node07', 'node08'],
  420. ['node07', 'node09'],
  421. ['node07', 'node11'],
  422. ['node07', 'node13'],
  423. // Node09 as root.
  424. ['node09', 'node04'],
  425. ['node09', 'node11'],
  426. ['node09', 'node13'],
  427. // Node10 as root.
  428. ['node10', 'node04'],
  429. ['node10', 'node09'],
  430. ['node10', 'node11'],
  431. ['node10', 'node12'],
  432. ['node10', 'node13'],
  433. // Node11 as root.
  434. ['node11', 'node04'],
  435. ['node11', 'node09'],
  436. ['node11', 'node13'],
  437. ];
  438. // Populate the cvtermpath for our test OBO.
  439. chado_update_cvtermpath($cv_id);
  440. foreach ($relationships as $relationship) {
  441. $object = $relationship[0];
  442. $subject = $relationship[1];
  443. $sql = "
  444. SELECT cvtermpath_id
  445. FROM {cvtermpath} CVTP
  446. INNER JOIN {cvterm} CVTO on CVTO.cvterm_id = CVTP.object_id
  447. INNER JOIN {cvterm} CVTS on CVTS.cvterm_id = CVTP.subject_id
  448. INNER JOIN {cvterm} CVTT on CVTT.cvterm_id = CVTP.type_id
  449. WHERE CVTP.cv_id = :cv_id and CVTO.name = :object and
  450. CVTS.name = :subject
  451. ";
  452. $args = [
  453. ':cv_id' => $cv_id,
  454. ':object' => $object,
  455. ':subject' => $subject,
  456. ];
  457. $cvtermpath_id = chado_query($sql, $args)->fetchField();
  458. $this->assertNotFalse($cvtermpath_id,
  459. "Cound not find the cvtermpath record for the relationship: $subject => $object.");
  460. }
  461. // Now make sure we have no additional entries.
  462. $sql = "
  463. SELECT count(cvtermpath_id)
  464. FROM {cvtermpath} CVTP
  465. INNER JOIN {cvterm} CVTO on CVTO.cvterm_id = CVTP.object_id
  466. INNER JOIN {cvterm} CVTS on CVTS.cvterm_id = CVTP.subject_id
  467. INNER JOIN {cvterm} CVTT on CVTT.cvterm_id = CVTP.type_id
  468. WHERE CVTP.cv_id = :cv_id
  469. ";
  470. $args = [':cv_id' => $cv_id];
  471. $rel_count = chado_query($sql, $args)->fetchField();
  472. $expected = count($relationships);
  473. $this->assertEquals($expected, $rel_count,
  474. "There are an incorrect number of paths. There were $rel_count found but there should be $expected.");
  475. }
  476. /**
  477. * Tests that the EBI Lookup is properly working.
  478. *
  479. * The term CHEBI:132502 should have been loaded via EBI.
  480. *
  481. * @group obo
  482. * @dataProvider testLocalOBO
  483. */
  484. public function testEBILookup($cv_id, $db_id) {
  485. $sql = "
  486. SELECT CVT.cvterm_id
  487. FROM {cvterm} CVT
  488. INNER JOIN {dbxref} DBX on DBX.dbxref_id = CVT.dbxref_id
  489. INNER JOIN {db} DB on DB.db_id = DBX.db_id
  490. WHERE DB.name = 'CHEBI' and DBX.accession = '132502'
  491. ";
  492. $cvterm_id = chado_query($sql)->fetchField();
  493. $this->assertNotFalse($cvterm_id,
  494. "The term, CHEBI:132502, is not present the EBI OLS lookup must not have succeeded.");
  495. }
  496. /**
  497. * Tests when changes are made between OBO loads.
  498. *
  499. * Sometimes an ontology can change the names of it's terms, or set some
  500. * as obsolete, etc. We need to makes sure that when changes are made and
  501. * the OBO is reloaded that the terms are properly update.
  502. *
  503. * @group obo
  504. * @dataProvider testLocalOBO
  505. */
  506. public function testOBOChanges($cv_id, $db_id) {
  507. $name = 'tripal_obo_test_update';
  508. $path = __DIR__ . '/../example_files/test.update.obo';
  509. $this->loadOBO($name, $path);
  510. // Did the name of term 13 change?
  511. $sql = "
  512. SELECT CVT.name
  513. FROM {cvterm} CVT
  514. INNER JOIN {dbxref} DBX on DBX.dbxref_id = CVT.dbxref_id
  515. INNER JOIN {db} DB on DB.db_id = DBX.db_id
  516. WHERE DB.name = 'TOT' and DBX.accession = '013'
  517. ";
  518. $name = chado_query($sql)->fetchField();
  519. $this->assertEquals('New name 13.', $name,
  520. "The name for node13 (TOT:013) failed to update to 'New name 13'.");
  521. // Node15 is new, and node02 got removed. Node15 now uses node02's name and
  522. // has TOT:002 as an alt_id. So, node02 should be marked as obsolete
  523. $sql = "
  524. SELECT CVT.is_obsolete
  525. FROM {cvterm} CVT
  526. INNER JOIN {dbxref} DBX on DBX.dbxref_id = CVT.dbxref_id
  527. INNER JOIN {db} DB on DB.db_id = DBX.db_id
  528. WHERE DB.name = 'TOT' and DBX.accession = '002'
  529. ";
  530. $is_obsolete = chado_query($sql)->fetchField();
  531. $this->assertEquals(1, $is_obsolete,
  532. "The node02 (TOT:002) should be marked as obsolete after update.");
  533. // Node16 is new, and node08 is now obsolete. Node16 now uses node08's name,
  534. // so, node08 should be marked as obsolete and have the word '(obsolete)'
  535. // added to prevent future conflicts.
  536. $sql = "
  537. SELECT CVT.name
  538. FROM {cvterm} CVT
  539. INNER JOIN {dbxref} DBX on DBX.dbxref_id = CVT.dbxref_id
  540. INNER JOIN {db} DB on DB.db_id = DBX.db_id
  541. WHERE DB.name = 'TOT' and DBX.accession = '008'
  542. ";
  543. $name = chado_query($sql)->fetchField();
  544. $this->assertEquals("node08 (obsolete)", $name,
  545. "The node08 (TOT:008) should be marked as obsolete after update.");
  546. }
  547. /**
  548. * @group obo
  549. * @group chado
  550. */
  551. public function testfindEBITerm_finder_retrieves_term() {
  552. module_load_include('inc', 'tripal_chado', 'includes/TripalImporter/OBOImporter');
  553. $importer_private = new \OBOImporter();
  554. $importer = reflect($importer_private);
  555. $id = 'PECO:0007085';
  556. $result = $importer->findEBITerm($id);
  557. $this->assertNotEmpty($result);
  558. $this->assertEquals('fertilizer exposure', $result['name'][0]);
  559. }
  560. }