source: trunk/grails-app/conf/BootStrap.groovy @ 177

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

added mouse genotype fields to bootstrap, replaced giveAllFields in Study to return template fields

  • Property svn:keywords set to
    Date
    Author
    Rev
File size: 8.1 KB
Line 
1import org.codehaus.groovy.grails.commons.GrailsApplication
2import grails.util.GrailsUtil
3import dbnp.studycapturing.*
4
5import dbnp.data.Ontology
6import dbnp.data.Term
7
8/**
9 * Application Bootstrapper
10 * @Author Jeroen Wesbeek
11 * @Since 20091021
12 *
13 * Revision information:
14 * $Rev: 177 $
15 * $Author: keesvb $
16 * $Date: 2010-02-08 11:46:19 +0000 (ma, 08 feb 2010) $
17 */
18class BootStrap {
19        def init = {servletContext ->
20                // define timezone
21                System.setProperty('user.timezone', 'CET')     
22
23                if (GrailsUtil.environment == GrailsApplication.ENV_DEVELOPMENT) {
24                        printf("development bootstrapping....\n\n");
25
26                        // ontologies
27                        def speciesOntology = new Ontology(
28                                name: 'NCBI Taxonomy',
29                                shortName: 'Taxon',
30                                url: 'http://www.obofoundry.org/cgi-bin/detail.cgi?id=ncbi_taxonomy'
31                        ).with { if (!validate()) { errors.each { println it} } else save()}
32
33
34                        // terms
35                        def mouseTerm = new Term(
36                                name: 'Mus musculus',
37                                ontology: speciesOntology,
38                                accession: '10090'
39                        ).with { if (!validate()) { errors.each { println it} } else save()}
40                        def humanTerm = new Term(
41                                name: 'Homo sapiens',
42                                ontology: speciesOntology,
43                                accession: '9606'
44                        ).with { if (!validate()) { errors.each { println it} } else save()}
45
46                        def madmaxOntology = new Ontology(
47                                name: 'Madmax ontology',
48                                shortName: 'MDMX',
49                                url: 'madmax.bioinformatics.nl'
50                        ).with { if (!validate()) { errors.each { println it} } else save()}
51
52                        def treatmentTerm = new Term(
53                                name: 'ExperimentalProtocol',
54                                ontology: madmaxOntology,
55                                accession: 'P-MDMXGE-264'
56                        ).with { if (!validate()) { errors.each { println it} } else save()}
57
58
59                        def treatmentProtocol = new Protocol(
60                                name: 'MADMAX Experimental Protocol',
61                                reference: treatmentTerm
62                        ).with { if (!validate()) { errors.each { println it} } else save()}
63
64
65                        // added by Jahn for testing the event views
66                        def treatmentProtocol2 = new Protocol(
67                                name: 'MADMAX Experimental Protocol 2',
68                                reference: treatmentTerm
69                        ).with { if (!validate()) { errors.each { println it} } else save()}
70
71
72
73                        treatmentProtocol
74                        .addToParameters(new ProtocolParameter(
75                                name: 'Diet',
76                                type: ProtocolParameterType.STRINGLIST,
77                                listEntries: ['10% fat (palm oil)','45% fat (palm oil)']))
78                        .addToParameters(new ProtocolParameter(
79                                name: 'Compound',
80                                type: ProtocolParameterType.STRINGLIST,
81                                listEntries: ['Vehicle','Leptin']))
82                        .addToParameters(new ProtocolParameter(
83                                name: 'Administration',
84                                type: ProtocolParameterType.STRING))
85                        .save()
86
87
88                        // added by Jahn for testing the event views
89                        treatmentProtocol2
90                        .addToParameters(new ProtocolParameter(
91                                name: 'Diet',
92                                type: ProtocolParameterType.STRINGLIST,
93                                listEntries: ['99% fat (crude oil)','1% fat (palm oil)']))
94                        .addToParameters(new ProtocolParameter(
95                                name: 'Compound',
96                                type: ProtocolParameterType.STRINGLIST,
97                                listEntries: ['Vehicle','Leptin']))
98                        .addToParameters(new ProtocolParameter(
99                                name: 'Administration',
100                                type: ProtocolParameterType.STRING))
101                        .save()
102
103
104
105                        // create system user
106                        /*
107                        def systemUser = userService.createUser(InstanceGenerator.user(
108                                username: 'system',
109                                pass: 'system',
110                                passConfirm: 'system',
111                                enabled: true
112                        ))
113                        */
114
115                        // Mouse template
116                        def mouseTemplate = new Template(
117                                name: 'Mouse'
118                        ).addToSubjectFields(new TemplateSubjectField(
119                                name: 'Genotype',type: TemplateFieldType.STRINGLIST,
120                                listEntries: ['C57/Bl6j','wild type']))
121                        .addToSubjectFields(new TemplateSubjectField(
122                                name: 'Gender',type: TemplateFieldType.STRINGLIST,
123                                listEntries: ['Male','Female']))
124                        .addToSubjectFields(new TemplateSubjectField(
125                                name: 'Age',type: TemplateFieldType.INTEGER))
126                        .addToSubjectFields(new TemplateSubjectField(
127                                name: 'Cage',type: TemplateFieldType.INTEGER))
128                        .with { if (!validate()) { errors.each { println it} } else save()}
129
130
131                        //events
132                        def eventTreatment = new EventDescription(
133                                name: 'Treatment',
134                                description: 'Experimental Treatment Protocol NuGO PPS3 leptin module',
135                                classification: treatmentTerm,
136                                protocol: treatmentProtocol
137                        ).with { if (!validate()) { errors.each { println it} } else save()}
138
139                        def eventTreatment2 = new EventDescription(
140                                name: 'Treatment2',
141                                description: 'Treatment Protocol NuGO PPS1',
142                                classification: treatmentTerm,
143                                protocol: treatmentProtocol2
144                        ).with { if (!validate()) { errors.each { println it} } else save()}
145
146                        // studies
147                        def exampleStudy = new Study(
148                                title:"NuGO PPS3 mouse study leptin module",
149                                code:"PPS3_leptin_module",
150                                researchQuestion:"Leptin etc.",
151                                description:"C57Bl/6 mice were fed a high fat (45 en%) or low fat (10 en%) diet after a four week run-in on low fat diet. After 1 week 10 mice that received a low fat diet were given an IP leptin challenge and 10 mice of the low-fat group received placebo injections. The same procedure was performed with mice that were fed the high-fat diet. After 4 weeks the procedure was repeated. In total 80 mice were culled.",
152                                ecCode:"2007117.c",
153                                startDate: Date.parse('yyyy-MM-dd','2007-12-11'),
154                                template: mouseTemplate
155                        ).with { if (!validate()) { errors.each { println it} } else save()}
156
157                        def x=1
158                        12.times {
159                                def currentSubject = new Subject(
160                                        name: "A" + x++,
161                                        species: mouseTerm,
162                                        template: mouseTemplate,
163                                        templateStringFields: ["Genotype" : "C57/Bl6j", "Gender" : "Male"],
164                                        templateIntegerFields: ["Age" : 17, "Cage" : (int)(x/2)]
165                                ).with { if (!validate()) { errors.each { println it} } else save()}
166
167                                exampleStudy.addToSubjects(currentSubject)
168                                .addToEvents(new Event(
169                                        subject: currentSubject,
170                                        startTime: Date.parse('yyyy-MM-dd','2008-01-07'),
171                                        endTime: Date.parse('yyyy-MM-dd','2008-01-14'),
172                                        eventDescription: eventTreatment,
173                                        parameterStringValues: ['Diet':'10% fat (palm oil)','Compound':'Vehicle','Administration':'intraperitoneal injection'])
174                                ).with { if (!validate()) { errors.each { println it} } else save()}
175                        }
176
177
178                        def secondStudy = new Study(
179                                title:"NuGO PPS1 mouse study leptin module",
180                                code:"PPS1",
181                                researchQuestion:"etc.",
182                                description:"C57Bl/6 mice were fed a high fat (45 en%) or low fat (10 en%) diet after a four week run-in on low fat diet. After 1 week 10 mice that received a low fat diet were given an IP leptin challenge and 10 mice of the low-fat group received placebo injections. The same procedure was performed with mice that were fed the high-fat diet. After 4 weeks the procedure was repeated. In total 80 mice were culled.",
183                                ecCode:"2007.c",
184                                startDate: Date.parse('yyyy-MM-dd','2007-12-11'),
185                                template: mouseTemplate
186                        ).with { if (!validate()) { errors.each { println it} } else save()}
187
188                        def y=1
189                        5.times {
190                                def currentSubject = new Subject(
191                                        name: "A" + y++,
192                                        species: mouseTerm,
193                                        template: mouseTemplate,
194                                        templateStringFields: ["Genotype" : "C57/Bl6j", "Gender" : "Male"],
195                                        templateIntegerFields: ["Age" : 17, "Cage" : (int)(y/2)]
196                                ).with { if (!validate()) { errors.each { println it} } else save()}
197
198                                secondStudy.addToSubjects(currentSubject)
199                                .addToEvents(new SamplingEvent(
200                                        subject: currentSubject,
201                                        startTime: Date.parse('yyyy-MM-dd','2008-01-07'),
202                                        endTime: Date.parse('yyyy-MM-dd','2008-01-14'),
203                                        eventDescription: eventTreatment2,
204                                        parameterStringValues: ['Diet':'10% fat (palm oil)','Compound':'Vehicle','Administration':'intraperitoneal injection'])
205                                ).with { if (!validate()) { errors.each { println it} } else save()}
206                        }
207
208//                        new Study(title:"example",code:"Excode",researchQuestion:"ExRquestion",description:"Exdescription",ecCode:"ExecCode",dateCreated:new Date(),lastUpdated:new Date(),startDate:new Date()).save()
209//                        new Study(title:"testAgain",code:"testcode",researchQuestion:"testRquestion",description:"testdescription",ecCode:"testCode",dateCreated:new Date(),lastUpdated:new Date(),startDate:new Date()).save()
210//                        new Study(title:"Exampletest",code:"Examplecode",researchQuestion:"ExampleRquestion",description:"Exampledescription",ecCode:"ExampleecCode",dateCreated:new Date(),lastUpdated:new Date(),startDate:new Date()).save()
211                }
212        }
213
214        def destroy = {
215        }
216} 
Note: See TracBrowser for help on using the repository browser.