source: trunk/grails-app/domain/dbnp/data/Term.groovy @ 756

Last change on this file since 756 was 756, checked in by keesvb, 13 years ago

updated Term constraint: accession is prefixed by the ontology identifier, and should therefore be unique database-wide

  • Property svn:keywords set to Date Rev Author
File size: 2.1 KB
Line 
1package dbnp.data
2
3import dbnp.data.Ontology
4
5/**
6 * The Term object describes a term in the ontology that is referred to in other entities such as events.
7 * The Term object should point to an existing term in an online ontology, therefore instances of this class can also
8 * be seen as a cache of elements of the external ontology.
9 * BioPortal example: Mus musculus: http://rest.bioontology.org/bioportal/concepts/38802/NCBITaxon:10090
10 *
11 * Revision information:
12 * $Rev: 756 $
13 * $Author: keesvb $
14 * $Date: 2010-08-02 10:29:50 +0000 (ma, 02 aug 2010) $
15 */
16class Term implements Serializable {
17    //static searchable = { [only: ['ontology']] }
18
19        String name             // BioPortal: label (preferred name)
20        Ontology ontology       // Parent ontology. To enable the unique constraints, we describe the Ontology-Term relation here
21        String accession        // BioPortal: conceptId
22
23        static constraints = {
24                accession(unique: true)     // Accession should be unique db-wide
25                name(unique: 'ontology')    // Preferred name should be unique within an ontology
26        name(size: 1..255)          // Name should be a non-empty string
27        }
28
29        def String toString() {
30                return name
31        }
32
33        /**
34         * Return all terms for a string of comma separated ontology ncboId's.
35         * @see Ontology.groovy
36         * @param ontologies
37         * @return
38         */
39        def giveAllByOntologies( ontologies ) {
40                // this method does not seem to work (see taglibrary:termSelect)
41                // i'll try to get it working later, or delete this altogether
42                // - Jeroen
43                def data = []
44                def terms = []
45
46                // got a string?
47                if (ontologies instanceof String) {
48                        // split the ontologies string
49                        ontologies.split(/\,/).each() { ncboId ->
50                                // trim the id
51                                ncboId.trim()
52
53                                // fetch all terms for this ontology
54                                def ontology = Ontology.findAllByNcboId(ncboId)
55
56                                // does this ontology exist?
57                                if (ontology) {
58                                        ontology.each() {
59                                                data[ data.size() ] = it
60                                        }
61                                }
62                        }
63
64                        ontologies = data
65                }
66
67                // iterate through ontologies
68                ontologies.each() { ontology ->
69                        Term.findAllByOntology( ontology ).each() { term ->
70                                terms[ terms.size() ] = term
71                        }
72                }
73
74                // sort alphabetically
75                terms.sort()
76        }
77}
Note: See TracBrowser for help on using the repository browser.