Changeset 662


Ignore:
Timestamp:
Jul 19, 2010, 4:28:10 PM (6 years ago)
Author:
keesvb
Message:

restructured BootStrap?, it should now run faster because there are no BioPortal? connections, and it adds sample studies in development mode (outcomment the addExampleStudies call in the BootStrap? if you don't want that). Renamed TemplateEntity?.getFieldType to giveFieldType and added tests to SampleTests? for the method.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/conf/BootStrap.groovy

    r639 r662  
    2222                System.setProperty('user.timezone', 'CET')
    2323
     24                // If there are no templates yet in the database
    2425                if (Template.count() == 0) {
    2526                        println "No templates in the current database.";
     27
     28                        // If in development or test mode, add the ontologies manually to the database
     29                        // without contacting the BioPortal website, to avoid annoying hiccups when the server is busy
     30                        if (grails.util.GrailsUtil.environment != GrailsApplication.ENV_PRODUCTION) {
     31                                println "Adding ontology descriptors"
     32                                BootStrapTemplates.initTemplateOntologies()
     33                        }
     34
    2635                        // Add example study, subject, event etc. templates
    2736                        BootStrapTemplates.initTemplates()
    2837
    29                         // Add example studies
     38                        // If in development mode and no studies are present, add example studies
    3039                        if (Study.count() == 0 && grails.util.GrailsUtil.environment == GrailsApplication.ENV_DEVELOPMENT) {
    31 
    32                                 // When the code is properly refactored, BootStrapStudies.addExampleStudies() may be called here
     40                                BootStrapStudies.addExampleStudies()
    3341                        }
    3442                }
     
    4553                // register methods for accessing SAM's Rest services
    4654                CommunicationManager.SAMServerURL = 'nbx5.nugo.org/sam'
    47         CommunicationManager.registerRestWrapperMethodsSAMtoGSCF()
     55                CommunicationManager.registerRestWrapperMethodsSAMtoGSCF()
    4856        }
    4957
  • trunk/grails-app/conf/BootStrapStudies.groovy

    r626 r662  
    1010
    1111import dbnp.studycapturing.*
     12import dbnp.data.Term
     13import dbnp.data.Ontology
    1214
    1315class BootStrapStudies {
    1416
     17        /**
     18         * Add example studies. This function is meant to be called only in development mode
     19         */
     20
    1521        public static void addExampleStudies() {
    1622
    17                 // TODO: Strip this code from all references to template and term objects
    18                 // which now are not there anymore because this code was separated from the template bootstrapping
    19                 // and because terms should be dynamically added
    20 
    21                 /*
     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 humanBloodSampleTemplate = Template.findByName("Human blood sample")
     39               
     40
     41                // Add terms manually, to avoid having to do many HTTP requests to the BioPortal website
     42                println ".adding terms"
     43
     44
     45                def mouseTerm = new Term(
     46                        name: 'Mus musculus',
     47                        ontology: speciesOntology,
     48                        accession: '10090'
     49                ).with { if (!validate()) { errors.each { println it} } else save()}
     50
     51                def humanTerm = new Term(
     52                        name: 'Homo sapiens',
     53                        ontology: speciesOntology,
     54                        accession: '9606'
     55                ).with { if (!validate()) { errors.each { println it} } else save()}
     56
     57                def arabTerm = new Term(
     58                        name: 'Arabidopsis thaliana',
     59                        ontology: speciesOntology,
     60                        accession: '3702'
     61                ).with { if (!validate()) { errors.each { println it} } else save()}
     62
     63                def tomatoTerm = new Term(
     64                        name: 'Solanum lycopersicum',
     65                        ontology: speciesOntology,
     66                        accession: '4081'
     67                ).with { if (!validate()) { errors.each { println it} } else save()}
     68
     69                def potatoTerm = new Term(
     70                        name: 'Solanum tuberosum',
     71                        ontology: speciesOntology,
     72                        accession: '0000'
     73                ).with { if (!validate()) { errors.each { println it} } else save()}
     74
     75                def bloodTerm = new Term(
     76                        name: 'blood plasma',
     77                        ontology: brendaOntology,
     78                        accession: 'BTO:0000131'
     79                ).with { if (!validate()) { errors.each { println it} } else save()}
     80
     81                def c57bl6Term = new Term(
     82                        name: 'C57BL/6 Mouse',
     83                        ontology: nciOntology,
     84                        accession: 'C14424'
     85                ).with { if (!validate()) { errors.each { println it} } else save()}
     86
     87                def glucoseTerm = new Term(
     88                        name: 'Glucose',
     89                        ontology: chebiOntology,
     90                        accession: 'CHEBI:17234'
     91                ).with { if (!validate()) { errors.each { println it} } else save()}
     92
    2293                // Create a few persons, roles and Affiliations
    2394                println ".adding persons, roles and affiliations"
     
    313384                        startTime: 3 * 24 * 3600 + 22 * 3600,
    314385                        endTime: 3 * 24 * 3600 + 30 * 3600,
    315                         template: fastingTreatment)
     386                        template: fastingTreatmentTemplate)
    316387                .setFieldValue('Fasting period','8h');
    317388
     
    421492
    422493                def clinicalModule = new AssayModule(
    423                         name: 'Clinical data',
    424                         type: AssayType.CLINICAL_DATA,
     494                        name: 'SAM module for clinical data',
     495                        type: AssayType.SIMPLE_ASSAY,
    425496                        platform: 'clinical measurements',
    426                         url: 'http://localhost:8080/gscf'
     497                        url: 'http://sam.dbnp.org'
    427498                ).with { if (!validate()) { errors.each { println it} } else save()}
    428499
     
    441512                humanStudy.save()
    442513
    443                mouseStudy.addToAssays(lipidAssayRef);
     514                mouseStudy.addToAssays(lipidAssayRef);
    444515                mouseStudy.save()
    445                 */
    446516        }
    447517
  • trunk/grails-app/conf/BootStrapTemplates.groovy

    r626 r662  
    1414class BootStrapTemplates {
    1515
     16        /**
     17         * Add the ontologies that are necessary for the templates below manually
     18         * This function can be called to avoid the HTTP requests to BioPortal each time
     19         * (e.g. in development or automated test environments)
     20         */
     21        public static void initTemplateOntologies() {
     22
     23                // add Subject>species ontology
     24                println ".adding NCBI species ontology"
     25                def speciesOntology = new Ontology(
     26                        name: 'NCBI organismal classification',
     27                        description: 'A taxonomic classification of living organisms and associated artifacts for their controlled description within the context of databases.',
     28                        url: 'http://www.ncbi.nlm.nih.gov/Taxonomy/taxonomyhome.html/',
     29                        versionNumber: '1.2',
     30                        ncboId: '1132',
     31                        ncboVersionedId: '38802'
     32                ).with { if (!validate()) { errors.each { println it} } else save()}
     33
     34                // add Sample>material ontology
     35                println ".adding BRENDA source material ontology"
     36                def brendaOntology = new Ontology(
     37                        name: 'BRENDA tissue / enzyme source',
     38                        description: 'A structured controlled vocabulary for the source of an enzyme. It comprises terms for tissues, cell lines, cell types and cell cultures from uni- and multicellular organisms.',
     39                        url: 'http://www.brenda-enzymes.info',
     40                        versionNumber: '1.3',
     41                        ncboId: '1005',
     42                        ncboVersionedId: '40643'
     43                ).with { if (!validate()) { errors.each { println it} } else save()}
     44
     45                // add NCI ontology which is used in Mouse genotype template field
     46                def nciOntology = new Ontology(
     47                        name: 'NCI Thesaurus',
     48                        description: 'A vocabulary for clinical care, translational and basic research, and public information and administrative activities.',
     49                        url: 'http://ncicb.nci.nih.gov/core/EVS',
     50                        versionNumber: '10.01',
     51                        ncboId: '1032',
     52                        ncboVersionedId: '42693'
     53                ).with { if (!validate()) { errors.each { println it} } else save()}
     54
     55                // add CHEBI ontology which is used in Mouse genotype template field
     56                def chebiOntology = new Ontology(
     57                        name: 'Chemical entities of biological interest',
     58                        description: 'A structured classification of chemical compounds of biological relevance.',
     59                        url: 'http://www.ebi.ac.uk/chebi',
     60                        versionNumber: '1.68',
     61                        ncboId: '1007',
     62                        ncboVersionedId: '42878'
     63                ).with { if (!validate()) { errors.each { println it} } else save()}
     64               
     65        }
     66
     67        /**
     68         * Add example templates, this function would normally be called on an empty database
     69         */
    1670        public static void initTemplates() {
    1771
  • trunk/grails-app/domain/dbnp/studycapturing/TemplateEntity.groovy

    r661 r662  
    623623
    624624        /**
     625         * Look up the type of a certain template field
     626         * @param String fieldName The name of the template field
     627         * @return String The type (static member of TemplateFieldType) of the field, or null of the field does not exist
     628         */
     629        TemplateFieldType giveFieldType(String fieldName) {
     630                def field = giveFields().find {
     631                        it.name == fieldName
     632                }
     633                field?.type
     634        }
     635
     636        /**
    625637         * Return all relevant 'built-in' domain fields of the super class. Should be implemented by a static method
    626638         * @return List with DomainTemplateFields
     
    659671        }
    660672
    661                     /**
    662          * Look up the type of a certain template subject field
    663          * @param String fieldName The name of the template field
    664          * @return String       The type (static member of TemplateFieldType) of the field, or null of the field does not exist
    665          */
    666         def TemplateFieldType getFieldType(String fieldName) {
    667                 def field = this.giveFields().find {
    668                         it.name == fieldName
    669                 }
    670                 field?.type
    671         }
    672673}
  • trunk/test/integration/gscf/SampleTests.groovy

    r654 r662  
    66import dbnp.studycapturing.SamplingEvent
    77import dbnp.studycapturing.Sample
     8import dbnp.studycapturing.TemplateFieldType
    89
    910/**
     
    177178                assert sample.isDomainField('material')
    178179
     180                // Make sure that they have the right type
     181                assert sample.giveFieldType('name') == TemplateFieldType.STRING
     182                assert sample.giveFieldType('material') == TemplateFieldType.ONTOLOGYTERM
     183
    179184        }
    180185
Note: See TracChangeset for help on using the changeset viewer.