source: trunk/grails-app/domain/dbnp/studycapturing/Assay.groovy @ 1873

Last change on this file since 1873 was 1873, checked in by work@…, 10 years ago
  • Property svn:keywords set to Rev Author Date
File size: 2.5 KB
Line 
1package dbnp.studycapturing
2import org.dbnp.gdt.*
3
4/**
5 * This class describes an Assay, which describes the application of a certain (omics) measurement to multiple samples.
6 * The actual data of these measurements are described in submodules of dbNP. The type property describes in which module
7 * this data can be found.
8 */
9class Assay extends TemplateEntity {
10        // The name of the assay, which should indicate the measurements represented in this assay to the user.
11        String name
12
13        // The dbNP module in which the assay omics data can be found. */
14        AssayModule module
15
16        /**
17        * UUID of this assay
18        */
19    String assayUUID
20
21        /**
22         * return the domain fields for this domain class
23         * @return List
24         */
25        static List<TemplateField> giveDomainFields() { return Assay.domainFields }
26        static List<TemplateField> domainFields = [
27                new TemplateField(
28                        name: 'name',
29                        type: TemplateFieldType.STRING,
30                        preferredIdentifier: true,
31                        comment: 'The name you give here is used to discern this assay within the study (e.g. \'liver transcriptomics\', \'blood lipidomics\')',
32                        required: true
33                ),
34                new TemplateField(
35                        name: 'module',
36                        type: TemplateFieldType.MODULE,
37                        comment: 'Select the dbNP module where the actual assay measurement data is stored',
38                        required: true
39                )
40        ]
41
42        // An Assay always belongs to one study.
43        static belongsTo = [parent: Study]
44
45        // An Assay can have many samples on which it is performed, but all samples should be within the 'parent' Study.
46        static hasMany = [samples: Sample]
47
48        static constraints = {
49                assayUUID(nullable:true, unique: true)
50        }
51
52    static mapping = {
53        sort "name"
54
55        // Workaround for bug http://jira.codehaus.org/browse/GRAILS-6754
56        templateTextFields type: 'text'
57    }
58
59        def String toString() {
60                return name;
61        }
62
63    def getToken() {
64                return giveUUID()
65    }
66       
67        /**
68         * Basic equals method to check whether objects are equals, by comparing the ids
69         * @param o             Object to compare with
70         * @return              True iff the id of the given Study is equal to the id of this Study
71         */
72        public boolean equals( Object o ) {
73                if( o == null )
74                        return false;
75
76                if( !( o instanceof Assay ) )
77                        return false
78
79                Assay s = (Assay) o;
80
81                return this.id == s.id
82        }
83       
84        /**
85         * Returns the UUID of this sample and generates one if needed
86         */
87        public String giveUUID() {
88                if( !this.assayUUID ) {
89                        this.assayUUID = UUID.randomUUID().toString();
90                        if( !this.save(flush:true) ) {
91                                log.error "Couldn't save assay UUID: " + this.getErrors();
92                        }
93                }
94               
95                return this.assayUUID;
96        }
97}
Note: See TracBrowser for help on using the repository browser.