Search in sources :

Example 16 with OntologyTerm

use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.

the class GeneOntologyServiceImpl method findTerm.

@Override
public Collection<OntologyTerm> findTerm(String queryString) {
    if (!this.isReady())
        return new HashSet<>();
    if (GeneOntologyServiceImpl.log.isDebugEnabled())
        GeneOntologyServiceImpl.log.debug("Searching Gene Ontology for '" + queryString + "'");
    // make sure we are all-inclusive
    queryString = queryString.trim();
    queryString = queryString.replaceAll("\\s+", " AND ");
    StopWatch timer = new StopWatch();
    timer.start();
    Collection<OntologyResource> rawMatches = new HashSet<>();
    for (SearchIndex index : this.indices) {
        rawMatches.addAll(OntologySearch.matchIndividuals(model, index, queryString));
    }
    if (timer.getTime() > 100) {
        GeneOntologyServiceImpl.log.info("Find " + rawMatches.size() + " raw go terms from " + queryString + ": " + timer.getTime() + " ms");
    }
    timer.reset();
    timer.start();
    /*
         * Required to make sure the descriptions are filled in.
         */
    Collection<OntologyTerm> matches = new HashSet<>();
    for (OntologyResource r : rawMatches) {
        if (StringUtils.isBlank(r.getUri()))
            continue;
        OntologyTerm termForURI = GeneOntologyServiceImpl.getTermForURI(r.getUri());
        if (termForURI == null) {
            GeneOntologyServiceImpl.log.warn("No term for : " + r);
            continue;
        }
        matches.add(termForURI);
    }
    if (timer.getTime() > 100) {
        GeneOntologyServiceImpl.log.info("Convert " + rawMatches.size() + " raw go terms to terms: " + timer.getTime() + " ms");
    }
    return matches;
}
Also used : SearchIndex(ubic.basecode.ontology.search.SearchIndex) OntologyTerm(ubic.basecode.ontology.model.OntologyTerm) OntologyResource(ubic.basecode.ontology.model.OntologyResource) StopWatch(org.apache.commons.lang3.time.StopWatch)

Example 17 with OntologyTerm

use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.

the class GeneOntologyServiceImpl method putOverlapGenes.

private void putOverlapGenes(Map<Long, Collection<OntologyTerm>> overlap, Collection<OntologyTerm> queryGeneTerms, Collection<Gene> genes) {
    for (Object obj : genes) {
        Gene gene = (Gene) obj;
        if (queryGeneTerms.isEmpty()) {
            overlap.put(gene.getId(), new HashSet<OntologyTerm>());
            continue;
        }
        Collection<OntologyTerm> comparisonOntos = this.getGOTerms(gene);
        if (comparisonOntos == null || comparisonOntos.isEmpty()) {
            overlap.put(gene.getId(), new HashSet<OntologyTerm>());
            continue;
        }
        overlap.put(gene.getId(), this.computeOverlap(queryGeneTerms, comparisonOntos));
    }
}
Also used : Gene(ubic.gemma.model.genome.Gene) GeneOntologyTermValueObject(ubic.gemma.model.genome.GeneOntologyTermValueObject) OntologyTerm(ubic.basecode.ontology.model.OntologyTerm)

Example 18 with OntologyTerm

use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.

the class GeneOntologyServiceTest2 method testAllParents.

@Test
public final void testAllParents() {
    // regulation of erythrocyte aggregation
    String id = "GO:0034118";
    OntologyTerm termForId = GeneOntologyServiceImpl.getTermForId(id);
    assertNotNull(termForId);
    Collection<OntologyTerm> terms = GeneOntologyServiceTest2.gos.getAllParents(termForId);
    // excludes "regulates" relations, excludes root.
    /*
         * regulation of homotypic cell-cell adhesion
         *
         * regulation of cell-cell adhesion
         *
         * regulation of cell adhesion
         *
         * regulation of cellular process
         *
         * regulation of biological process
         *
         * biological regulation
         *
         * (biological process)
         */
    assertEquals(6, terms.size());
}
Also used : OntologyTerm(ubic.basecode.ontology.model.OntologyTerm) Test(org.junit.Test)

Example 19 with OntologyTerm

use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.

the class OntologyServiceTest method test.

@Test
public void test() {
    os.getDiseaseOntologyService().loadTermsInNameSpace(this.getClass().getResourceAsStream("/data/loader/ontology/dotest.owl.xml"));
    Collection<CharacteristicValueObject> name = os.findTermsInexact("diarrhea", null);
    assertTrue(name.size() > 0);
    OntologyTerm t1 = os.getTerm("http://purl.obolibrary.org/obo/DOID_0050001");
    assertNotNull(t1);
    // Actinomadura madurae infectious disease
    assertTrue(os.isObsolete("http://purl.obolibrary.org/obo/DOID_0050001"));
    // inflammatory diarrhea, not obsolete as of May 2012.
    assertNotNull(os.getTerm("http://purl.obolibrary.org/obo/DOID_0050132"));
    assertTrue(!os.isObsolete("http://purl.obolibrary.org/obo/DOID_0050132"));
}
Also used : CharacteristicValueObject(ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject) OntologyTerm(ubic.basecode.ontology.model.OntologyTerm) BaseSpringContextTest(ubic.gemma.core.testing.BaseSpringContextTest) Test(org.junit.Test)

Example 20 with OntologyTerm

use of ubic.basecode.ontology.model.OntologyTerm in project Gemma by PavlidisLab.

the class GeneOntologyServiceTest method testGetParentsPartOf.

@Test
public final void testGetParentsPartOf() {
    String id = "GO:0000332";
    OntologyTerm termForId = GeneOntologyServiceTest.gos.getTermForId(id);
    assertNotNull(termForId);
    Collection<OntologyTerm> terms = GeneOntologyServiceTest.gos.getAllParents(termForId, true);
    for (OntologyTerm term : terms) {
        GeneOntologyServiceTest.log.info(term);
    }
    // is a subclass and partof.
    assertEquals(12, terms.size());
}
Also used : OntologyTerm(ubic.basecode.ontology.model.OntologyTerm) Test(org.junit.Test)

Aggregations

OntologyTerm (ubic.basecode.ontology.model.OntologyTerm)73 Test (org.junit.Test)13 VocabCharacteristic (ubic.gemma.model.common.description.VocabCharacteristic)13 Gene (ubic.gemma.model.genome.Gene)11 OntologyResource (ubic.basecode.ontology.model.OntologyResource)8 HashSet (java.util.HashSet)6 StopWatch (org.apache.commons.lang3.time.StopWatch)6 CharacteristicValueObject (ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject)6 BufferedReader (java.io.BufferedReader)3 ConcurrentHashSet (org.compass.core.util.concurrent.ConcurrentHashSet)3 Element (org.w3c.dom.Element)3 OntologyIndividual (ubic.basecode.ontology.model.OntologyIndividual)3 EntityNotFoundException (ubic.gemma.core.association.phenotype.PhenotypeExceptions.EntityNotFoundException)3 Characteristic (ubic.gemma.model.common.description.Characteristic)3 GeneEvidenceValueObject (ubic.gemma.model.genome.gene.phenotype.valueObject.GeneEvidenceValueObject)3 Resource (com.hp.hpl.jena.rdf.model.Resource)2 FileReader (java.io.FileReader)2 SocketException (java.net.SocketException)2 Collection (java.util.Collection)2 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)2