Search in sources :

Example 61 with OntologyTerm

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

the class GeneOntologyServiceImpl method getGOTerms.

@Override
public Collection<OntologyTerm> getGOTerms(Gene gene, boolean includePartOf, GOAspect goAspect) {
    Collection<OntologyTerm> cachedTerms = goTerms.get(gene);
    if (GeneOntologyServiceImpl.log.isTraceEnabled() && cachedTerms != null) {
        this.logIds("found cached GO terms for " + gene.getOfficialSymbol(), goTerms.get(gene));
    }
    if (cachedTerms == null) {
        Collection<OntologyTerm> allGOTermSet = new HashSet<>();
        Collection<VocabCharacteristic> annotations = gene2GOAssociationService.findByGene(gene);
        for (VocabCharacteristic c : annotations) {
            if (!GeneOntologyServiceImpl.uri2Term.containsKey(c.getValueUri())) {
                GeneOntologyServiceImpl.log.warn("Term " + c.getValueUri() + " not found in term list cant add to results");
                continue;
            }
            allGOTermSet.add(GeneOntologyServiceImpl.uri2Term.get(c.getValueUri()));
        }
        allGOTermSet.addAll(this.getAllParents(allGOTermSet, includePartOf));
        cachedTerms = Collections.unmodifiableCollection(allGOTermSet);
        if (GeneOntologyServiceImpl.log.isTraceEnabled())
            this.logIds("caching GO terms for " + gene.getOfficialSymbol(), allGOTermSet);
        goTerms.put(gene, cachedTerms);
    }
    if (goAspect != null) {
        Collection<OntologyTerm> finalTerms = new HashSet<>();
        for (OntologyTerm ontologyTerm : cachedTerms) {
            GOAspect term = this.getTermAspect(ontologyTerm);
            if (term != null && term.equals(goAspect)) {
                finalTerms.add(ontologyTerm);
            }
        }
        return finalTerms;
    }
    return cachedTerms;
}
Also used : VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic) OntologyTerm(ubic.basecode.ontology.model.OntologyTerm)

Example 62 with OntologyTerm

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

the class GeneOntologyServiceImpl method getDescendants.

/**
 * @return Given an ontology term recursively determines all the children and adds them to a cache (same as
 * getAllParents but the recursive code is a little cleaner and doesn't use and accumulator)
 */
private synchronized Collection<OntologyTerm> getDescendants(OntologyTerm entry, boolean includePartOf) {
    Collection<OntologyTerm> descendants = childrenCache.get(entry.getUri());
    if (descendants == null) {
        descendants = new HashSet<>();
        Collection<OntologyTerm> children = this.getChildren(entry, includePartOf);
        if (children != null) {
            for (OntologyTerm child : children) {
                descendants.add(child);
                descendants.addAll(this.getDescendants(child, includePartOf));
            }
        }
        descendants = Collections.unmodifiableCollection(descendants);
        childrenCache.put(entry.getUri(), descendants);
    }
    return new HashSet<>(descendants);
}
Also used : OntologyTerm(ubic.basecode.ontology.model.OntologyTerm)

Example 63 with OntologyTerm

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

the class GeneOntologyServiceImpl method getTermDefinition.

@Override
public String getTermDefinition(String goId) {
    OntologyTerm t = GeneOntologyServiceImpl.getTermForId(goId);
    assert t != null;
    Collection<AnnotationProperty> annotations = t.getAnnotations();
    for (AnnotationProperty annot : annotations) {
        GeneOntologyServiceImpl.log.info(annot.getProperty());
        if (annot.getProperty().equals("hasDefinition")) {
            return annot.getContents();
        }
    }
    return null;
}
Also used : AnnotationProperty(ubic.basecode.ontology.model.AnnotationProperty) OntologyTerm(ubic.basecode.ontology.model.OntologyTerm)

Example 64 with OntologyTerm

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

the class GeneOntologyServiceImpl method getGenes.

@Override
public Collection<Gene> getGenes(String goId, Taxon taxon) {
    OntologyTerm t = GeneOntologyServiceImpl.getTermForId(goId);
    if (t == null)
        return null;
    Collection<OntologyTerm> terms = this.getAllChildren(t);
    Collection<Gene> results = new HashSet<>(this.gene2GOAssociationService.findByGOTerm(goId, taxon));
    for (OntologyTerm term : terms) {
        results.addAll(this.gene2GOAssociationService.findByGOTerm(GeneOntologyServiceImpl.asRegularGoId(term), taxon));
    }
    return results;
}
Also used : Gene(ubic.gemma.model.genome.Gene) OntologyTerm(ubic.basecode.ontology.model.OntologyTerm)

Example 65 with OntologyTerm

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

the class GeneOntologyServiceImpl method getIsPartOf.

/**
 * Return terms to which the given term has a part_of relation (it is "part_of" them).
 */
private Collection<OntologyTerm> getIsPartOf(OntologyTerm entry) {
    Collection<OntologyTerm> r = new HashSet<>();
    String u = entry.getUri();
    String queryString = "SELECT ?x WHERE {  <" + u + ">  <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?v . " + "?v <http://www.w3.org/2002/07/owl#onProperty>  <" + GeneOntologyServiceImpl.PART_OF_URI + "> . " + "?v <http://www.w3.org/2002/07/owl#someValuesFrom> ?x . }";
    Query q = QueryFactory.create(queryString);
    QueryExecution qexec = QueryExecutionFactory.create(q, (Model) entry.getModel());
    try {
        ResultSet results = qexec.execSelect();
        while (results.hasNext()) {
            QuerySolution soln = results.nextSolution();
            Resource x = soln.getResource("x");
            if (x.isAnon())
                // some reasoners will return these.
                continue;
            String uri = x.getURI();
            if (GeneOntologyServiceImpl.log.isDebugEnabled())
                GeneOntologyServiceImpl.log.debug(entry + " is part of " + GeneOntologyServiceImpl.uri2Term.get(uri));
            r.add(GeneOntologyServiceImpl.uri2Term.get(uri));
        }
    } finally {
        qexec.close();
    }
    return r;
}
Also used : OntologyResource(ubic.basecode.ontology.model.OntologyResource) Resource(com.hp.hpl.jena.rdf.model.Resource) OntologyTerm(ubic.basecode.ontology.model.OntologyTerm)

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