Changeset 552


Ignore:
Timestamp:
Jun 10, 2010, 1:36:02 AM (13 years ago)
Author:
keesvb
Message:

added BioPortal? Ontology add function via Ontocat, added test for that

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/domain/dbnp/data/Ontology.groovy

    r496 r552  
    4040                }*/
    4141        }
     42
     43        static Ontology getBioPortalOntology(String ncboId) {
     44                // Get ontology from BioPortal via Ontocat
     45                // TODO: maybe make a static OntologyService instance to be more efficient, and decorate it with caching?
     46                uk.ac.ebi.ontocat.OntologyService os = new uk.ac.ebi.ontocat.bioportal.BioportalOntologyService()
     47                uk.ac.ebi.ontocat.Ontology o = os.getOntology(ncboId)
     48
     49                // Instantiate and return Ontology object
     50                new dbnp.data.Ontology(
     51                        name: o.label,
     52                        description: o.description,
     53                        url: o.properties['homepage'] ?: "http://bioportal.bioontology.org/ontologies/${o.id}",
     54                        versionNumber: o.versionNumber,
     55                        ncboId: o.ontologyAccession,
     56                        ncboVersionedId: o.id
     57                );
     58        }
    4259}
  • trunk/test/integration/gscf/OntologyTests.groovy

    r496 r552  
    103103        /**
    104104         * Ontocat test for debug purposes: show all properties of a certain ontology
     105        * Make this method private in order to run it
    105106         */
    106107        private void testOntocatBioPortalDebug() {
     
    111112                uk.ac.ebi.ontocat.Ontology o = os.getOntology("1005")
    112113                StringBuilder sb = new StringBuilder();
     114                // This is of course a very scary way to getting more information on 'o', but it seems to be the only way to reach codingScheme
    113115                def bean = os.getOntologyBean()
    114116                String codingScheme = bean.codingScheme
     
    120122                }
    121123                sb.append "Bean:\t" + bean.dump()
     124                sb.append("Coding scheme: ")
    122125                sb.append(bean.properties['codingScheme'])
    123126                sb.append("\t");
     
    167170
    168171                // Iterate over all ontologies in OLS
    169                 os.getOntologies().each {
    170 
    171                         // Get bean and extract versionedId
    172                         def bean = os.ontologyBean
    173                         def matcher = bean.codingScheme =~ "/(\\d{5})/"
    174                         assert matcher
    175                         assert matcher.size() == 1
    176                         assert matcher[0].size() == 2
    177                         def versionedId = matcher[0][1]
     172                os.getOntologies().each { o ->
    178173
    179174                        // Instantiate ontology
     
    181176                            name: o.label,
    182177                            description: o.description,
    183                             url: bean.properties['homepage'],
     178                            url: o.properties['homepage'],
    184179                            //url: 'http://bioportal.bioontology.org/ontologies/' + versionedId,
    185180                            versionNumber: o.versionNumber,
    186181                            ncboId: o.ontologyAccession,
    187                             ncboVersionedId: versionedId
     182                            ncboVersionedId: o.id
    188183                        );
    189184
     
    194189                        //println ontology.dump()
    195190                }
     191
     192        }
     193
     194        public void testAddBioPortalOntology() {
     195                def ontology = dbnp.data.Ontology.getBioPortalOntology("1005")                 
     196                // Validate and save ontology
     197                if (!ontology.validate()) { ontology.errors.each { println it} }
     198                assert ontology.validate()
     199                assert ontology.save(flush: true)
     200                assert Ontology.findByNcboId(1005).name.equals(ontology.name)
    196201        }
    197202}
Note: See TracChangeset for help on using the changeset viewer.