Search in sources :

Example 11 with OntologyTerm

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

the class GoMetric method getOntologyTerms.

/**
 * @param gene gene
 * @return direct GO annotation terms
 */
private Collection<OntologyTerm> getOntologyTerms(Gene gene) {
    Collection<VocabCharacteristic> termsVoc = gene2GOAssociationService.findByGene(gene);
    HashSet<OntologyTerm> termsGO = new HashSet<>();
    for (VocabCharacteristic characteristic : termsVoc) {
        OntologyTerm term = GeneOntologyServiceImpl.getTermForId(characteristic.getValue());
        if ((term != null))
            termsGO.add(term);
    }
    return termsGO;
}
Also used : VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic) OntologyTerm(ubic.basecode.ontology.model.OntologyTerm)

Example 12 with OntologyTerm

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

the class OntologyServiceImpl method findCharacteristicsFromOntology.

/**
 * given a collection of characteristics add them to the correct List
 */
private Collection<CharacteristicValueObject> findCharacteristicsFromOntology(String searchQuery, boolean useNeuroCartaOntology, Map<String, CharacteristicValueObject> characteristicFromDatabaseWithValueUri) {
    Collection<CharacteristicValueObject> characteristicsFromOntology = new HashSet<>();
    // in neurocarta we don't need to search all Ontologies
    Collection<AbstractOntologyService> ontologyServicesToUse = new HashSet<>();
    if (useNeuroCartaOntology) {
        ontologyServicesToUse.add(this.nifstdOntologyService);
        ontologyServicesToUse.add(this.fmaOntologyService);
        ontologyServicesToUse.add(this.obiService);
    } else {
        ontologyServicesToUse = this.ontologyServices;
    }
    // search all Ontology
    for (AbstractOntologyService ontologyService : ontologyServicesToUse) {
        Collection<OntologyTerm> ontologyTerms = ontologyService.findTerm(searchQuery);
        for (OntologyTerm ontologyTerm : ontologyTerms) {
            // if the ontology term wasnt already found in the database
            if (characteristicFromDatabaseWithValueUri.get(ontologyTerm.getUri()) == null) {
                CharacteristicValueObject phenotype = new CharacteristicValueObject(-1L, ontologyTerm.getLabel().toLowerCase(), ontologyTerm.getUri());
                characteristicsFromOntology.add(phenotype);
            }
        }
    }
    return characteristicsFromOntology;
}
Also used : CharacteristicValueObject(ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject) OntologyTerm(ubic.basecode.ontology.model.OntologyTerm) ConcurrentHashSet(org.compass.core.util.concurrent.ConcurrentHashSet)

Example 13 with OntologyTerm

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

the class GeneOntologyServiceImpl method getPartsOf.

/**
 * Return terms which have "part_of" relation with the given term (they are "part_of" the given term).
 */
private Collection<OntologyTerm> getPartsOf(OntologyTerm entry) {
    Collection<OntologyTerm> r = new HashSet<>();
    String u = entry.getUri();
    String queryString = "SELECT ?x WHERE {" + "?x <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> <" + u + "> . }";
    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");
            String uri = x.getURI();
            if (x.isAnon())
                // some reasoners will return these.
                continue;
            if (GeneOntologyServiceImpl.log.isDebugEnabled())
                GeneOntologyServiceImpl.log.debug(GeneOntologyServiceImpl.uri2Term.get(uri) + " is part of " + entry);
            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)

Example 14 with OntologyTerm

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

the class GeneOntologyServiceImpl method addTerms.

private void addTerms(Collection<OntologyResource> newTerms) {
    for (OntologyResource term : newTerms) {
        if (term.getUri() == null)
            continue;
        if (term instanceof OntologyTerm) {
            OntologyTerm ontTerm = (OntologyTerm) term;
            GeneOntologyServiceImpl.uri2Term.put(term.getUri(), ontTerm);
            for (String alternativeID : ontTerm.getAlternativeIds()) {
                GeneOntologyServiceImpl.log.debug(GeneOntologyServiceImpl.toUri(alternativeID));
                GeneOntologyServiceImpl.uri2Term.put(GeneOntologyServiceImpl.toUri(alternativeID), ontTerm);
            }
        }
    }
}
Also used : OntologyTerm(ubic.basecode.ontology.model.OntologyTerm) OntologyResource(ubic.basecode.ontology.model.OntologyResource)

Example 15 with OntologyTerm

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

the class GeneOntologyServiceImpl method getAncestors.

private synchronized Collection<OntologyTerm> getAncestors(OntologyTerm entry, boolean includePartOf) {
    if (entry == null) {
        return new HashSet<>();
    }
    Collection<OntologyTerm> ancestors = parentsCache.get(entry.getUri());
    if (ancestors == null) {
        ancestors = new HashSet<>();
        Collection<OntologyTerm> parents = this.getParents(entry, includePartOf);
        if (parents != null) {
            for (OntologyTerm parent : parents) {
                ancestors.add(parent);
                ancestors.addAll(this.getAncestors(parent, includePartOf));
            }
        }
        ancestors = Collections.unmodifiableCollection(ancestors);
        parentsCache.put(entry.getUri(), ancestors);
    }
    return new HashSet<>(ancestors);
}
Also used : 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