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

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