source: trunk/grails-app/conf/BootStrapStudies.groovy @ 835

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

added metabolomics assay examples, cleaned up RestController?, changed assay show link for SAM

  • Property svn:keywords set to Author Date Rev
File size: 16.8 KB
Line 
1/**
2 * @Author kees
3 * @Since Jun 25, 2010
4 *
5 * Revision information:
6 * $Rev: 835 $
7 * $Author: keesvb $
8 * $Date: 2010-08-24 15:26:25 +0000 (di, 24 aug 2010) $
9 */
10
11import dbnp.studycapturing.*
12import dbnp.data.Term
13import dbnp.data.Ontology
14
15class BootStrapStudies {
16
17        /**
18         * Add example studies. This function is meant to be called only in development mode
19         */
20
21        public static void addExampleStudies(dbnp.user.User owner) {
22
23                // Look up the used ontologies which should be in the database by now
24                def speciesOntology = Ontology.getOrCreateOntologyByNcboId(1132)
25                def brendaOntology = Ontology.getOrCreateOntologyByNcboId(1005)
26                def nciOntology = Ontology.getOrCreateOntologyByNcboId(1032)
27                def chebiOntology = Ontology.getOrCreateOntologyByNcboId(1007)
28
29                // Look up the used templates which should also be in the database by now
30                def studyTemplate = Template.findByName("Academic study")
31                def mouseTemplate = Template.findByName("Mouse")
32                def humanTemplate = Template.findByName("Human")
33                def dietTreatmentTemplate = Template.findByName("Diet treatment")
34                def boostTreatmentTemplate = Template.findByName("Compound challenge")
35                def liverSamplingEventTemplate = Template.findByName("Liver extraction")
36                def fastingTreatmentTemplate = Template.findByName("Fasting treatment")
37                def bloodSamplingEventTemplate = Template.findByName("Blood extraction")
38                def humanTissueSampleTemplate = Template.findByName("Human tissue sample")
39                def humanBloodSampleTemplate = Template.findByName("Human blood sample")
40               
41
42                // Add terms manually, to avoid having to do many HTTP requests to the BioPortal website
43                println ".adding terms"
44
45
46                def mouseTerm = new Term(
47                        name: 'Mus musculus',
48                        ontology: speciesOntology,
49                        accession: '10090'
50                ).with { if (!validate()) { errors.each { println it} } else save()}
51
52                def humanTerm = new Term(
53                        name: 'Homo sapiens',
54                        ontology: speciesOntology,
55                        accession: '9606'
56                ).with { if (!validate()) { errors.each { println it} } else save()}
57
58                def arabTerm = new Term(
59                        name: 'Arabidopsis thaliana',
60                        ontology: speciesOntology,
61                        accession: '3702'
62                ).with { if (!validate()) { errors.each { println it} } else save()}
63
64                def tomatoTerm = new Term(
65                        name: 'Solanum lycopersicum',
66                        ontology: speciesOntology,
67                        accession: '4081'
68                ).with { if (!validate()) { errors.each { println it} } else save()}
69
70                def potatoTerm = new Term(
71                        name: 'Solanum tuberosum',
72                        ontology: speciesOntology,
73                        accession: '0000'
74                ).with { if (!validate()) { errors.each { println it} } else save()}
75
76                def bloodTerm = new Term(
77                        name: 'blood plasma',
78                        ontology: brendaOntology,
79                        accession: 'BTO:0000131'
80                ).with { if (!validate()) { errors.each { println it} } else save()}
81
82                def c57bl6Term = new Term(
83                        name: 'C57BL/6 Mouse',
84                        ontology: nciOntology,
85                        accession: 'C14424'
86                ).with { if (!validate()) { errors.each { println it} } else save()}
87
88                def glucoseTerm = new Term(
89                        name: 'Glucose',
90                        ontology: chebiOntology,
91                        accession: 'CHEBI:17234'
92                ).with { if (!validate()) { errors.each { println it} } else save()}
93
94                // Create a few persons, roles and Affiliations
95                println ".adding persons, roles and affiliations"
96                def affiliation1 = new PersonAffiliation(
97                        institute: "Science Institute NYC",
98                        department: "Department of Mathematics"
99                ).save();
100                def affiliation2 = new PersonAffiliation(
101                        institute: "InfoStats GmbH, Hamburg",
102                        department: "Life Sciences"
103                ).save();
104                def role1 = new PersonRole(
105                        name: "Principal Investigator"
106                ).save();
107                def role2 = new PersonRole(
108                        name: "Statician"
109                ).save();
110
111                // Create persons
112                def person1 = new Person(
113                        lastName: "Scientist",
114                        firstName: "John",
115                        gender: "Male",
116                        initials: "J.R.",
117                        email: "john@scienceinstitute.com",
118                        phone: "1-555-3049",
119                        address: "First street 2,NYC"
120                )
121                .addToAffiliations( affiliation1 )
122                .addToAffiliations( affiliation2 )
123                .save();
124
125                def person2 = new Person(
126                        lastName: "Statician",
127                        firstName: "Jane",
128                        gender: "Female",
129                        initials: "W.J.",
130                        email: "jane@statisticalcompany.de",
131                        phone: "49-555-8291",
132                        address: "Dritten strasse 38, Hamburg, Germany"
133                )
134                .addToAffiliations( affiliation2 )
135                .save();
136
137                // Create 30 persons to test pagination
138                def personCounter = 1;
139                30.times { new Person( firstName: "Person #${personCounter}", lastName: "Testperson", email: "email${personCounter++}@testdomain.com" ).save() }
140
141                // Create a few publications
142                println ".adding publications"
143                def publication1 = new Publication(
144                        title: "Postnatal development of hypothalamic leptin receptors",
145                        authorsList: "Cottrell EC, Mercer JG, Ozanne SE.",
146                        pubMedID: "20472140",
147                        comments: "Not published yet",
148                        DOI: "unknown"
149                )
150                .save();
151
152                def publication2 = new Publication(
153                        title: "Induction of regulatory T cells decreases adipose inflammation and alleviates insulin resistance in ob/ob mice",
154                        authorsList: "Ilan Y, Maron R, Tukpah AM, Maioli TU, Murugaiyan G, Yang K, Wu HY, Weiner HL.",
155                        pubMedID: "20445103",
156                        comments: "",
157                        DOI: ""
158                )
159                .save();
160
161                // Add example mouse study
162                println ".adding NuGO PPS3 leptin example study..."
163                def mouseStudy = new Study(
164                        template: studyTemplate,
165                        title:"NuGO PPS3 mouse study leptin module",
166                        code:"PPS3_leptin_module",
167                        researchQuestion:"Leptin etc.",
168                        ecCode:"2007117.c",
169                        startDate: Date.parse('yyyy-MM-dd','2008-01-02'),
170                        owner: owner
171                ).with { if (!validate()) { errors.each { println it} } else save()}
172
173                mouseStudy.setFieldValue('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." )
174                mouseStudy.save()
175
176                def evLF = new Event(
177                        startTime: 3600,
178                        endTime: 3600 +7 * 24 * 3600,
179                        template: dietTreatmentTemplate
180                )
181                .setFieldValue( 'Diet','low fat')
182
183                def evHF = new Event(
184                        startTime: 3600,
185                        endTime: 3600 +7 * 24 * 3600,
186                        template: dietTreatmentTemplate
187                )
188                .setFieldValue( 'Diet','high fat' )
189
190                def evBV = new Event(
191                        startTime: 3600,
192                        endTime: 3600 +7 * 24 * 3600,
193                        template: boostTreatmentTemplate
194                )
195                .setFieldValue( 'Control','true' )
196
197                def evBL = new Event(
198                        startTime: 3600,
199                        endTime: 3600 +7 * 24 * 3600,
200                        template: boostTreatmentTemplate
201                )
202                .setFieldValue( 'Control','false' )
203
204                def evLF4 = new Event(
205                        startTime: 3600,
206                        endTime: 3600 + 4 * 7 * 24 * 3600,
207                        template: dietTreatmentTemplate
208                )
209                .setFieldValue( 'Diet','low fat')
210
211                def evHF4 = new Event(
212                        startTime: 3600,
213                        endTime: 3600 + 4 * 7 * 24 * 3600,
214                        template: dietTreatmentTemplate
215                )
216                .setFieldValue( 'Diet','high fat' )
217
218                def evBV4 = new Event(
219                        startTime: 3600,
220                        endTime: 3600 + 4 * 7 * 24 * 3600,
221                        template: boostTreatmentTemplate
222                )
223                .setFieldValue( 'Control','true' )
224
225                def evBL4 = new Event(
226                        startTime: 3600,
227                        endTime: 3600 + 4 * 7 * 24 * 3600,
228                        template: boostTreatmentTemplate
229                )
230                .setFieldValue( 'Control','false' )
231
232                def evS = new SamplingEvent(
233                        startTime: 3600 +7 * 24 * 3600,
234                        template: liverSamplingEventTemplate,
235                        sampleTemplate: humanTissueSampleTemplate)
236                .setFieldValue('Sample weight',5F)
237
238                def evS4 = new SamplingEvent(
239                        startTime: 3600 +7 * 24 * 3600,
240                        template: liverSamplingEventTemplate,
241                        sampleTemplate: humanTissueSampleTemplate)
242                .setFieldValue('Sample weight',5F)
243
244                // Add events to study
245                mouseStudy
246                .addToEvents(evLF)
247                .addToEvents(evHF)
248                .addToEvents(evBV)
249                .addToEvents(evBL)
250                .addToEvents(evLF4)
251                .addToEvents(evHF4)
252                .addToEvents(evBV4)
253                .addToEvents(evBL4)
254                .addToSamplingEvents(evS)
255                .addToSamplingEvents(evS4)
256                .with { if (!validate()) { errors.each { println it} } else save()}
257
258                // Extra check if the SamplingEvents are saved correctly
259                evS.with { if (!validate()) { errors.each { println it} } else save()}
260                evS4.with { if (!validate()) { errors.each { println it} } else save()}
261
262                def LFBV1 = new EventGroup(name:"10% fat + vehicle for 1 week")
263                .addToEvents(evLF)
264                .addToEvents(evBV)
265                .addToSamplingEvents(evS)
266
267                def LFBL1 = new EventGroup(name:"10% fat + leptin for 1 week")
268                .addToEvents(evLF)
269                .addToEvents(evBL)
270                .addToSamplingEvents(evS)
271
272                def HFBV1 = new EventGroup(name:"45% fat + vehicle for 1 week")
273                .addToEvents(evHF)
274                .addToEvents(evBV)
275                .addToSamplingEvents(evS)
276
277                def HFBL1 = new EventGroup(name:"45% fat + leptin for 1 week")
278                .addToEvents(evHF)
279                .addToEvents(evBL)
280                .addToSamplingEvents(evS)
281
282                def LFBV4 = new EventGroup(name:"10% fat + vehicle for 4 weeks")
283                .addToEvents(evLF4)
284                .addToEvents(evBV4)
285                .addToSamplingEvents(evS4)
286
287                def LFBL4 = new EventGroup(name:"10% fat + leptin for 4 weeks")
288                .addToEvents(evLF4)
289                .addToEvents(evBL4)
290                .addToSamplingEvents(evS4)
291
292                def HFBV4 = new EventGroup(name:"45% fat + vehicle for 4 weeks")
293                .addToEvents(evHF4)
294                .addToEvents(evBV4)
295                .addToSamplingEvents(evS4)
296
297                def HFBL4 = new EventGroup(name:"45% fat + leptin for 4 weeks")
298                .addToEvents(evHF4)
299                .addToEvents(evBL4)
300                .addToSamplingEvents(evS4)
301               
302        // Add subjects and samples and compose EventGroups
303                def x=1
304                80.times {
305                        def currentSubject = new Subject(
306                                name: "A" + x++,
307                                species: mouseTerm,
308                                template: mouseTemplate,
309                        )
310                        .setFieldValue("Gender", "Male")
311                        .setFieldValue("Genotype", c57bl6Term)
312                        .setFieldValue("Age", 17)
313                        .setFieldValue("Cage", "" + (int)(x/2))
314
315                        // We have to save the subject first, otherwise the parentEvent property of the sample cannot be set
316                        // (this is possibly a Grails or Hibernate bug)
317                        mouseStudy.addToSubjects(currentSubject)
318                        currentSubject.with { if (!validate()) { errors.each { println it} } else save()}
319
320                        // Add subject to appropriate EventGroup
321                        if (x > 70) { HFBL4.addToSubjects(currentSubject).save() }
322                        else if (x > 60) { HFBV4.addToSubjects(currentSubject).save() }
323                        else if (x > 50) { LFBL4.addToSubjects(currentSubject).save() }
324                        else if (x > 40) { LFBV4.addToSubjects(currentSubject).save() }
325                        else if (x > 30) { HFBL1.addToSubjects(currentSubject).save() }
326                        else if (x > 20) { HFBV1.addToSubjects(currentSubject).save() }
327                        else if (x > 10) { LFBL1.addToSubjects(currentSubject).save() }
328                        else             { LFBV1.addToSubjects(currentSubject).save() }
329
330                        // Create sample
331                        def currentSample = new Sample(
332                                name: currentSubject.name + '_B',
333                                material: bloodTerm,
334                                template: humanBloodSampleTemplate,
335                                parentSubject: currentSubject,
336                                parentEvent: evS //x > 40 ? evS4 : evS
337                        );
338                        mouseStudy.addToSamples(currentSample)
339                        currentSample.with { if (!validate()) { errors.each { println it} } else save()}
340                        currentSample.setFieldValue( "Text on vial", "T" + (Math.random() * 100L) )
341                }
342
343                // Add EventGroups to study
344                mouseStudy
345                .addToEventGroups(LFBV1)
346                .addToEventGroups(LFBL1)
347                .addToEventGroups(HFBV1)
348                .addToEventGroups(HFBL1)
349                .addToEventGroups(LFBV4)
350                .addToEventGroups(LFBL4)
351                .addToEventGroups(HFBV4)
352                .addToEventGroups(HFBL4)
353                .with { if (!validate()) { errors.each { println it} } else save()}
354
355                // Add persons and publications to study
356                def studyperson1 = new StudyPerson( person: person1, role: role1 )
357                def studyperson2 = new StudyPerson( person: person2, role: role2 )
358
359                mouseStudy
360                .addToPersons( studyperson1 )
361                .addToPersons( studyperson2 )
362        .addToPublications( publication1 )
363        .addToPublications( publication2 )
364                .with { if (!validate()) { errors.each { println it} } else save()}
365
366                // Add example human study
367                println ".adding NuGO PPSH example study..."
368
369                def humanStudy = new Study(
370                        template: studyTemplate,
371                        title:"NuGO PPS human study",
372                        code:"PPSH",
373                        researchQuestion:"How much are fasting plasma and urine metabolite levels affected by prolonged fasting ?",
374                        description:"Human study",
375                        ecCode:"unknown",
376                        startDate: Date.parse('yyyy-MM-dd','2008-01-14'),
377                        owner: owner
378                )
379                .setFieldValue( 'Description', "Human study performed at RRI; centres involved: RRI, IFR, TUM, Maastricht U." )
380                .with { if (!validate()) { errors.each { println it} } else save()}
381
382                def rootGroup = new EventGroup(name: 'Root group');
383
384                def fastingEvent = new Event(
385                        startTime: 3 * 24 * 3600 + 22 * 3600,
386                        endTime: 3 * 24 * 3600 + 30 * 3600,
387                        template: fastingTreatmentTemplate)
388                .setFieldValue('Fasting period','8h');
389
390                def bloodSamplingEventBefore = new SamplingEvent(
391                        startTime: 0,
392                        template: bloodSamplingEventTemplate,
393                        sampleTemplate: humanBloodSampleTemplate)
394                .setFieldValue('Sample volume',4.5F);
395
396                def bloodSamplingEventAfter = new SamplingEvent(
397                        startTime: 3 * 24 * 3600 + 30 * 3600,
398                        template: bloodSamplingEventTemplate,
399                        sampleTemplate: humanBloodSampleTemplate)
400                .setFieldValue('Sample volume',4.5F);
401
402                rootGroup.addToEvents fastingEvent
403                rootGroup.addToSamplingEvents bloodSamplingEventBefore
404                rootGroup.addToSamplingEvents bloodSamplingEventAfter
405                rootGroup.save()
406
407                def y = 1
408                11.times {
409                        def currentSubject = new Subject(
410                                name: "" + y++,
411                                species: humanTerm,
412                                template: humanTemplate
413                        )
414                        .setFieldValue("Gender", (Math.random() > 0.5) ? "Male" : "Female")
415                        .setFieldValue("DOB", new java.text.SimpleDateFormat("dd-mm-yy").parse("01-02-19" + (10 + (int) (Math.random() * 80))))
416                        .setFieldValue("Age", 30)
417                        .setFieldValue("Height", Math.random() * 2F)
418                        .setFieldValue("Weight", Math.random() * 150F)
419                        .setFieldValue("BMI", 20 + Math.random() * 10F)
420
421                        humanStudy.addToSubjects(currentSubject)
422                        currentSubject.with { if (!validate()) { errors.each { println it} } else save()}
423
424                        rootGroup.addToSubjects currentSubject
425                        rootGroup.save()
426
427                        def currentSample = new Sample(
428                                name: currentSubject.name + '_B',
429                                material: bloodTerm,
430                                template: humanBloodSampleTemplate,
431                                parentSubject: currentSubject,
432                                parentEvent: bloodSamplingEventBefore
433                        );
434
435                        humanStudy.addToSamples(currentSample)
436                        currentSample.with { if (!validate()) { errors.each { println it} } else save()}
437                        currentSample.setFieldValue( "Text on vial", "T" + (Math.random() * 100L) )
438
439                        currentSample = new Sample(
440                                name: currentSubject.name + '_A',
441                                material: bloodTerm,
442                                template: humanBloodSampleTemplate,
443                                parentSubject: currentSubject,
444                                parentEvent: bloodSamplingEventAfter
445                        );
446
447                        humanStudy.addToSamples(currentSample)
448                        currentSample.with { if (!validate()) { errors.each { println it} } else save()}
449                        currentSample.setFieldValue( "Text on vial", "T" + (Math.random() * 100L) )
450                }
451
452                humanStudy.addToEvents(fastingEvent)
453                humanStudy.addToSamplingEvents(bloodSamplingEventBefore)
454                humanStudy.addToSamplingEvents(bloodSamplingEventAfter)
455                humanStudy.addToEventGroups rootGroup
456
457                println ".adding persons and saving PPSH study..."
458                // Add persons to study
459                def studyperson3 = new StudyPerson( person: person1, role: role2 )
460                humanStudy
461                .addToPersons( studyperson3 )
462                .addToPublications( publication2 )
463                .with { if (!validate()) { errors.each { println it} } else save()}
464
465                println ".adding assay references to mouse example study..."
466
467                // Add SAM assay reference
468                def clinicalModule = new AssayModule(
469                        name: 'SAM module for clinical data',
470                        platform: 'clinical measurements',
471                        url: 'http://localhost:8182/sam'
472                ).with { if (!validate()) { errors.each { println it} } else save()}
473
474                // Add metabolomics assay reference
475                def metabolomicsModule = new AssayModule(
476                        name: 'Metabolomics module',
477                        platform: 'GCMS/LCMS',
478                        url: 'http://localhost:8080/nmcdsp'
479                ).with { if (!validate()) { errors.each { println it} } else save()}
480
481                def lipidAssayRef = new Assay(
482                        name: 'Lipid profiling',
483                        module: clinicalModule,
484                        externalAssayID: 'PPS3_SAM'
485                )
486
487                def metAssayRef = new Assay(
488                        name: 'Lipidomics profile',
489                        module: metabolomicsModule,
490                        externalAssayID: 'PPS3_Lipidomics'
491                )
492
493                mouseStudy.samples*.each {
494                        lipidAssayRef.addToSamples(it)
495                        metAssayRef.addToSamples(it)
496                }
497
498                mouseStudy.addToAssays(lipidAssayRef);
499                mouseStudy.addToAssays(metAssayRef);
500                mouseStudy.save(flush:true)
501
502                println ".adding assay references to human example study..."
503
504                def  glucoseAssayBRef = new Assay(
505                        name: 'Glucose assay before',
506                        module: clinicalModule,
507                        externalAssayID: 'PPSH-Glu-B'
508                )
509
510                def  glucoseAssayARef = new Assay(
511                        name: 'Glucose assay after',
512                        module: clinicalModule,
513                        externalAssayID: 'PPSH-Glu-A'
514                )
515
516                def metAssayRefB = new Assay(
517                        name: 'Lipidomics profile before',
518                        module: metabolomicsModule,
519                        externalAssayID: 'PPSH_Lipidomics_start'
520                )
521
522                def metAssayRefA = new Assay(
523                        name: 'Lipidomics profile after',
524                        module: metabolomicsModule,
525                        externalAssayID: 'PPSH_Lipidomics_end'
526                )
527                humanStudy.samples*.each {
528                        if (it.parentEvent.startTime == 0) {
529                                glucoseAssayBRef.addToSamples(it)
530                                metAssayRefB.addToSamples(it)
531                        }
532                        else {
533                                glucoseAssayARef.addToSamples(it)
534                                metAssayRefA.addToSamples(it)
535                        }
536                }
537
538
539                humanStudy.addToAssays(glucoseAssayARef)
540                humanStudy.addToAssays(glucoseAssayBRef)
541                humanStudy.addToAssays(metAssayRefA)
542                humanStudy.addToAssays(metAssayRefB)
543                humanStudy.save(flush:true)
544
545        }
546
547}
Note: See TracBrowser for help on using the repository browser.