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

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

getting studies back in bootstrap

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