org.obolibrary.oboformat.model.OBODoc Java Examples
The following examples show how to use
org.obolibrary.oboformat.model.OBODoc.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AxiomAnnotationToolsTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Test for {@link AxiomAnnotationTools#reduceAxiomAnnotationsToOboBasic(org.semanticweb.owlapi.model.OWLOntology)}. * * @throws Exception */ @Test public void testReduceAxiomAnnotationsToOboBasicOWLOntology() throws Exception { final File inputFile = getResource("qualifiers/with-qualifiers.obo"); final File referenceFile = getResource("qualifiers/no-qualifiers.obo"); OBOFormatParser p = new OBOFormatParser(); OBODoc inputOboDoc = p.parse(inputFile); Obo2Owl obo2Owl = new Obo2Owl(); OWLOntology owlOntology = obo2Owl.convert(inputOboDoc); Owl2Obo owl2Obo = new Owl2Obo(); // check round-trip first before removing equals(inputFile, owl2Obo.convert(owlOntology)); // remove axiom annotations AxiomAnnotationTools.reduceAxiomAnnotationsToOboBasic(owlOntology); equals(referenceFile, owl2Obo.convert(owlOntology)); }
Example #2
Source File: OwlSimUtil.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * @param file * @return * @throws OWLOntologyCreationException * @throws IOException * @throws OBOFormatParserException */ public static OwlSim createOwlSimFromOntologyFile(File file) throws OWLOntologyCreationException, OBOFormatParserException, IOException { OWLOntologyManager m = OWLManager.createOWLOntologyManager(); OWLOntology ont; if (file.getPath().endsWith(".obo")) { OBOFormatParser p = new OBOFormatParser(); OBODoc obodoc = p.parse(file); Obo2Owl bridge = new Obo2Owl(m); ont = bridge.convert(obodoc); } else { ont = m.loadOntology(IRI.create(file)); } return new FastOwlSimFactory().createOwlSim(ont); }
Example #3
Source File: TaxonGraphTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Before public void before() throws Exception { LOG.debug("Setting up: " + this); List<String> files = new Vector<String>(); //files.add(getResource("cell_prolif_placenta.obo").getAbsolutePath()); files.add(getResource("ncbi_taxon_slim.obo").getAbsolutePath()); files.add(getResource("taxon_union_terms.obo").getAbsolutePath()); OBOFormatParser p = new OBOFormatParser(); Obo2Owl obo2Owl = new Obo2Owl(); OBODoc merged = null; for(String file : files) { OBODoc oboDoc = p.parse(file); if (merged == null) { merged = oboDoc; } else { merged.mergeContents(oboDoc); } } OWLOntology ont = obo2Owl.convert(merged); gw = new OWLGraphWrapper(ont); gw.getConfig().isGraphReasonedAndRelaxed = false; }
Example #4
Source File: CardinalityCheckAndRepairMooncatTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test and repair cardinalities of DEF and COMMENT tags after merging * ontologies (B contains MIREOTed terms from C) via {@link Mooncat}. * * @throws Exception */ @Test public void testMireot() throws Exception { ParserWrapper pw = new ParserWrapper(); OWLGraphWrapper g = pw.parseToOWLGraph(getResourceIRIString("mooncat/A.obo")); Mooncat m = new Mooncat(g); m.addReferencedOntology(pw.parseOBO(getResourceIRIString("mooncat/B.obo"))); m.addReferencedOntology(pw.parseOBO(getResourceIRIString("mooncat/C.obo"))); m.mergeOntologies(); OWLOntology sourceOntology = g.getSourceOntology(); OboInOwlCardinalityTools.checkAnnotationCardinality(sourceOntology); Owl2Obo owl2Obo = new Owl2Obo(); OBODoc oboDoc = owl2Obo.convert(sourceOntology); if (RENDER_ONTOLOGY_FLAG) { renderOBO(oboDoc); } Frame termFrame = oboDoc.getTermFrame("C:0000001"); Collection<Clause> defClauses = termFrame.getClauses(OboFormatTag.TAG_DEF); assertEquals(1, defClauses.size()); Collection<Clause> commentClauses = termFrame.getClauses(OboFormatTag.TAG_COMMENT); assertEquals(1, commentClauses.size()); }
Example #5
Source File: OWLGraphWrapperTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
private OWLGraphWrapper getOBO2OWLOntologyWrapper(String file) throws Exception{ OBOFormatParser p = new OBOFormatParser(); OBODoc obodoc = p.parse(new BufferedReader(new FileReader(getResource(file)))); Obo2Owl bridge = new Obo2Owl(); OWLOntology ontology = bridge.convert(obodoc); OWLGraphWrapper wrapper = new OWLGraphWrapper(ontology); return wrapper; }
Example #6
Source File: RetrieveRelationByLabelTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
private OWLGraphWrapper getOBO2OWLOntologyWrapper(String file) throws Exception{ OBOFormatParser p = new OBOFormatParser(); OBODoc obodoc = p.parse(new BufferedReader(new FileReader(getResource(file)))); Obo2Owl bridge = new Obo2Owl(); OWLOntology ontology = bridge.convert(obodoc); OWLGraphWrapper wrapper = new OWLGraphWrapper(ontology); return wrapper; }
Example #7
Source File: OWLToolsTestBasics.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
protected static String renderOBOtoString(OBODoc oboDoc) throws IOException { OBOFormatWriter writer = new OBOFormatWriter(); writer.setCheckStructure(true); StringWriter out = new StringWriter(); BufferedWriter stream = new BufferedWriter(out); writer.write(oboDoc, stream); stream.close(); return out.getBuffer().toString(); }
Example #8
Source File: IOHelper.java From robot with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Given an ontology, a document format, and a boolean indicating to check OBO formatting, return * the ontology file in the OWLDocumentFormat as a byte array. * * @param ontology OWLOntology to save * @param format OWLDocumentFormat to save in * @param checkOBO boolean indiciating to check OBO formatting * @return byte array of formatted ontology data * @throws IOException on any problem */ private byte[] getOntologyFileData( final OWLOntology ontology, OWLDocumentFormat format, boolean checkOBO) throws IOException { byte[] data; // first handle any non-official output formats. // currently this is just OboGraphs JSON format if (format instanceof OboGraphJsonDocumentFormat) { FromOwl fromOwl = new FromOwl(); GraphDocument gd = fromOwl.generateGraphDocument(ontology); String doc = OgJsonGenerator.render(gd); data = doc.getBytes(); } else if (format instanceof OBODocumentFormat && !checkOBO) { OWLAPIOwl2Obo bridge = new OWLAPIOwl2Obo(ontology.getOWLOntologyManager()); OBODoc oboOntology = bridge.convert(ontology); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(baos))) { OBOFormatWriter oboWriter = new OBOFormatWriter(); oboWriter.setCheckStructure(checkOBO); oboWriter.write(oboOntology, bw); } data = baos.toByteArray(); } else { try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { ontology.getOWLOntologyManager().saveOntology(ontology, format, baos); data = baos.toByteArray(); } catch (IOException | OWLOntologyStorageException e) { // TODO throw new IOException(e); } } return data; }
Example #9
Source File: SubsetDefMooncatTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test for missing comments and duplicate header entries. * * @throws Exception */ @Test public void testImportProperties2() throws Exception { ParserWrapper pw = new ParserWrapper(); OWLGraphWrapper g = pw.parseToOWLGraph(getResourceIRIString("mooncat/D.obo")); Mooncat m = new Mooncat(g); m.addReferencedOntology(pw.parseOBO(getResourceIRIString("mooncat/E-complex.obo"))); m.addReferencedOntology(pw.parseOBO(getResourceIRIString("mooncat/F.obo"))); m.mergeOntologies(); OWLOntology sourceOntology = g.getSourceOntology(); OboInOwlCardinalityTools.checkAnnotationCardinality(sourceOntology); Owl2Obo owl2Obo = new Owl2Obo(); OBODoc oboDoc = owl2Obo.convert(sourceOntology); if (RENDER_ONTOLOGY_FLAG) { renderOBO(oboDoc); } Frame headerFrame = oboDoc.getHeaderFrame(); List<Clause> clauses = new ArrayList<Clause>(headerFrame.getClauses(OboFormatTag.TAG_SUBSETDEF)); OBOFormatWriter.sortTermClauses(clauses); assertTrue(clauses.size() > 2); Clause prev = null; for(Clause clause : clauses) { String value = clause.getValue(String.class); assertNotNull(value); assertFalse(value.isEmpty()); String value2 = clause.getValue2(String.class); assertNotNull(value2); assertFalse(value2.isEmpty()); if (clause.equals(prev)) { fail("Duplicate clause: "+clause); } prev = clause; } }
Example #10
Source File: CardinalityContraintsToolsTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testRemoveCardinalityConstraints() throws Exception { OWLGraphWrapper graph = getGraph("cardinality.obo"); OWLOntology owlOntology = graph.getSourceOntology(); CardinalityContraintsTools.removeCardinalityConstraints(owlOntology); Owl2Obo owl2Obo = new Owl2Obo(); OBODoc obo = owl2Obo.convert(owlOntology); assertNoQualifiers("TEST:1000", obo); assertNoQualifiers("TEST:1001", obo); assertNoQualifiers("TEST:1002", obo); assertNoQualifiers("TEST:1003", obo); }
Example #11
Source File: ParserWrapper.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @param graph * @param oboDoc * * If an {@link OBODoc} is available use {@link OboAndOwlNameProvider}. */ @Deprecated public OWLGraphWrapperNameProvider(OWLGraphWrapper graph, OBODoc oboDoc) { super(); this.graph = graph; String defaultOboNamespace = null; if (oboDoc != null) { Frame headerFrame = oboDoc.getHeaderFrame(); if (headerFrame != null) { defaultOboNamespace = headerFrame.getTagValue(OboFormatTag.TAG_DEFAULT_NAMESPACE, String.class); } } this.defaultOboNamespace = defaultOboNamespace; }
Example #12
Source File: CardinalityContraintsToolsTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void assertNoQualifiers(String id, OBODoc obo) { Frame frame = obo.getTermFrame(id); Collection<Clause> clauses = frame.getClauses(OboFormatTag.TAG_INTERSECTION_OF); final String message = "Expected intersection clauses for id: "+id; assertNotNull(message, clauses); assertEquals(message, 2, clauses.size()); for (Clause clause : clauses) { Collection<QualifierValue> qualifierValues = clause.getQualifierValues(); if (qualifierValues != null && !qualifierValues.isEmpty()) { fail("No qualifiers expected, but was: "+frame); } } }
Example #13
Source File: OWLGsonRendererTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
private OWLGraphWrapper getOBO2OWLOntologyWrapper(String file) throws Exception{ OBOFormatParser p = new OBOFormatParser(); OBODoc obodoc = p.parse(new BufferedReader(new FileReader(getResource(file)))); Obo2Owl bridge = new Obo2Owl(); OWLOntology ontology = bridge.convert(obodoc); OWLGraphWrapper wrapper = new OWLGraphWrapper(ontology); return wrapper; }
Example #14
Source File: FlexTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testFlexReflectionLoading() throws IOException, OWLOntologyCreationException, OBOFormatParserException{ String fstr = FlexTest.class. getResource("/trivial.obo").getFile(); //ParserWrapper pw = new ParserWrapper(); //OWLGraphWrapper g = pw.parseOBOFiles(files); OBOFormatParser p = new OBOFormatParser(); OBODoc obodoc = p.parse(fstr); Obo2Owl bridge = new Obo2Owl(); OWLOntology ont = bridge.convert(obodoc); OWLGraphWrapper g = new OWLGraphWrapper(ont); // Get an object and a FlexCollection to play with. OWLObject a1 = g.getOWLObjectByIdentifier("A:0000001"); FlexCollection fc = new FlexCollection(g); // Trivial 1 List<String> sexpr_t1 = new ArrayList<String>(); sexpr_t1.add("getIdentifier"); String ans_t1 = fc.getExtString(a1, sexpr_t1, null); assertNotNull("Hope not!", ans_t1); assertEquals("Get identifier", "A:0000001", ans_t1); // Trivial 2 List<String> sexpr_t2 = new ArrayList<String>(); sexpr_t2.add("getLabel"); String ans_t2 = fc.getExtString(a1, sexpr_t2, null); assertEquals("Get label a1", "a1", ans_t2); // Non-trivial 1 List<String> sexpr_t3 = new ArrayList<String>(); sexpr_t3.add("getAnnotationPropertyValues"); sexpr_t3.add("alt_id"); List<String> ans_t3 = fc.getExtStringList(a1, sexpr_t3, null); assertTrue("Get label a1 alt_id a:0000001", ans_t3.contains("a:0000001")); assertTrue("Get label a1 alt_id AY:0000001", ans_t3.contains("AY:0000001")); }
Example #15
Source File: StanzaToOWLConverterTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
private OWLGraphWrapper getOBO2OWLOntologyWrapper(String file) throws Exception{ OBOFormatParser p = new OBOFormatParser(); OBODoc obodoc = p.parse(new BufferedReader(new FileReader(getResource(file)))); Obo2Owl bridge = new Obo2Owl(); OWLOntology ontology = bridge.convert(obodoc); OWLGraphWrapper wrapper = new OWLGraphWrapper(ontology); return wrapper; }
Example #16
Source File: AxiomAnnotationToolsTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
private static void equals(File reference, OBODoc oboDoc) throws IOException { String oboString = renderOBOtoString(oboDoc); String referenceString = FileUtils.readFileToString(reference); assertEquals(referenceString, oboString); }
Example #17
Source File: OWLToolsTestBasics.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
protected static void renderOBO(OBODoc oboDoc) throws IOException { LOG.debug(renderOBOtoString(oboDoc)); }
Example #18
Source File: RemoveDirectivesTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test public void testRemove() throws Exception { ParserWrapper pw = new ParserWrapper(); OWLGraphWrapper g = pw.parseToOWLGraph(getResourceIRIString("mooncat/remove-directives-test1.obo")); System.out.println(g.getSourceOntology().getAxioms(AxiomType.EQUIVALENT_CLASSES)); OWLOntology secondary = pw.parse(getResourceIRIString("mooncat/remove-directives-test2.obo")); System.out.println(secondary.getAxioms(AxiomType.EQUIVALENT_CLASSES)); g.addSupportOntology(secondary); Mooncat mooncat = new Mooncat(g); //mooncat.mergeOntologies(); g.mergeOntology(secondary); OWLOntology merged = g.getSourceOntology(); System.out.println(merged.getAxioms(AxiomType.EQUIVALENT_CLASSES)); Owl2Obo owl2Obo = new Owl2Obo(); OBODoc mergedObo = owl2Obo.convert(merged); if (USE_SYSTEM_OUT) { System.out.println("------------------------"); OWLOntologyManager manager = merged.getOWLOntologyManager(); OWLOntologyDocumentTarget documentTarget = new SystemOutDocumentTarget(); manager.saveOntology(merged, new RDFXMLDocumentFormat(), documentTarget); System.out.println("------------------------"); String oboString = renderOBOtoString(mergedObo); System.out.println(oboString); System.out.println("------------------------"); } Frame headerFrame = mergedObo.getHeaderFrame(); String owlAxiomString = headerFrame.getTagValue(OboFormatTag.TAG_OWL_AXIOMS, String.class); assertNotNull(owlAxiomString); Frame frame = mergedObo.getTermFrame("X:1"); Collection<Clause> clauses = frame.getClauses(OboFormatTag.TAG_INTERSECTION_OF); assertEquals(2, clauses.size()); }
Example #19
Source File: ParserWrapper.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
public OboAndOwlNameProvider(OBODoc oboDoc, OWLGraphWrapper wrapper) { super(oboDoc); this.graph = wrapper; }
Example #20
Source File: ParserWrapper.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
public OBODoc getOBOdoc() { return obodoc; }
Example #21
Source File: OWLGraphWrapperExtended.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
public IRI getIRIByIdentifier(String id, boolean isAutoResolve) { if (isAutoResolve) { OWLObject obj = this.getObjectByAltId(id); if (obj != null) { return ((OWLNamedObject) obj).getIRI(); } } // special magic for finding IRIs from a non-standard identifier // This is the case for relations (OWLObject properties) with a short hand // or for relations with a non identifiers with-out a colon, e.g. negative_regulation // we first collect all candidate matching properties in candIRISet. Set<IRI> candIRISet = Sets.newHashSet(); if (!id.contains(":")) { final OWLAnnotationProperty shortHand = getDataFactory().getOWLAnnotationProperty(Obo2OWLVocabulary.IRI_OIO_shorthand.getIRI()); final OWLAnnotationProperty oboIdInOwl = getDataFactory().getOWLAnnotationProperty(Obo2Owl.trTagToIRI(OboFormatTag.TAG_ID.getTag())); for (OWLOntology o : getAllOntologies()) { for(OWLObjectProperty p : o.getObjectPropertiesInSignature()) { // check for short hand or obo ID in owl Set<OWLAnnotation> annotations = OwlHelper.getAnnotations(p, o); if (annotations != null) { for (OWLAnnotation owlAnnotation : annotations) { OWLAnnotationProperty property = owlAnnotation.getProperty(); if ((shortHand != null && shortHand.equals(property)) || (oboIdInOwl != null && oboIdInOwl.equals(property))) { OWLAnnotationValue value = owlAnnotation.getValue(); if (value != null && value instanceof OWLLiteral) { OWLLiteral literal = (OWLLiteral) value; String shortHandLabel = literal.getLiteral(); if (id.equals(shortHandLabel)) { candIRISet.add(p.getIRI()); } } } } } } } } // In the case where we find multiple candidate IRIs, we give priorities for IRIs from BFO or RO ontologies. IRI returnIRI = null; for (IRI iri: candIRISet) { String iriStr = iri.toString(); if (iriStr.contains("BFO") || iriStr.contains("RO")) { returnIRI = iri; } } // If we were not able to find RO/BFO candidate IRIs for id if (returnIRI == null) { // We return it only if we have only one candidate. if (candIRISet.size() == 1) return new ArrayList<IRI>(candIRISet).get(0); // This is the unexpected case. Multiple non-RO/BPO properties are mapped to given id and it's not clear what to return. else if (candIRISet.size() > 1) throw new RuntimeException("Multiple candidate IRIs are found for id: " + id + ". None of them are from BFO or RO."); } // If we were able to find the property from RO/BFO, just return it. else { return returnIRI; } // otherwise use the obo2owl method Obo2Owl b = new Obo2Owl(getManager()); // re-use manager, creating a new one can be expensive as this is a highly used code path b.setObodoc(new OBODoc()); return b.oboIdToIRI(id); }
Example #22
Source File: OWLGraphFlexTest.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test public void testFlexClosures() throws Exception{ // Setup wrapper environment. String fstr = getResourceString("trivial.obo"); OBOFormatParser p = new OBOFormatParser(); OBODoc obodoc = p.parse(fstr); Obo2Owl bridge = new Obo2Owl(); OWLOntology ont = bridge.convert(obodoc); OWLGraphWrapper g = new OWLGraphWrapper(ont); // Get objects and a FlexCollection to play with. OWLObject a3 = g.getOWLObjectByIdentifier("A:0000003"); OWLObject a4 = g.getOWLObjectByIdentifier("A:0000004"); // Define isa. List<String> isa = new ArrayList<String>(); isa.add("getRelationIDClosure"); // Define isa_partof. List<String> isa_partof = new ArrayList<String>(); isa_partof.add("getRelationIDClosure"); isa_partof.add("BFO:0000050"); // Define regulates. List<String> reg = new ArrayList<String>(); reg.add("getRelationIDClosure"); reg.add("BFO:0000050"); reg.add("BFO:0000066"); reg.add("RO:0002211"); reg.add("RO:0002212"); reg.add("RO:0002213"); FlexCollection fc = new FlexCollection(g); // Small closure on a3, over just is_a. List<String> ans_t1 = fc.getExtStringList(a3, isa, null); assertTrue("In is_a closure: A:0000001", ans_t1.contains("A:0000001")); assertFalse("/Not/ in is_a closure: A:0000002", ans_t1.contains("A:0000002")); assertTrue("In is_a closure: A:0000003", ans_t1.contains("A:0000003")); // Small closure on a3, over is_a/part_of. List<String> ans_t2 = fc.getExtStringList(a3, isa_partof, null); assertTrue("In is_a/part_of closure: A:0000001", ans_t2.contains("A:0000001")); assertFalse("/Not/ in is_a/part_of closure: A:0000002", ans_t2.contains("A:0000002")); assertTrue("In is_a/part_of closure: A:0000003", ans_t2.contains("A:0000003")); // Small closure on a4, over is_a. List<String> ans_t3 = fc.getExtStringList(a4, isa, null); assertTrue("In is_a closure: A:0000001", ans_t3.contains("A:0000001")); assertFalse("/Not/ in is_a closure: A:0000002", ans_t3.contains("A:0000002")); assertTrue("In is_a closure: A:0000003", ans_t3.contains("A:0000003")); assertTrue("In is_a closure: A:0000004", ans_t3.contains("A:0000004")); // Small closure on a4, over is_a/part_of. List<String> ans_t4 = fc.getExtStringList(a4, isa_partof, null); assertTrue("In is_a/part_of closure: A:0000001", ans_t4.contains("A:0000001")); assertTrue("In is_a/part_of closure: A:0000002", ans_t4.contains("A:0000002")); assertTrue("In is_a/part_of closure: A:0000003", ans_t4.contains("A:0000003")); assertTrue("In is_a/part_of closure: A:0000004", ans_t4.contains("A:0000004")); }