Changeset 506
- Timestamp:
- 01/19/12 17:21:46 (16 months ago)
- Location:
- trunk/ontoCAT
- Files:
-
- 2 edited
-
dist/release_notes.txt (modified) (1 diff)
-
src/uk/ac/ebi/ontocat/ols/OlsOntologyService.java (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ontoCAT/dist/release_notes.txt
r504 r506 4 4 Version 0.9.9.2 / / / 5 5 Added <userIds> <obsoleteParent> fields to Bioportal's OntologyBean 6 FIX for the inability of using encoded slashes in the URL proper when querying Bioportal .6 FIX for the inability of using encoded slashes in the URL proper when querying Bioportal 7 7 Now passing them as string parameters, q=? pattern 8 Added xrefs to annotations returned from OLS 8 9 9 10 Version 0.9.9.1 30/9/2011 -
trunk/ontoCAT/src/uk/ac/ebi/ontocat/ols/OlsOntologyService.java
r489 r506 33 33 import java.util.Set; 34 34 import java.util.TreeMap; 35 import java.util.regex.Matcher; 36 import java.util.regex.Pattern; 35 37 36 38 import javax.xml.rpc.ServiceException; … … 70 72 @SuppressWarnings("unchecked") 71 73 public class OlsOntologyService extends AbstractOntologyService implements 72 OntologyService {74 OntologyService { 73 75 Logger logger = Logger.getLogger(OlsOntologyService.class); 74 76 // Webservice API … … 88 90 // Try to make connections to the database and the webservice 89 91 try { 90 this.locator = new QueryServiceLocator();91 this.qs = locator.getOntologyQuery();92 locator = new QueryServiceLocator(); 93 qs = locator.getOntologyQuery(); 92 94 } catch (ServiceException e) { 93 95 throw new OntologyServiceException(e); … … 142 144 if (ops.contains(SearchOptions.EXACT) 143 145 && dh.getAnnotationStringValue() 144 .equalsIgnoreCase(query)) {146 .equalsIgnoreCase(query)) { 145 147 continue; 146 148 } … … 155 157 String label = terms.get(key); 156 158 URI uri = URI 157 .create("http://www.ebi.ac.uk/ontology-lookup/?termId=" + key); 159 .create("http://www.ebi.ac.uk/ontology-lookup/?termId=" 160 + key); 158 161 result.add(new OntologyTerm(ontAccession, key, label, uri)); 159 162 } … … 166 169 @Override 167 170 public List<OntologyTerm> searchAll(String query, SearchOptions... options) 168 throws OntologyServiceException {171 throws OntologyServiceException { 169 172 List<SearchOptions> ops = new ArrayList<SearchOptions>( 170 173 Arrays.asList(options)); … … 185 188 String label = entry.getValue().split(":")[1]; 186 189 URI uri = URI 187 .create("http://www.ebi.ac.uk/ontology-lookup/?termId=" + termAccession); 190 .create("http://www.ebi.ac.uk/ontology-lookup/?termId=" 191 + termAccession); 188 192 // filter out non-exact terms if necessary 189 193 if (ops.contains(SearchOptions.EXACT) … … 205 209 @Override 206 210 public Ontology getOntology(String ontologyAccession) 207 throws OntologyServiceException {211 throws OntologyServiceException { 208 212 Ontology o = new Ontology(ontologyAccession); 209 213 try { 210 214 String label = (String) qs.getOntologyNames() 211 .get(ontologyAccession);215 .get(ontologyAccession); 212 216 if (label == null) { 213 217 return null; … … 225 229 @Override 226 230 public OntologyTerm getTerm(String ontologyAccession, String termAccession) 227 throws OntologyServiceException {231 throws OntologyServiceException { 228 232 String label = null; 229 233 try { … … 235 239 throw new OntologyServiceException(e); 236 240 } 237 URI uri = URI 238 .create("http://www.ebi.ac.uk/ontology-lookup/?termId="+ termAccession);241 URI uri = URI.create("http://www.ebi.ac.uk/ontology-lookup/?termId=" 242 + termAccession); 239 243 return new OntologyTerm(ontologyAccession, termAccession, label, uri); 240 244 } … … 242 246 @Override 243 247 public OntologyTerm getTerm(String termAccession) 244 throws OntologyServiceException {248 throws OntologyServiceException { 245 249 246 250 return getTerm(getOntologyAccFromTerm(termAccession), termAccession); … … 260 264 @Override 261 265 public List<OntologyTerm> getRootTerms(String ontologyAccession) 262 throws OntologyServiceException {266 throws OntologyServiceException { 263 267 // Make sure the ontology exists 264 268 getOntology(ontologyAccession); … … 276 280 // Make sure the term exists 277 281 getTerm(ontologyAccession, termAccession); 278 String key = ontologyAccession + ":" + termAccession;279 if (!annotationCache.containsKey( key)) {282 String termKey = ontologyAccession + ":" + termAccession; 283 if (!annotationCache.containsKey(termKey)) { 280 284 try { 281 Map result = qs.getTermMetadata(termAccession, 285 Map<String, List<String>> result = new HashMap<String, List<String>>(); 286 Map<String, Object> annots = qs.getTermMetadata(termAccession, 282 287 ontologyAccession); 283 // clean out the String from String[] 284 for (Object metadataKey : result.keySet()) { 285 // logger.debug("getting annotation "+metadataKey); 286 if (result.get(metadataKey) instanceof String) { 287 result.put(metadataKey, Arrays 288 .asList(new String[] { (String) result 289 .get(metadataKey) })); 290 } else if (result.get(metadataKey) instanceof String[]) { 291 result.put(metadataKey, Arrays.asList((String[]) result 292 .get(metadataKey))); 288 // dump xrefs into the annotation list 289 annots.putAll(qs.getTermXrefs(termAccession, ontologyAccession)); 290 291 for (String annotsKey : annots.keySet()) { 292 Object values = annots.get(annotsKey); 293 String cleanedKey = cleanupAnnotsKey(annotsKey); 294 295 List<String> temp = result.get(cleanedKey); 296 if (temp == null) { 297 temp = new ArrayList<String>(); 298 } 299 300 // convert String[] to List<String> if necessary 301 if (values instanceof String) { 302 temp.add((String) values); 303 } else if (values instanceof String[]) { 304 temp.addAll(Arrays.asList((String[]) values)); 293 305 } else { 294 306 throw new OntologyServiceException("annotation error: " 295 + metadataKey);307 + annotsKey); 296 308 } 309 result.put(cleanedKey, temp); 297 310 } 298 annotationCache.put( key, result);311 annotationCache.put(termKey, result); 299 312 } catch (RemoteException e) { 300 313 throw new OntologyServiceException(e); 301 314 } 302 315 } 303 return annotationCache.get(key); 316 return annotationCache.get(termKey); 317 } 318 319 /** 320 * Removes the unnecessary index from OLS annotation key, e.g., 321 * exact_synonym_4 becomes exact_synonym 322 */ 323 private String cleanupAnnotsKey(String indexedKey) { 324 Pattern p = Pattern.compile("(.*)_\\d+"); 325 Matcher m = p.matcher(indexedKey); 326 if (m.find()) { 327 return m.group(1); 328 } else { 329 return indexedKey; 330 } 304 331 } 305 332 … … 308 335 String termAccession) throws OntologyServiceException { 309 336 List<String> result = getAnnotations(ontologyAccession, termAccession) 310 .get("exact_synonym");337 .get("exact_synonym"); 311 338 if (result == null) { 312 339 return Collections.EMPTY_LIST; … … 328 355 // helper methods 329 356 protected List<OntologyTerm> fetchFullTerms(Map<String, String> terms) 330 throws OntologyServiceException {357 throws OntologyServiceException { 331 358 List<OntologyTerm> result = new ArrayList<OntologyTerm>(); 332 359 for (String termAccession : terms.keySet()) { … … 341 368 String termAccession) throws OntologyServiceException { 342 369 List<String> result = getAnnotations(ontologyAccession, termAccession) 343 .get("definition");370 .get("definition"); 344 371 if (result == null) { 345 372 return Collections.EMPTY_LIST; … … 397 424 throw new OntologyServiceException( 398 425 "findSearchTermPath(): TOO MANY ITERATIONS (" 399 + iteration + "x)");426 + iteration + "x)"); 400 427 } 401 428 }
Note: See TracChangeset
for help on using the changeset viewer.