1 | import org.codehaus.groovy.grails.commons.GrailsApplication |
---|
2 | import grails.util.GrailsUtil |
---|
3 | import dbnp.studycapturing.* |
---|
4 | |
---|
5 | import dbnp.data.Ontology |
---|
6 | import dbnp.data.Term |
---|
7 | |
---|
8 | /** |
---|
9 | * Application Bootstrapper |
---|
10 | * @Author Jeroen Wesbeek |
---|
11 | * @Since 20091021 |
---|
12 | * |
---|
13 | * Revision information: |
---|
14 | * $Rev: 192 $ |
---|
15 | * $Author: duh $ |
---|
16 | * $Date: 2010-02-11 16:47:49 +0000 (do, 11 feb 2010) $ |
---|
17 | */ |
---|
18 | class 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 | def humanBodyOntology = new Ontology( |
---|
34 | name: 'Foundational Model of Anatomy', |
---|
35 | shortName: 'HumanBody', |
---|
36 | url: 'http://bioportal.bioontology.org/ontologies/39966' |
---|
37 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
38 | |
---|
39 | // terms |
---|
40 | def mouseTerm = new Term( |
---|
41 | name: 'Mus musculus', |
---|
42 | ontology: speciesOntology, |
---|
43 | accession: '10090' |
---|
44 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
45 | def humanTerm = new Term( |
---|
46 | name: 'Homo sapiens', |
---|
47 | ontology: speciesOntology, |
---|
48 | accession: '9606' |
---|
49 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
50 | |
---|
51 | def bloodTerm = new Term( |
---|
52 | name: 'Portion of blood', |
---|
53 | ontology: humanBodyOntology, |
---|
54 | accession: '9670' |
---|
55 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
56 | |
---|
57 | def madmaxOntology = new Ontology( |
---|
58 | name: 'Madmax ontology', |
---|
59 | shortName: 'MDMX', |
---|
60 | url: 'madmax.bioinformatics.nl' |
---|
61 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
62 | |
---|
63 | def treatmentTerm = new Term( |
---|
64 | name: 'ExperimentalProtocol', |
---|
65 | ontology: madmaxOntology, |
---|
66 | accession: 'P-MDMXGE-264' |
---|
67 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
68 | |
---|
69 | def treatmentProtocol = new Protocol( |
---|
70 | name: 'MADMAX Experimental Protocol', |
---|
71 | reference: treatmentTerm |
---|
72 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
73 | |
---|
74 | |
---|
75 | // added by Jahn for testing the event views |
---|
76 | def treatmentProtocol2 = new Protocol( |
---|
77 | name: 'MADMAX Experimental Protocol 2', |
---|
78 | reference: treatmentTerm |
---|
79 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
80 | |
---|
81 | treatmentProtocol |
---|
82 | .addToParameters(new ProtocolParameter( |
---|
83 | name: 'Diet', |
---|
84 | type: ProtocolParameterType.STRINGLIST, |
---|
85 | listEntries: ['10% fat (palm oil)','45% fat (palm oil)'])) |
---|
86 | .addToParameters(new ProtocolParameter( |
---|
87 | name: 'Compound', |
---|
88 | type: ProtocolParameterType.STRINGLIST, |
---|
89 | listEntries: ['Vehicle','Leptin'])) |
---|
90 | .addToParameters(new ProtocolParameter( |
---|
91 | name: 'Administration', |
---|
92 | type: ProtocolParameterType.STRING)) |
---|
93 | .save() |
---|
94 | |
---|
95 | |
---|
96 | // added by Jahn for testing the event views |
---|
97 | treatmentProtocol2 |
---|
98 | .addToParameters(new ProtocolParameter( |
---|
99 | name: 'Diet', |
---|
100 | type: ProtocolParameterType.STRINGLIST, |
---|
101 | listEntries: ['99% fat (crude oil)','1% fat (palm oil)'])) |
---|
102 | .addToParameters(new ProtocolParameter( |
---|
103 | name: 'BackgroundDiet', |
---|
104 | type: ProtocolParameterType.STRING)) |
---|
105 | .save() |
---|
106 | |
---|
107 | // sampling event protocols |
---|
108 | |
---|
109 | def liverSamplingProtocol = new Protocol( |
---|
110 | name: 'Liver sampling' |
---|
111 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
112 | |
---|
113 | liverSamplingProtocol |
---|
114 | .addToParameters(new ProtocolParameter( |
---|
115 | name: 'Sample weight', |
---|
116 | unit: 'mg', |
---|
117 | type: ProtocolParameterType.FLOAT)) |
---|
118 | .save() |
---|
119 | |
---|
120 | def bloodSamplingProtocol = new Protocol( |
---|
121 | name: 'Liver sampling' |
---|
122 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
123 | |
---|
124 | bloodSamplingProtocol |
---|
125 | .addToParameters(new ProtocolParameter( |
---|
126 | name: 'Sample volume', |
---|
127 | unit: 'ml', |
---|
128 | type: ProtocolParameterType.FLOAT)) |
---|
129 | .save() |
---|
130 | |
---|
131 | // create system user |
---|
132 | /* |
---|
133 | def systemUser = userService.createUser(InstanceGenerator.user( |
---|
134 | username: 'system', |
---|
135 | pass: 'system', |
---|
136 | passConfirm: 'system', |
---|
137 | enabled: true |
---|
138 | )) |
---|
139 | */ |
---|
140 | |
---|
141 | def genderField = new TemplateSubjectField( |
---|
142 | name: 'Gender',type: TemplateFieldType.STRINGLIST, |
---|
143 | listEntries: ['Male','Female']) |
---|
144 | .with { if (!validate()) { errors.each { println it} } else save()} |
---|
145 | |
---|
146 | // Mouse template |
---|
147 | def mouseTemplate = new Template( |
---|
148 | name: 'Mouse' |
---|
149 | ).addToSubjectFields(new TemplateSubjectField( |
---|
150 | name: 'Genotype',type: TemplateFieldType.STRINGLIST, |
---|
151 | listEntries: ['C57/Bl6j','wild type'])) |
---|
152 | .addToSubjectFields(genderField) |
---|
153 | .addToSubjectFields(new TemplateSubjectField( |
---|
154 | name: 'Age',type: TemplateFieldType.INTEGER)) |
---|
155 | .addToSubjectFields(new TemplateSubjectField( |
---|
156 | name: 'Cage',type: TemplateFieldType.INTEGER)) |
---|
157 | .addToSubjectFields(new TemplateSubjectField( |
---|
158 | name: 'Some float', type: TemplateFieldType.FLOAT)) |
---|
159 | .addToSubjectFields(new TemplateSubjectField( |
---|
160 | name: 'Some ontology', type: TemplateFieldType.ONTOLOGYTERM)) |
---|
161 | .with { if (!validate()) { errors.each { println it} } else save()} |
---|
162 | |
---|
163 | // Human template |
---|
164 | def humanTemplate = new Template( |
---|
165 | name: 'Human') |
---|
166 | .addToSubjectFields(genderField) |
---|
167 | .with { if (!validate()) { errors.each { println it} } else save()} |
---|
168 | |
---|
169 | //events |
---|
170 | def eventTreatment = new EventDescription( |
---|
171 | name: 'Treatment', |
---|
172 | description: 'Experimental Treatment Protocol NuGO PPS3 leptin module', |
---|
173 | classification: treatmentTerm, |
---|
174 | protocol: treatmentProtocol, |
---|
175 | isSamplingEvent: false |
---|
176 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
177 | |
---|
178 | def samplingEvent = new EventDescription( |
---|
179 | name: 'Liver extraction', |
---|
180 | description: 'Liver sampling for transcriptomics arrays', |
---|
181 | protocol: liverSamplingProtocol, |
---|
182 | isSamplingEvent: true |
---|
183 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
184 | |
---|
185 | def bloodSamplingEvent = new EventDescription( |
---|
186 | name: 'Blood extraction', |
---|
187 | description: 'Blood extraction targeted at lipid assays', |
---|
188 | protocol: bloodSamplingProtocol, |
---|
189 | isSamplingEvent: true |
---|
190 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
191 | |
---|
192 | |
---|
193 | def eventTreatment2 = new EventDescription( |
---|
194 | name: 'Diet treatment', |
---|
195 | description: 'Treatment Protocol NuGO PPSH', |
---|
196 | protocol: treatmentProtocol2, |
---|
197 | isSamplingEvent: false |
---|
198 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
199 | |
---|
200 | println('Adding PPS3 study...') |
---|
201 | |
---|
202 | // studies |
---|
203 | def exampleStudy = new Study( |
---|
204 | title:"NuGO PPS3 mouse study leptin module", |
---|
205 | code:"PPS3_leptin_module", |
---|
206 | researchQuestion:"Leptin etc.", |
---|
207 | 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.", |
---|
208 | ecCode:"2007117.c", |
---|
209 | startDate: Date.parse('yyyy-MM-dd','2007-12-11'), |
---|
210 | template: mouseTemplate |
---|
211 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
212 | |
---|
213 | def x=1 |
---|
214 | 12.times { |
---|
215 | def currentSubject = new Subject( |
---|
216 | name: "A" + x++, |
---|
217 | species: mouseTerm, |
---|
218 | template: mouseTemplate, |
---|
219 | templateStringFields: ["Genotype" : "C57/Bl6j", "Gender" : "Male"], |
---|
220 | templateIntegerFields: ["Age" : 17, "Cage" : (int)(x/2)] |
---|
221 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
222 | |
---|
223 | exampleStudy.addToSubjects(currentSubject) |
---|
224 | .addToEvents(new Event( |
---|
225 | subject: currentSubject, |
---|
226 | startTime: Date.parse('yyyy-MM-dd','2008-01-07'), |
---|
227 | endTime: Date.parse('yyyy-MM-dd','2008-01-14'), |
---|
228 | eventDescription: eventTreatment, |
---|
229 | parameterStringValues: ['Diet':'10% fat (palm oil)','Compound':'Vehicle','Administration':'intraperitoneal injection']) |
---|
230 | ) |
---|
231 | .addToSamplingEvents(new SamplingEvent( |
---|
232 | subject: currentSubject, |
---|
233 | startTime: Date.parse('yyyy-MM-dd','2008-01-14'), |
---|
234 | endTime: Date.parse('yyyy-MM-dd','2008-01-14'), |
---|
235 | eventDescription: samplingEvent, |
---|
236 | parameterFloatValues: ['Sample weight':5F]) |
---|
237 | ) |
---|
238 | .with { if (!validate()) { errors.each { println it} } else save()} |
---|
239 | } |
---|
240 | |
---|
241 | println 'Adding PPSH study' |
---|
242 | |
---|
243 | def humanStudy = new Study( |
---|
244 | title:"NuGO PPS human study", |
---|
245 | code:"PPSH", |
---|
246 | researchQuestion:"etc.", |
---|
247 | description:"Human study", |
---|
248 | ecCode:"unknown", |
---|
249 | startDate: Date.parse('yyyy-MM-dd','2008-01-11'), |
---|
250 | template: humanTemplate |
---|
251 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
252 | |
---|
253 | def y=1 |
---|
254 | 5.times { |
---|
255 | def currentSubject = new Subject( |
---|
256 | name: "A" + y++, |
---|
257 | species: humanTerm, |
---|
258 | template: humanTemplate, |
---|
259 | templateStringFields: ["Gender" : "Male"], |
---|
260 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
261 | |
---|
262 | humanStudy.addToSubjects(currentSubject) |
---|
263 | .addToEvents(new Event( |
---|
264 | subject: currentSubject, |
---|
265 | startTime: Date.parse('yyyy-MM-dd','2008-01-14'), |
---|
266 | endTime: Date.parse('yyyy-MM-dd','2008-01-14'), |
---|
267 | eventDescription: eventTreatment2, |
---|
268 | parameterStringValues: ['Diet':'99% fat (crude oil)','BackgroundDiet':'Mediterranean diet']) |
---|
269 | ) |
---|
270 | .addToSamplingEvents(new SamplingEvent( |
---|
271 | subject: currentSubject, |
---|
272 | startTime: Date.parse('yyyy-MM-dd','2008-01-14'), |
---|
273 | endTime: Date.parse('yyyy-MM-dd','2008-01-14'), |
---|
274 | eventDescription: bloodSamplingEvent, |
---|
275 | parameterFloatValues: ['Sample volume':4.5F]) |
---|
276 | .addToSamples(new Sample( |
---|
277 | name: currentSubject.name + '_B', |
---|
278 | material: bloodTerm |
---|
279 | )) |
---|
280 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
281 | } |
---|
282 | |
---|
283 | // new Study(title:"example",code:"Excode",researchQuestion:"ExRquestion",description:"Exdescription",ecCode:"ExecCode",dateCreated:new Date(),lastUpdated:new Date(),startDate:new Date()).save() |
---|
284 | // new Study(title:"testAgain",code:"testcode",researchQuestion:"testRquestion",description:"testdescription",ecCode:"testCode",dateCreated:new Date(),lastUpdated:new Date(),startDate:new Date()).save() |
---|
285 | // new Study(title:"Exampletest",code:"Examplecode",researchQuestion:"ExampleRquestion",description:"Exampledescription",ecCode:"ExampleecCode",dateCreated:new Date(),lastUpdated:new Date(),startDate:new Date()).save() |
---|
286 | |
---|
287 | // Add clinical data |
---|
288 | |
---|
289 | def lipidAssay = new dbnp.clinicaldata.ClinicalAssay( |
---|
290 | name: 'Lipid profile', |
---|
291 | approved: true |
---|
292 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
293 | |
---|
294 | def ldlMeasurement = new dbnp.clinicaldata.ClinicalMeasurement( |
---|
295 | name: 'LDL', |
---|
296 | unit: 'mg/dL', |
---|
297 | type: dbnp.data.FeatureType.QUANTITATIVE, |
---|
298 | referenceValues: '100 mg/dL', |
---|
299 | detectableLimit: 250, |
---|
300 | isDrug: false, isIntake: true, inSerum: true |
---|
301 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
302 | |
---|
303 | def hdlMeasurement = new dbnp.clinicaldata.ClinicalMeasurement( |
---|
304 | name: 'HDL', |
---|
305 | unit: 'mg/dL', |
---|
306 | type: dbnp.data.FeatureType.QUANTITATIVE, |
---|
307 | referenceValues: '50 mg/dL', |
---|
308 | detectableLimit: 100, |
---|
309 | isDrug: false, isIntake: true, inSerum: true |
---|
310 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
311 | |
---|
312 | lipidAssay.addToMeasurements ldlMeasurement |
---|
313 | lipidAssay.addToMeasurements hdlMeasurement |
---|
314 | |
---|
315 | def lipidAssayInstance = new dbnp.clinicaldata.ClinicalAssayInstance( |
---|
316 | assay: lipidAssay |
---|
317 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
318 | |
---|
319 | humanStudy.giveSamples()*.each { |
---|
320 | new dbnp.clinicaldata.ClinicalFloatData( |
---|
321 | assay: lipidAssayInstance, |
---|
322 | measurement: ldlMeasurement, |
---|
323 | sample: it.name, |
---|
324 | value: Math.round(Math.random()*ldlMeasurement.detectableLimit) |
---|
325 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
326 | |
---|
327 | new dbnp.clinicaldata.ClinicalFloatData( |
---|
328 | assay: lipidAssayInstance, |
---|
329 | measurement: hdlMeasurement, |
---|
330 | sample: it.name, |
---|
331 | value: Math.round(Math.random()*hdlMeasurement.detectableLimit) |
---|
332 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
333 | } |
---|
334 | |
---|
335 | // Add assay to study capture module |
---|
336 | |
---|
337 | def clinicalModule = new AssayModule( |
---|
338 | name: 'Clinical data', |
---|
339 | type: AssayType.CLINICAL_DATA, |
---|
340 | platform: 'clinical measurements', |
---|
341 | url: 'http://localhost:8080/gscf' |
---|
342 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
343 | |
---|
344 | def lipidAssayRef = new Assay( |
---|
345 | name: 'Lipid profiling', |
---|
346 | module: clinicalModule, |
---|
347 | externalAssayId: lipidAssayInstance.id |
---|
348 | ).with { if (!validate()) { errors.each { println it} } else save()} |
---|
349 | |
---|
350 | humanStudy.giveSamples()*.each { |
---|
351 | lipidAssayRef.addToSamples(it) |
---|
352 | } |
---|
353 | lipidAssayRef.save() |
---|
354 | |
---|
355 | humanStudy.addToAssays(lipidAssayRef); |
---|
356 | humanStudy.save() |
---|
357 | } |
---|
358 | } |
---|
359 | |
---|
360 | def destroy = { |
---|
361 | } |
---|
362 | } |
---|