/** * */ package oboannotator.ontology; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * @author ahmedabdeenhamed * */ public class OntoUtil { private static Pattern quotedTextPattern = Pattern.compile("\\.owl$", Pattern.CASE_INSENSITIVE ); public static final String OBO = "OBO"; public static final String OWL = "OWL"; public static final String NOT_SUPPORTED = "NOT_SUPPORTED"; public static String extractAnnotationNameFromURI(String uri){ int index = uri.indexOf('#'); return uri.substring(index+1); } public static String extractSynonymFromOwlComment(String owlComment){ String synonym = null; //int length = owlComment.length(); String cleanString = cleanupAnnotationFromCarretString(owlComment); //System.out.println("Matched Result is 1: " + cleanString); if(!cleanString.contains("synonym")){ return synonym; } //System.out.println("Matched Result is 2: " + cleanString); int index = cleanString.indexOf(":"); if(index>0){ synonym = cleanString.substring(cleanString.indexOf("synonym")); synonym = synonym.substring(synonym.indexOf(':')+1); //System.out.println("Extacted synonym:" + synonym.trim()); return synonym.trim(); } return synonym; } public static String cleanupAnnotationFromCarretString(String annotation){ String cleanString = null; if(annotation.contains("^^string")){ cleanString = annotation.replace("^^string", ""); return cleanString.trim(); } //System.out.println("Matched Result is: " + cleanString); return annotation; } public static String extractTextFromQuotedText(String text){ String matchedResult = null; if (text.contains("\"")){ matchedResult = text.replace("\"", ""); //System.out.println("Matched Result is: " + matchedResult); return matchedResult.trim(); } return text; } public static String[] tokenizeOwlTerm(String term){ String[] listOfTokens = null; listOfTokens = term.split("_"); return listOfTokens; } public static String oboOrOwl(String ontologyUri){ Pattern owlPattern = Pattern.compile("\\.owl$", Pattern.CASE_INSENSITIVE); Pattern oboPattern = Pattern.compile("\\.obo$", Pattern.CASE_INSENSITIVE); Matcher matchOwl = owlPattern.matcher(ontologyUri); Matcher matchObo = oboPattern.matcher(ontologyUri); if(matchOwl.find()){ //System.out.println("OWL"); return OWL; } if(matchObo.find()){ //System.out.println("OBO"); return OBO; } //System.out.println("NOT_SUPPORTED"); return NOT_SUPPORTED; } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub //System.out.println("CURRENT ANNOTATION: " + extractAnnotationNameFromURI("http://www.geneontology.org/go#def")); //System.out.println("CURRENT ANNOTATION: " + extractAnnotationNameFromURI("http://www.geneontology.org/go#synonym")); // System.out.println("CURRENT ANNOTATION: " + extractAnnotationFromURI("http://www.geneontology.org/go#xdef")); // System.out.println("CURRENT ANNOTATION: " + extractAnnotationFromURI("http://www.geneontology.org/go#namespace")); // System.out.println("CURRENT ANNOTATION: " + extractAnnotationFromURI("http://www.geneontology.org/go#label")); //extractSynonymFromOwlComment("defprov: Bruker website synonym: Bruker Efficient Sample Transfer NMR\"^^string"); //extractTextFromQuotedText("\"defprov: Bruker website synonym: Bruker Efficient Sample Transfer NMR\"^^string"); //extractSynonymFromOwlComment("tempdef: An improved water-suppression technique called WET (water suppression enhanced through T1 effects), developed from a Bloch equation analysis of the longitudinal magnetization over the T1 and B1 ranges of interest, achieves T1- and B1-insensitive suppression with four RF pulses, each having a numerically optimized flip angle. Once flip angles have been optimized for a given sequence, time-consuming flip-angle adjustments during clinical examinations are eliminated. defprov: Daniel Schober synonym: WET"); // String[] list = tokenizeOwlTerm("Ahmed_abdeen_hamed_is_married_to_lindsay_and_has_laila"); // for(String token: list){ // System.out.print(token + " "); // // } String ontoType = oboOrOwl("https://msi-workgroups.svn.sourceforge.net/svnroot/msi-workgroups/ontology/NMR.owl"); ontoType = oboOrOwl("http://obo.cvs.sourceforge.net/*checkout*/obo/obo/ontology/phenotype/worm_phenotype.obo"); ontoType = oboOrOwl("http://obi.svn.sourceforge.net/svnroot/obi/tags/releases/2008-06-27/merged/OBI.owl"); ontoType = oboOrOwl(""); } }