1 | package dbnp.data |
---|
2 | |
---|
3 | /** |
---|
4 | * This class describes an existing ontology, of which terms can be stored (actually 'cached' would be a better description) |
---|
5 | * in the (global) Term store. |
---|
6 | * This information is mapped from the BioPortal NCBO REST service, e.g.: http://rest.bioontology.org/bioportal/ontologies/38802 |
---|
7 | * @see http://www.bioontology.org/wiki/index.php/NCBO_REST_services |
---|
8 | * |
---|
9 | * Revision information: |
---|
10 | * $Rev: 558 $ |
---|
11 | * $Author: roberth $ |
---|
12 | * $Date: 2010-06-11 14:00:10 +0000 (vr, 11 jun 2010) $ |
---|
13 | */ |
---|
14 | class Ontology implements Serializable { |
---|
15 | String name // BioPortal: displayLabel |
---|
16 | String description // BioPortal: description |
---|
17 | String url // BioPortal: homepage |
---|
18 | String versionNumber // BioPortal: versionNumber |
---|
19 | int ncboId // BioPortal: ontologyId |
---|
20 | int ncboVersionedId // BioPortal: id |
---|
21 | |
---|
22 | /** |
---|
23 | * Find child terms |
---|
24 | * @return A set containing all terms that reside under this ontology |
---|
25 | */ |
---|
26 | Set<Term> giveTerms() { |
---|
27 | Term.findAllByOntology(this) |
---|
28 | } |
---|
29 | |
---|
30 | Object giveTermByName(String name) { |
---|
31 | giveTerms().find { |
---|
32 | it.name == name |
---|
33 | } |
---|
34 | |
---|
35 | /* TODO: find out why the following doesn't work (probably more efficient): |
---|
36 | Term.find { |
---|
37 | it.name == name |
---|
38 | it.ontology == this |
---|
39 | } |
---|
40 | }*/ |
---|
41 | } |
---|
42 | |
---|
43 | static Ontology getBioPortalOntology(String ncboId) { |
---|
44 | // Get ontology from BioPortal via Ontocat |
---|
45 | // TODO: maybe make a static OntologyService instance to be more efficient, and decorate it with caching? |
---|
46 | uk.ac.ebi.ontocat.OntologyService os = new uk.ac.ebi.ontocat.bioportal.BioportalOntologyService() |
---|
47 | uk.ac.ebi.ontocat.Ontology o = os.getOntology(ncboId) |
---|
48 | |
---|
49 | // Instantiate and return Ontology object |
---|
50 | new dbnp.data.Ontology( |
---|
51 | name: o.label, |
---|
52 | description: o.description, |
---|
53 | url: o.properties['homepage'] ?: "http://bioportal.bioontology.org/ontologies/${o.id}", |
---|
54 | versionNumber: o.versionNumber, |
---|
55 | ncboId: o.ontologyAccession, |
---|
56 | ncboVersionedId: o.id |
---|
57 | ); |
---|
58 | } |
---|
59 | |
---|
60 | static Ontology getBioPortalOntologyByTerm(String termId) { |
---|
61 | // Get ontology from BioPortal via Ontocat |
---|
62 | // TODO: maybe make a static OntologyService instance to be more efficient, and decorate it with caching? |
---|
63 | uk.ac.ebi.ontocat.OntologyService os = new uk.ac.ebi.ontocat.bioportal.BioportalOntologyService() |
---|
64 | uk.ac.ebi.ontocat.OntologyTerm term = os.getTerm( termId ); |
---|
65 | println( term ); |
---|
66 | uk.ac.ebi.ontocat.Ontology o = os.getOntology( term.getOntologyAccession() ); |
---|
67 | println( o ); |
---|
68 | |
---|
69 | // Instantiate and return Ontology object |
---|
70 | new dbnp.data.Ontology( |
---|
71 | name: o.label, |
---|
72 | description: o.description, |
---|
73 | url: o.properties['homepage'] ?: "http://bioportal.bioontology.org/ontologies/${o.id}", |
---|
74 | versionNumber: o.versionNumber, |
---|
75 | ncboId: o.ontologyAccession, |
---|
76 | ncboVersionedId: o.id |
---|
77 | ); |
---|
78 | } |
---|
79 | } |
---|