PseudoRdfXmlWriter extends AbstractXmlWriter { void writeRelations(XMLStreamWriter writer, OWLClass c, OWLGraphWrapper graph) throws XMLStreamException { SortedSet<String> is_a_rels = new TreeSet<String>(); SortedSet<String> part_of_rels = new TreeSet<String>(); SortedSet<String> negatively_regulates_rels = new TreeSet<String>(); SortedSet<String> positively_regulates_rels = new TreeSet<String>(); SortedSet<String> regulates_rels = new TreeSet<String>(); Set<OWLGraphEdge> edges = graph.getOutgoingEdges(c); for (OWLGraphEdge owlGraphEdge : edges) { OWLObject target = owlGraphEdge.getTarget(); List<OWLQuantifiedProperty> propertyList = owlGraphEdge.getQuantifiedPropertyList(); if ("GO:0006417".equals(graph.getIdentifier(c))) { System.out.println(); } boolean is_a = false; boolean part_of = false; boolean negatively_regulates = false; boolean positively_regulates = false; boolean regulates = false; for (OWLQuantifiedProperty property : propertyList) { OWLObjectProperty objectProperty = property.getProperty(); if (objectProperty != null) { String label = graph.getLabel(objectProperty); if ("part_of".equals(label) || "part of".equals(label)) { part_of = true; break; } else if ("negatively_regulates".equals(label) || "negatively regulates".equals(label)) { negatively_regulates = true; break; } else if ("positively_regulates".equals(label) || "positively regulates".equals(label)) { positively_regulates = true; break; } else if ("regulates".equals(label)) { regulates = true; break; } } else { is_a = property.isSubClassOf(); } } if (negatively_regulates) { negatively_regulates_rels.add(graph.getIdentifier(target)); } else if (positively_regulates) { positively_regulates_rels.add(graph.getIdentifier(target)); } else if (regulates) { regulates_rels.add(graph.getIdentifier(target)); } else if (part_of) { part_of_rels.add(graph.getIdentifier(target)); } else if (is_a) { is_a_rels.add(graph.getIdentifier(target)); } } writeRelation(writer, "is_a", is_a_rels); writeRelation(writer, "part_of", part_of_rels); writeRelation(writer, "regulates", regulates_rels); writeRelation(writer, "positively_regulates", positively_regulates_rels); writeRelation(writer, "negatively_regulates", negatively_regulates_rels); if (graph.isObsolete(c)) { String namespace = graph.getNamespace(c); if (namespace != null) { namespace = namespace.toLowerCase(); if (namespace.equals("biological_process") || namespace.equals("molecular_function") || namespace.equals("cellular_component")) { writeRelation(writer, "is_a", "obsolete_" + namespace); } } } } PseudoRdfXmlWriter(); void setProgressReporter(ProgressReporter reporter); void write(OutputStream stream, OWLGraphWrapper graph, List<GafDocument> gafs);  }
@Test public void testRelationWriter() throws Exception { PseudoRdfXmlWriter w = new PseudoRdfXmlWriter(); OWLClass c = graph.getOWLClassByIdentifier("GO:0006417"); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); XMLStreamWriter writer = w.createWriter(outputStream); writer.setPrefix("go", PseudoRdfXmlWriter.GO_NAMESPACE_URI); writer.setPrefix("rdf", PseudoRdfXmlWriter.RDF_NAMESPACE_URI); writer.writeStartElement("test"); w.writeRelations(writer, c, graph); writer.writeEndElement(); writer.close(); System.out.println(outputStream.toString()); assertEquals("\n<test>\n" + DEFAULT_INDENT+"<go:is_a rdf:resource=\"http: DEFAULT_INDENT+"<go:is_a rdf:resource=\"http: DEFAULT_INDENT+"<go:is_a rdf:resource=\"http: DEFAULT_INDENT+"<go:regulates rdf:resource=\"http: "</test>", outputStream.toString()); }