package au.edu.apf.phenomebank.ontology;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.Collection;
import java.util.LinkedList;
import org.obo.dataadapter.DefaultOBOParser;
import org.obo.dataadapter.OBOParseEngine;
import org.obo.datamodel.Dbxref;
import org.obo.datamodel.IdentifiedObject;
import org.obo.datamodel.Link;
import org.obo.datamodel.LinkDatabase;
import org.obo.datamodel.NestedValue;
import org.obo.datamodel.OBOObject;
import org.obo.datamodel.OBOSession;
import org.obo.datamodel.PropertyValue;
import org.obo.datamodel.Synonym;
import org.obo.util.TextUtil;
/**
* Testing ontology parsing
*
*
* @author Philip Wu
*/
public class OntologyTest {
public static void main (String[] args) throws Exception {
System.out.println("Start");
DefaultOBOParser parser = new DefaultOBOParser();
OBOParseEngine engine = new OBOParseEngine(parser);
String path = "C:/Documents and Settings/a295029/Desktop/latest_MPheno_OBO.ontology";
Collection paths = new LinkedList();
paths.add(path);
engine.setPaths(paths);
engine.parse();
OBOSession session = parser.getSession();
// Using the Ontology
IdentifiedObject obj = session.getObject("MP:0009788");
if (obj != null) {
if (obj instanceof OBOObject) {
OBOObject term = (OBOObject) obj;
dumpTerm(System.out, term);
}
}
System.out.println("Finished");
}
public static void dumpNestedValue(PrintStream ps, NestedValue nv) {
if (nv!= null) {
ps.print(" Name: "+nv.getName());
if (nv.getPropertyValues() != null) {
for (PropertyValue pv : nv.getPropertyValues()) {
ps.println("Property: "+pv.getProperty()+"="+pv.getValue());
}
}
}
}
public static void dumpTerm(PrintStream ps, OBOObject term) {
String id = term.getID();
ps.println("ID:"+id);
ps.println("Name: "+term.getName());
if (term.getIDExtension() != null) {
ps.println("ID Extension: ");
dumpNestedValue(ps, term.getIDExtension());
}
if (term.getPropertyValues() != null && term.getPropertyValues().size() > 0) {
ps.println("Property values");
dumpPropertyValues(ps, term.getPropertyValues());
}
ps.println("Definition: "+term.getDefinition());
if (term.getDefinitionExtension() != null) {
dumpNestedValue(ps, term.getDefinitionExtension());
}
for (Dbxref dbxref : TextUtil.getAllDbxrefs(term)) {
ps.println("Def dbxref. ID: "+dbxref.getID()+ " DatabaseID: "+dbxref.getDatabaseID()+" Database: "+ dbxref.getDatabase()+" Desc: "+dbxref.getDesc());
}
for (Synonym syn : term.getSynonyms()) {
ps.println("Synonym. ID: "+syn.getID()+ " Text:"+syn.getText());
}
for (Link link : term.getParents()) {
ps.println("Parent. ID: "+ link.getParent().getID());
}
}
public static void dumpPropertyValues(PrintStream ps, Collection<PropertyValue> propertyValues) {
if (propertyValues != null) {
for (PropertyValue pv : propertyValues) {
ps.println("Property: "+pv.getProperty()+"="+pv.getValue());
}
}
}
}
Tips and experience about developing websites with various technologies
Sunday, September 27, 2009
Searching and Displaying Terms OBO
Here is some sample code on how to search for a term and display its properties:
Labels:
java obo parsing
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment