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

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

added plant template to BootStrap?

  • Property svn:keywords set to Author Rev Date
File size: 26.2 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
7import java.text.SimpleDateFormat
8
9/**
10 * Application Bootstrapper
11 * @Author Jeroen Wesbeek
12 * @Since 20091021
13 *
14 * Revision information:
15 * $Rev: 339 $
16 * $Author: keesvb $
17 * $Date: 2010-04-12 14:19:28 +0000 (ma, 12 apr 2010) $
18 */
19class BootStrap {
20        def init = {servletContext ->
21                // define timezone
22                System.setProperty('user.timezone', 'CET')
23
24                // we could also check if we are in development by GrailsUtil.environment == GrailsApplication.ENV_DEVELOPMENT
25                if (Study.count() == 0) {
26                        printf("development bootstrapping....\n\n");
27
28                        // ontologies
29                        def speciesOntology = new Ontology(
30                                name: 'NCBI Taxonomy',
31                                shortName: 'Taxon',
32                                url: 'http://www.obofoundry.org/cgi-bin/detail.cgi?id=ncbi_taxonomy'
33                        ).with { if (!validate()) { errors.each { println it} } else save()}
34
35                        def humanBodyOntology = new Ontology(
36                                name: 'Foundational Model of Anatomy',
37                                shortName: 'HumanBody',
38                                url: 'http://bioportal.bioontology.org/ontologies/39966'
39                        ).with { if (!validate()) { errors.each { println it} } else save()}
40
41                        def nciOntology = new Ontology(
42                                name: 'NCI Thesaurus',
43                                shortName: 'NCI',
44                                url: 'http://bioportal.bioontology.org/ontologies/42331'
45                        ).with { if (!validate()) { errors.each { println it} } else save()}
46
47                        // terms
48                        def mouseTerm = new Term(
49                                name: 'Mus musculus',
50                                ontology: speciesOntology,
51                                accession: '10090'
52                        ).with { if (!validate()) { errors.each { println it} } else save()}
53                        def humanTerm = new Term(
54                                name: 'Homo sapiens',
55                                ontology: speciesOntology,
56                                accession: '9606'
57                        ).with { if (!validate()) { errors.each { println it} } else save()}
58                        def arabTerm = new Term(
59                                name: 'Arabidopsis thaliana',
60                                ontology: speciesOntology,
61                                accession: '3702'
62                        ).with { if (!validate()) { errors.each { println it} } else save()}
63                       
64                        def bloodTerm = new Term(
65                                name: 'Portion of blood',
66                                ontology: humanBodyOntology,
67                                accession: '9670'
68                        ).with { if (!validate()) { errors.each { println it} } else save()}
69
70                        def c57bl6Term = new Term(
71                                name: 'C57BL/6 Mouse',
72                                ontology: nciOntology,
73                                accession: 'C14424'
74                        ).with { if (!validate()) { errors.each { println it} } else save()}
75
76                        def madmaxOntology = new Ontology(
77                                name: 'Madmax ontology',
78                                shortName: 'MDMX',
79                                url: 'madmax.bioinformatics.nl'
80                        ).with { if (!validate()) { errors.each { println it} } else save()}
81
82                        def treatmentTerm = new Term(
83                                name: 'ExperimentalProtocol',
84                                ontology: madmaxOntology,
85                                accession: 'P-MDMXGE-264'
86                        ).with { if (!validate()) { errors.each { println it} } else save()}
87
88                        def dietProtocol = new Protocol(
89                                name: 'Diet treatment Protocol NuGO PPS3 leptin module',
90                                reference: treatmentTerm
91                        ).with { if (!validate()) { errors.each { println it} } else save()}
92
93                        def boostProtocol = new Protocol(
94                                name: 'Boost treatment Protocol NuGO PPS3 leptin module',
95                                reference: treatmentTerm
96                        ).with { if (!validate()) { errors.each { println it} } else save()}
97
98                        def fastingProtocol = new Protocol(
99                                name: 'Fasting',
100                                reference: treatmentTerm
101                        ).with { if (!validate()) { errors.each { println it} } else save()}
102
103
104                        // ParameterStringListItems
105                        def oil10= new ParameterStringListItem(
106                                name: '10% fat (palm oil)'
107                        ).with { if (!validate()) { errors.each { println it} } else save()}
108                        def oil45= new ParameterStringListItem(
109                                name: '45% fat (palm oil)'
110                        ).with { if (!validate()) { errors.each { println it} } else save()}
111                        def vehicle= new ParameterStringListItem(
112                                name: 'Vehicle'
113                        ).with { if (!validate()) { errors.each { println it} } else save()}
114                        def leptin= new ParameterStringListItem(
115                                name: 'Leptin'
116                        ).with { if (!validate()) { errors.each { println it} } else save()}
117
118
119                        dietProtocol
120                        .addToParameters(new ProtocolParameter(
121                                name: 'Diet',
122                                type: ProtocolParameterType.STRINGLIST,
123                                listEntries: [oil10,oil45]))
124                        .save()
125
126                        boostProtocol
127                        .addToParameters(new ProtocolParameter(
128                                name: 'Compound',
129                                type: ProtocolParameterType.STRINGLIST,
130                                listEntries: [vehicle,leptin]))
131                        .save()
132
133                        fastingProtocol
134                        .addToParameters(new ProtocolParameter(
135                                name: 'Fasting period',
136                                type: ProtocolParameterType.STRING))
137                        .save()
138
139
140                        // sampling event protocols
141
142                        def liverSamplingProtocol = new Protocol(
143                                name: 'Liver sampling'
144                        ).with { if (!validate()) { errors.each { println it} } else save()}
145
146                        liverSamplingProtocol
147                        .addToParameters(new ProtocolParameter(
148                                name: 'Sample weight',
149                                unit: 'mg',
150                                type: ProtocolParameterType.FLOAT))
151                        .save()
152
153                        def bloodSamplingProtocol = new Protocol(
154                                name: 'Blood sampling'
155                        ).with { if (!validate()) { errors.each { println it} } else save()}
156
157                        bloodSamplingProtocol
158                        .addToParameters(new ProtocolParameter(
159                                name: 'Sample volume',
160                                unit: 'ml',
161                                type: ProtocolParameterType.FLOAT))
162                        .save()
163
164                        // create system user
165
166                        /*def systemUser = userService.createUser(InstanceGenerator.user(
167                                username: 'system',
168                                pass: 'system',
169                                passConfirm: 'system',
170                                enabled: true
171                        ))*/
172
173
174                        def genderField = new TemplateField(
175                                name: 'Gender',type: TemplateFieldType.STRINGLIST,
176                                listEntries: [new TemplateFieldListItem(name:'Male'),new TemplateFieldListItem(name: 'Female')])
177                        .with { if (!validate()) { errors.each { println it} } else save()}
178
179                        def ageField = new TemplateField(
180                                name: 'Age (years)',type: TemplateFieldType.INTEGER,unit: 'years')
181                        .with { if (!validate()) { errors.each { println it} } else save()}
182
183                        def genotypeField = new TemplateField(
184                                name: 'Genotype', type: TemplateFieldType.ONTOLOGYTERM)
185                        .with { if (!validate()) { errors.each { println it} } else save()}
186
187                        def genotypeTypeField = new TemplateField(
188                                name: 'Genotype type',type: TemplateFieldType.STRINGLIST,
189                                listEntries: [new TemplateFieldListItem(name:'transgenic'),
190                                        new TemplateFieldListItem(name:'knock-out'),
191                                        new TemplateFieldListItem(name:'knock-in')])
192                        .with { if (!validate()) { errors.each { println it} } else save()}
193
194
195                        // Nutritional study template
196
197                        println "Adding academic study template..."
198                        def studyTemplate = new Template(
199                                name: 'Academic study', entity: dbnp.studycapturing.Study)
200                                .addToFields(new TemplateField(name: 'Consortium',type: TemplateFieldType.STRING))
201                                .addToFields(new TemplateField(name: 'Cohort name',type: TemplateFieldType.STRING))
202                                .addToFields(new TemplateField(name: 'Time zone',type: TemplateFieldType.STRING))
203                                .addToFields(new TemplateField(name: 'Responsible scientist',type: TemplateFieldType.STRING))
204                                .addToFields(new TemplateField(name: 'Lab code',type: TemplateFieldType.STRING))
205                                .addToFields(new TemplateField(name: 'Institute',type: TemplateFieldType.STRING))
206                        .with { if (!validate()) { errors.each { println it} } else save()}
207
208                        // Mouse template
209                        def mouseTemplate = new Template(
210                                name: 'Mouse', entity: dbnp.studycapturing.Subject)
211                        .addToFields(new TemplateField(
212                                name: 'Strain', type: TemplateFieldType.ONTOLOGYTERM))
213                        .addToFields(genotypeField)
214                        .addToFields(genotypeTypeField)
215                        .addToFields(genderField)
216                        .addToFields(new TemplateField(
217                                name: 'Age (weeks)', type: TemplateFieldType.INTEGER, unit: 'weeks'))
218                        .addToFields(new TemplateField(
219                                name: 'Age type',type: TemplateFieldType.STRINGLIST,
220                                listEntries: [new TemplateFieldListItem(name:'postnatal'),new TemplateFieldListItem(name:'embryonal')]))
221                        .addToFields(new TemplateField(
222                                name: 'Cage',type: TemplateFieldType.STRING))
223                        .addToFields(new TemplateField(
224                                name: '#Mice in cage',type: TemplateFieldType.INTEGER))
225                        .addToFields(new TemplateField(
226                                name: 'Litter size',type: TemplateFieldType.INTEGER))
227                        .addToFields(new TemplateField(
228                                name: 'Weight (g)', type: TemplateFieldType.DOUBLE, unit: 'gram'))
229                        .with { if (!validate()) { errors.each { println it} } else save()}
230
231                        // Human template
232                        def humanTemplate = new Template(
233                                name: 'Human', entity: dbnp.studycapturing.Subject)
234                        .addToFields(genderField)
235                        .addToFields(ageField)
236                        .addToFields(new TemplateField(
237                                name: 'DOB',type: TemplateFieldType.DATE))
238                        .addToFields(new TemplateField(
239                                name: 'Height',type: TemplateFieldType.DOUBLE, unit: 'm'))
240                        .addToFields(new TemplateField(
241                                name: 'Weight (kg)',type: TemplateFieldType.DOUBLE, unit: 'kg'))
242                        .addToFields(new TemplateField(
243                                name: 'BMI',type: TemplateFieldType.DOUBLE, unit: 'kg/m2'))
244                        .addToFields(new TemplateField(
245                                name: 'Race',type: TemplateFieldType.STRING))
246                        .addToFields(new TemplateField(
247                                name: 'Waist circumference',type: TemplateFieldType.FLOAT, unit: 'cm'))
248                        .addToFields(new TemplateField(
249                                name: 'Hip circumference',type: TemplateFieldType.FLOAT, unit: 'cm'))
250                        .addToFields(new TemplateField(
251                                name: 'Systolic blood pressure',type: TemplateFieldType.FLOAT, unit: 'mmHg'))
252                        .addToFields(new TemplateField(
253                                name: 'Diastolic blood pressure',type: TemplateFieldType.FLOAT, unit: 'mmHg'))
254                        .addToFields(new TemplateField(
255                                name: 'Heart rate',type: TemplateFieldType.FLOAT, unit: 'beats/min'))
256                        .addToFields(new TemplateField(
257                                name: 'Run-in-food',type: TemplateFieldType.TEXT))
258                        .with { if (!validate()) { errors.each { println it} } else save()}
259
260
261                        def sampleDescriptionField = new TemplateField(
262                                name: 'Description',type: TemplateFieldType.TEXT)
263                        .with { if (!validate()) { errors.each { println it} } else save()}
264                        def sampleTypeField = new TemplateField(
265                                name: 'SampleType',type: TemplateFieldType.STRING)
266                        .with { if (!validate()) { errors.each { println it} } else save()}
267                        def sampleProtocolField = new TemplateField(
268                                name: 'SampleProtocol',type: TemplateFieldType.STRING)
269                        .with { if (!validate()) { errors.each { println it} } else save()}
270                        def sampleVialTextField = new TemplateField(
271                                name: 'Text on vial',type: TemplateFieldType.STRING)
272                        .with { if (!validate()) { errors.each { println it} } else save()}
273
274                        // Human sample template
275                        def humanSampleTemplate = new Template(
276                                name: 'Human tissue sample', entity: dbnp.studycapturing.Sample)
277                        .addToFields(sampleDescriptionField)
278                        .addToFields(sampleTypeField)
279                        .addToFields(sampleProtocolField)
280                        .addToFields(sampleVialTextField)
281                        .with { if (!validate()) { errors.each { println it} } else save()}
282
283                        //Plant template
284                        def plantTemplate = new Template(
285                                name: 'Plant template', entity: dbnp.studycapturing.Subject)
286                        .addToFields(new TemplateField(
287                                name: 'Variety', type: TemplateFieldType.STRING))
288                        .addToFields(new TemplateField(
289                                name: 'Ecotype', type: TemplateFieldType.STRING))
290                        .addToFields(genotypeField)
291                        .addToFields(genotypeTypeField)
292                        .addToFields(new TemplateField(
293                                name: 'Growth location', type: TemplateFieldType.STRINGLIST,
294                                listEntries: [new TemplateFieldListItem(name:'Greenhouse'),new TemplateFieldListItem(name: 'Field')]))
295                        .addToFields(new TemplateField(
296                                name: 'Room', type: TemplateFieldType.STRING,
297                                comment: 'Chamber number in case of Greenhouse'))
298                        .addToFields(new TemplateField(
299                                name: 'Position X', type: TemplateFieldType.FLOAT))
300                        .addToFields(new TemplateField(
301                                name: 'Position Y', type: TemplateFieldType.FLOAT))
302                        .addToFields(new TemplateField(
303                                name: 'Block', type: TemplateFieldType.STRING))
304                        .addToFields(new TemplateField(
305                                name: 'Temperature at day', type: TemplateFieldType.FLOAT))
306                        .addToFields(new TemplateField(
307                                name: 'Temperature at night', type: TemplateFieldType.FLOAT))
308                        .addToFields(new TemplateField(
309                                name: 'Photo period', type: TemplateFieldType.STRING))
310                        .addToFields(new TemplateField(
311                                name: 'Light intensity', type: TemplateFieldType.STRING))
312                        .addToFields(new TemplateField(
313                                name: 'Start date', type: TemplateFieldType.DATE))
314                        .addToFields(new TemplateField(
315                                name: 'Harvest date', type: TemplateFieldType.DATE))
316                        .addToFields(new TemplateField(
317                                name: 'Growth type', type: TemplateFieldType.STRINGLIST,
318                                listEntries: [new TemplateFieldListItem(name:'Standard'),new TemplateFieldListItem(name: 'Experimental')]))
319                        .addToFields(new TemplateField(
320                                name: 'Growth protocol', type: TemplateFieldType.TEXT))
321                        .addToFields(new TemplateField(
322                                name: 'Harvest delay', type: TemplateFieldType.TEXT))
323                        .with { if (!validate()) { errors.each { println it} } else save()}
324
325                        def plantSampleTemplate = new Template(
326                                name: 'Plant sample', entity: dbnp.studycapturing.Sample)
327                        .addToFields(sampleDescriptionField)
328                        .addToFields(sampleTypeField)
329                        .addToFields(sampleProtocolField)
330                        .addToFields(sampleVialTextField)
331                        .with { if (!validate()) { errors.each { println it} } else save()}
332
333
334                        //events
335                        def eventDiet = new EventDescription(
336                                name: 'Diet treatment',
337                                description: 'Diet treatment (fat percentage)',
338                                classification: treatmentTerm,
339                                protocol: dietProtocol,
340                                isSamplingEvent: false
341                        ).with { if (!validate()) { errors.each { println it} } else save()}
342
343                        def eventBoost = new EventDescription(
344                                name: 'Boost treatment',
345                                description: 'Boost treatment (leptin or vehicle)',
346                                classification: treatmentTerm,
347                                protocol: boostProtocol,
348                                isSamplingEvent: false
349                        ).with { if (!validate()) { errors.each { println it} } else save()}
350
351                        def samplingEvent = new EventDescription(
352                                name: 'Liver extraction',
353                                description: 'Liver sampling for transcriptomics arrays',
354                                protocol: liverSamplingProtocol,
355                                isSamplingEvent: true
356                        ).with { if (!validate()) { errors.each { println it} } else save()}
357
358                        def bloodSamplingEventDescription = new EventDescription(
359                                name: 'Blood extraction',
360                                description: 'Blood extraction targeted at lipid assays',
361                                protocol: bloodSamplingProtocol,
362                                isSamplingEvent: true
363                        ).with { if (!validate()) { errors.each { println it} } else save()}
364
365
366            def fastingTreatment = new EventDescription(
367                                name: 'Fasting treatment',
368                                description: 'Fasting Protocol NuGO PPSH',
369                                protocol: fastingProtocol,
370                                isSamplingEvent: false
371                        ).with { if (!validate()) { errors.each { println it} } else save()}
372
373                        println('Adding PPS3 study...')
374
375                        // studies
376                        def exampleStudy = new Study(
377                                template: studyTemplate,
378                                title:"NuGO PPS3 mouse study leptin module",
379                                code:"PPS3_leptin_module",
380                                researchQuestion:"Leptin etc.",
381                                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.",
382                                ecCode:"2007117.c",
383                                startDate: Date.parse('yyyy-MM-dd','2007-12-11')
384                        ).with { if (!validate()) { errors.each { println it} } else save()}
385
386                        def exampleHumanStudy = new Study(
387                                template: humanTemplate,
388                                title:"Human example template",
389                                code:"Human example code",
390                                researchQuestion:"Leptin etc.",
391                                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.",
392                                ecCode:"2007117.c",
393                                startDate: Date.parse('yyyy-MM-dd','2007-12-11')
394                        ).with { if (!validate()) { errors.each { println it} } else save()}
395
396                        def evLF = new Event(
397                                startTime: Date.parse('yyyy-MM-dd','2008-01-07'),
398                                endTime: Date.parse('yyyy-MM-dd','2008-01-14'),
399                                eventDescription: eventDiet,
400                                parameterStringValues: ['Diet':'10% fat (palm oil)']
401                        ).with { if (!validate()) { errors.each { println it} } else save()}
402
403                        def evHF = new Event(
404                                startTime: Date.parse('yyyy-MM-dd','2008-01-07'),
405                                endTime: Date.parse('yyyy-MM-dd','2008-01-14'),
406                                eventDescription: eventDiet,
407                                parameterStringValues: ['Diet':'45% fat (palm oil)']
408                        ).with { if (!validate()) { errors.each { println it} } else save()}
409
410                        def evBV = new Event(
411                                startTime: Date.parse('yyyy-MM-dd','2008-01-07'),
412                                endTime: Date.parse('yyyy-MM-dd','2008-01-14'),
413                                eventDescription: eventBoost,
414                                parameterStringValues: ['Compound':'Vehicle']
415                        ).with { if (!validate()) { errors.each { println it} } else save()}
416
417                        def evBL = new Event(
418                                startTime: Date.parse('yyyy-MM-dd','2008-01-07'),
419                                endTime: Date.parse('yyyy-MM-dd','2008-01-14'),
420                                eventDescription: eventBoost,
421                                parameterStringValues: ['Compound':'Leptin']
422                        ).with { if (!validate()) { errors.each { println it} } else save()}
423
424                        def evLF4 = new Event(
425                                startTime: Date.parse('yyyy-MM-dd','2008-01-07'),
426                                endTime: Date.parse('yyyy-MM-dd','2008-02-04'),
427                                eventDescription: eventDiet,
428                                parameterStringValues: ['Diet':'10% fat (palm oil)']
429                        ).with { if (!validate()) { errors.each { println it} } else save()}
430
431                        def evHF4 = new Event(
432                                startTime: Date.parse('yyyy-MM-dd','2008-01-07'),
433                                endTime: Date.parse('yyyy-MM-dd','2008-02-04'),
434                                eventDescription: eventDiet,
435                                parameterStringValues: ['Diet':'45% fat (palm oil)']
436                        ).with { if (!validate()) { errors.each { println it} } else save()}
437
438                        def evBV4 = new Event(
439                                startTime: Date.parse('yyyy-MM-dd','2008-01-07'),
440                                endTime: Date.parse('yyyy-MM-dd','2008-02-04'),
441                                eventDescription: eventBoost,
442                                parameterStringValues: ['Compound':'Vehicle']
443                        ).with { if (!validate()) { errors.each { println it} } else save()}
444
445                        def evBL4 = new Event(
446                                startTime: Date.parse('yyyy-MM-dd','2008-01-07'),
447                                endTime: Date.parse('yyyy-MM-dd','2008-02-04'),
448                                eventDescription: eventBoost,
449                                parameterStringValues: ['Compound':'Leptin']
450                        ).with { if (!validate()) { errors.each { println it} } else save()}
451
452                        def evS = new SamplingEvent(
453                                        startTime: Date.parse('yyyy-MM-dd','2008-01-14'),
454                                        endTime: Date.parse('yyyy-MM-dd','2008-01-14'),
455                                        eventDescription: samplingEvent,
456                                        parameterFloatValues: ['Sample weight':5F]
457                        ).with { if (!validate()) { errors.each { println it} } else save()}
458
459                        def evS4 = new SamplingEvent(
460                                        startTime: Date.parse('yyyy-MM-dd','2008-02-04'),
461                                        endTime: Date.parse('yyyy-MM-dd','2008-02-04'),
462                                        eventDescription: samplingEvent,
463                                        parameterFloatValues: ['Sample weight':5F]
464                        ).with { if (!validate()) { errors.each { println it} } else save()}
465
466                        // Add events to study
467                        exampleStudy
468                        .addToEvents(evLF)
469                        .addToEvents(evHF)
470                        .addToEvents(evBV)
471                        .addToEvents(evBL)
472                        .addToEvents(evLF4)
473                        .addToEvents(evHF4)
474                        .addToEvents(evBV4)
475                        .addToEvents(evBL4)
476                        .addToSamplingEvents(evS)
477                        .addToSamplingEvents(evS4)
478                        .save()
479
480                        def LFBV1 = new EventGroup(name:"10% fat + vehicle for 1 week")
481                        .addToEvents(evLF)
482                        .addToEvents(evBV)
483                        .with { if (!validate()) { errors.each { println it} } else save()}
484
485                        def LFBL1 = new EventGroup(name:"10% fat + leptin for 1 week")
486                        .addToEvents(evLF)
487                        .addToEvents(evBL)
488                        .with { if (!validate()) { errors.each { println it} } else save()}
489
490                        def HFBV1 = new EventGroup(name:"45% fat + vehicle for 1 week")
491                        .addToEvents(evHF)
492                        .addToEvents(evBV)
493                        .with { if (!validate()) { errors.each { println it} } else save()}
494
495                        def HFBL1 = new EventGroup(name:"45% fat + leptin for 1 week")
496                        .addToEvents(evHF)
497                        .addToEvents(evBL)
498                        .with { if (!validate()) { errors.each { println it} } else save()}
499
500                        def LFBV4 = new EventGroup(name:"10% fat + vehicle for 4 weeks")
501                        .addToEvents(evLF4)
502                        .addToEvents(evBV4)
503                        .with { if (!validate()) { errors.each { println it} } else save()}
504
505                        def LFBL4 = new EventGroup(name:"10% fat + leptin for 4 weeks")
506                        .addToEvents(evLF4)
507                        .addToEvents(evBL4)
508                        .with { if (!validate()) { errors.each { println it} } else save()}
509
510                        def HFBV4 = new EventGroup(name:"45% fat + vehicle for 4 weeks")
511                        .addToEvents(evHF4)
512                        .addToEvents(evBV4)
513                        .with { if (!validate()) { errors.each { println it} } else save()}
514
515                        def HFBL4 = new EventGroup(name:"45% fat + leptin for 4 weeks")
516                        .addToEvents(evHF4)
517                        .addToEvents(evBL4)
518                        .with { if (!validate()) { errors.each { println it} } else save()}
519
520            // Add subjects and samples and compose EventGroups
521
522                        def x=1
523                        80.times {
524                                def currentSubject = new Subject(
525                                        name: "A" + x++,
526                                        species: mouseTerm,
527                                        template: mouseTemplate,
528                                )
529                                .setFieldValue("Gender", "Male")
530                                .setFieldValue("Genotype", c57bl6Term)
531                                .setFieldValue("Age (weeks)", 17)
532                                .setFieldValue("Cage", "" + (int)(x/2))
533                                .with { if (!validate()) { errors.each { println it} } else save()}
534
535                                exampleStudy.addToSubjects(currentSubject)
536                                .with { if (!validate()) { errors.each { println it} } else save()}
537
538                                // Add subject to appropriate EventGroup
539                                if (x > 70) { HFBL4.addToSubjects(currentSubject).save() }
540                                else if (x > 60) { HFBV4.addToSubjects(currentSubject).save() }
541                                else if (x > 50) { LFBL4.addToSubjects(currentSubject).save() }
542                                else if (x > 40) { LFBV4.addToSubjects(currentSubject).save() }
543                                else if (x > 30) { HFBL1.addToSubjects(currentSubject).save() }
544                                else if (x > 20) { HFBV1.addToSubjects(currentSubject).save() }
545                                else if (x > 10) { LFBL1.addToSubjects(currentSubject).save() }
546                                else             { LFBV1.addToSubjects(currentSubject).save() }
547
548                        }
549
550                        // Add EventGroups to study
551                        exampleStudy
552                        .addToEventGroups(LFBV1)
553                        .addToEventGroups(LFBL1)
554                        .addToEventGroups(HFBV1)
555                        .addToEventGroups(HFBL1)
556                        .addToEventGroups(LFBV4)
557                        .addToEventGroups(LFBL4)
558                        .addToEventGroups(HFBV4)
559                        .addToEventGroups(HFBL4)
560                        .save()
561
562                        println 'Adding PPSH study'
563
564                        def humanStudy = new Study(
565                                template: studyTemplate,
566                                title:"NuGO PPS human study",
567                                code:"PPSH",
568                                researchQuestion:"How much are fasting plasma and urine metabolite levels affected by prolonged fasting ?",
569                                description:"Human study",
570                                ecCode:"unknown",
571                                startDate: Date.parse('yyyy-MM-dd','2009-01-01')
572                        ).with { if (!validate()) { errors.each { println it} } else save()}
573
574                        def fastingEvent = new Event(
575                                        startTime: Date.parse('yyyy-MM-dd','2008-01-14'),
576                                        endTime: Date.parse('yyyy-MM-dd','2008-01-14'),
577                                        eventDescription: fastingTreatment,
578                                        parameterStringValues: ['Fasting period':'8h']);
579
580                        def bloodSamplingEvent = new SamplingEvent(
581                                        startTime: Date.parse('yyyy-MM-dd','2008-01-14'),
582                                        endTime: Date.parse('yyyy-MM-dd','2008-01-14'),
583                                        eventDescription: bloodSamplingEventDescription,
584                                        parameterFloatValues: ['Sample volume':4.5F]);
585
586                        def rootGroup = new EventGroup(name: 'Root group');
587                        rootGroup.addToEvents fastingEvent
588                        rootGroup.addToEvents bloodSamplingEvent
589                        rootGroup.save()
590
591            def y = 1
592            11.times {
593              def currentSubject = new Subject(
594                      name: "" + y++,
595                      species: humanTerm,
596                      template: humanTemplate).setFieldValue("Gender", (boolean) (x / 2) ? "Male" : "Female").setFieldValue("DOB", new java.text.SimpleDateFormat("dd-mm-yy").parse("01-02-19" + (10 + (int) (Math.random() * 80)))).setFieldValue("Age (years)", 30).setFieldValue("Height", Math.random() * 2F).setFieldValue("Weight (kg)", Math.random() * 150F).setFieldValue("BMI", 20 + Math.random() * 10F).with { if (!validate()) { errors.each { println it} } else save()}
597
598              rootGroup.addToSubjects currentSubject
599              rootGroup.save()
600
601              def currentSample = new Sample(
602                      name: currentSubject.name + '_B',
603                      material: bloodTerm,
604                      parentSubject: currentSubject,
605                      parentEvent: bloodSamplingEvent);
606
607
608              humanStudy.addToSubjects(currentSubject).addToSamples(currentSample).with { if (!validate()) { errors.each { println it} } else save()}
609          }
610
611          humanStudy.addToEvents(fastingEvent)
612          humanStudy.addToSamplingEvents(bloodSamplingEvent)
613          humanStudy.addToEventGroups rootGroup
614          humanStudy.save()
615
616                        // Add clinical data
617
618                        def lipidAssay = new dbnp.clinicaldata.ClinicalAssay(
619                                name: 'Lipid profile',
620                                approved: true
621                        ).with { if (!validate()) { errors.each { println it} } else save()}
622
623                        def ldlMeasurement = new dbnp.clinicaldata.ClinicalMeasurement(
624                                name: 'LDL',
625                                unit: 'mg/dL',
626                                type: dbnp.data.FeatureType.QUANTITATIVE,
627                                referenceValues: '100 mg/dL',
628                                detectableLimit: 250,
629                                isDrug: false, isIntake: true, inSerum: true
630                        ).with { if (!validate()) { errors.each { println it} } else save()}
631
632                        def hdlMeasurement = new dbnp.clinicaldata.ClinicalMeasurement(
633                                name: 'HDL',
634                                unit: 'mg/dL',
635                                type: dbnp.data.FeatureType.QUANTITATIVE,
636                                referenceValues: '50 mg/dL',
637                                detectableLimit: 100,
638                                isDrug: false, isIntake: true, inSerum: true
639                        ).with { if (!validate()) { errors.each { println it} } else save()}
640
641                        lipidAssay.addToMeasurements ldlMeasurement
642                        lipidAssay.addToMeasurements hdlMeasurement
643
644                        def lipidAssayInstance = new dbnp.clinicaldata.ClinicalAssayInstance(
645                                assay: lipidAssay
646                        ).with { if (!validate()) { errors.each { println it} } else save()}
647
648                        humanStudy.samples*.each {
649                                new dbnp.clinicaldata.ClinicalFloatData(
650                                        assay: lipidAssayInstance,
651                                        measurement: ldlMeasurement,
652                                        sample: it.name,
653                                        value: Math.round(Math.random()*ldlMeasurement.detectableLimit)
654                                ).with { if (!validate()) { errors.each { println it} } else save()}
655
656                                new dbnp.clinicaldata.ClinicalFloatData(
657                                        assay: lipidAssayInstance,
658                                        measurement: hdlMeasurement,
659                                        sample: it.name,
660                                        value: Math.round(Math.random()*hdlMeasurement.detectableLimit)
661                                ).with { if (!validate()) { errors.each { println it} } else save()}
662                        }
663
664                        // Add assay to study capture module
665
666                        def clinicalModule = new AssayModule(
667                                name: 'Clinical data',
668                                type: AssayType.CLINICAL_DATA,
669                                platform: 'clinical measurements',
670                                url: 'http://localhost:8080/gscf'
671                        ).with { if (!validate()) { errors.each { println it} } else save()}
672
673                        def lipidAssayRef = new Assay(
674                                name: 'Lipid profiling',
675                                module: clinicalModule,
676                                externalAssayId: lipidAssayInstance.id
677                        ).with { if (!validate()) { errors.each { println it} } else save()}
678
679                        humanStudy.samples*.each {
680                                lipidAssayRef.addToSamples(it)
681                        }
682                        lipidAssayRef.save()
683
684                        humanStudy.addToAssays(lipidAssayRef);
685                        humanStudy.save()
686
687                }
688        }
689
690        def destroy = {
691        }
692} 
Note: See TracBrowser for help on using the repository browser.