OntologyLoader { public static Ontology loadOntology(File file) { return loadOntology(file, CurieUtilBuilder.defaultCurieUtil()); } private  OntologyLoader(); static Ontology loadOntology(File file); static Ontology loadOntology(File file, String... termIdPrefixes); static Ontology loadOntology(File file, CurieUtil curieUtil, String... termIdPrefixes); static Ontology loadOntology(InputStream inputStream); static Ontology loadOntology(InputStream inputStream, String... termIdPrefixes); static Ontology loadOntology(InputStream inputStream, CurieUtil curieUtil, String... termIdPrefixes); static Ontology loadOntology(GraphDocument graphDocument, CurieUtil curieUtil, String... termIdPrefixes);  }
@Test void loadOwl() { Path ontologyPath = Paths.get("src/test/resources/ncit_module.owl"); Ontology ontology = OntologyLoader.loadOntology(ontologyPath.toFile()); assertEquals(6, ontology.countAllTerms()); }
@Test void loadOwlStream() throws Exception { Path ontologyPath = Paths.get("src/test/resources/ncit_module.owl"); Ontology ontology = OntologyLoader.loadOntology(Files.newInputStream(ontologyPath)); assertEquals(6, ontology.countAllTerms()); }
@Test void loadObo() { Path ontologyPath = Paths.get("src/test/resources/ecto.obo"); Ontology ontology = OntologyLoader.loadOntology(ontologyPath.toFile()); assertNotNull(ontology); }
@Test void loadOboStream() throws Exception { Path ontologyPath = Paths.get("src/test/resources/ecto.obo"); Ontology ontology = OntologyLoader.loadOntology(Files.newInputStream(ontologyPath)); assertNotNull(ontology); }
@Test void loadJson() { Path ontologyPath = Paths.get("src/test/resources/hp_small.json"); Ontology ontology = OntologyLoader.loadOntology(ontologyPath.toFile()); assertEquals(5, ontology.countAllTerms()); }
@Test void loadJsonStream() throws Exception { Path ontologyPath = Paths.get("src/test/resources/hp_small.json"); Ontology ontology = OntologyLoader.loadOntology(Files.newInputStream(ontologyPath)); System.out.println(ontology.countAllTerms()); }
@Test void testNCITLoad() { Path ncitPath = Paths.get("src/test/resources/ncit_module.owl"); Ontology ontology = OntologyLoader.loadOntology(ncitPath.toFile(), "NCIT"); DefaultDirectedGraph<TermId, IdLabeledEdge> graph = ontology.getGraph(); TermId t1 = TermId.of("NCIT:C2919"); TermId t2 = TermId.of("NCIT:C2852"); TermId t3 = TermId.of("NCIT:C48596"); TermId t4 = TermId.of("NCIT:C60312"); TermId t5 = TermId.of("NCIT:C116977"); TermId t6 = TermId.of("NCIT:C126659"); assertTrue(graph.vertexSet().contains(t1)); assertTrue(graph.vertexSet().contains(t2)); assertTrue(graph.vertexSet().contains(t3)); assertTrue(graph.vertexSet().contains(t4)); assertTrue(graph.vertexSet().contains(t5)); assertFalse(graph.vertexSet().contains(t6)); assertEquals(4, graph.edgeSet().size()); assertNotNull(graph.getEdge(t1, t2)); assertNotNull(graph.getEdge(t1, t3)); assertTrue(ontology.getAllTermIds().contains(t1)); assertTrue(ontology.getAllTermIds().contains(t2)); assertTrue(ontology.getAllTermIds().contains(t3)); assertTrue(ontology.getAllTermIds().contains(t4)); assertTrue(ontology.getAllTermIds().contains(t5)); assertFalse(ontology.getAllTermIds().contains(t6)); Relationship gr1 = ontology.getRelationMap().get(graph.getEdge(t1, t2).getId()); Relationship gr2 = ontology.getRelationMap().get(graph.getEdge(t1, t3).getId()); assertNotNull(gr1); assertNotNull(gr2); assertEquals(RelationshipType.IS_A, gr1.getRelationshipType()); assertEquals(RelationshipType.IS_A, gr2.getRelationshipType()); assertEquals(TermId.of("owl:Thing"), ontology.getRootTermId()); }
@Test void testMONDOLoad() { Path mondoPath = Paths.get("src", "test", "resources", "mondo_module.owl"); Ontology ontology = OntologyLoader.loadOntology(mondoPath.toFile(), "MONDO"); List<String> xrefs = Arrays.asList( "DOID:0060111", "ICD10:D28.2", "MedDRA:10053865", "NCIT:C4517", "Orphanet:180237", "SCTID:92100009", "UMLS:C0346190"); for (Term gt : ontology.getTerms()) { for (Dbxref xref : gt.getXrefs()) { boolean containFlag = false; for (String xrefStr : xrefs) { if (xref.getName().contains(xrefStr)) { containFlag = true; break; } } if (!containFlag) fail("Xref " + xref.getName() + " is not available."); } } assertEquals(TermId.of("MONDO:0000624"), ontology.getRootTermId()); }
@Test void testLoadEctoSubset() { Path ectoPath = Paths.get("src/test/resources/ecto.obo"); Ontology ecto = OntologyLoader.loadOntology(ectoPath.toFile(), "ECTO"); ecto.getRelationMap() .values() .forEach(relationship -> assertEquals(RelationshipType.IS_A, relationship.getRelationshipType())); Term rootT = ecto.getTermMap().get(ecto.getRootTermId()); assertEquals("artificial root term", rootT.getName()); assertEquals(TermId.of("owl:Thing"), ecto.getRootTermId()); Set<String> termPrefixes = ecto.getAllTermIds().stream().map(TermId::getPrefix).collect(toSet()); assertFalse(termPrefixes.contains("NCIT")); assertFalse(termPrefixes.contains("CHEBI")); assertFalse(termPrefixes.contains("GO")); assertEquals(2271, ecto.countNonObsoleteTerms()); assertEquals(0, ecto.countAlternateTermIds()); }
@Test void testLoadEctoAll() { Path ectoPath = Paths.get("src/test/resources/ecto.obo"); Ontology permissiveOntology = OntologyLoader.loadOntology(ectoPath.toFile()); assertEquals(TermId.of("owl:Thing"), permissiveOntology.getRootTermId()); assertEquals(8343, permissiveOntology.countNonObsoleteTerms()); assertEquals(4, permissiveOntology.countAlternateTermIds()); Set<String> prefixes = permissiveOntology.getAllTermIds() .stream() .map(TermId::getPrefix) .collect(toSet()); assertTrue(prefixes.contains("NCIT")); assertTrue(prefixes.contains("CHEBI")); assertTrue(prefixes.contains("GO")); long ectoTermCount = permissiveOntology.getTermMap().values(). stream(). filter(term -> term.getId().getPrefix().equals("ECTO")). count(); assertEquals(2270, ectoTermCount); }