Search in sources :

Example 56 with OntologyTerm

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

the class GoMetric method getChildrenOccurrence.

/**
 * @param termCountMap each GO term uri mapped to the number of its occurrence in the corpus
 * @param term         the uri of the query GO term
 * @return the number of times the query GO term occurs in addition to the number of times its children occur in
 * the corpus
 */
public Integer getChildrenOccurrence(Map<String, Integer> termCountMap, String term) {
    int termCount = termCountMap.get(term);
    OntologyTerm ont = GeneOntologyServiceImpl.getTermForURI(term);
    Collection<OntologyTerm> children = geneOntologyService.getAllChildren(ont, partOf);
    if (children.isEmpty()) {
        return termCount;
    }
    for (OntologyTerm child : children) {
        if (termCountMap.containsKey(child.getUri())) {
            int count = termCountMap.get(child.getUri());
            termCount += count;
        }
    }
    return termCount;
}
Also used : OntologyTerm(ubic.basecode.ontology.model.OntologyTerm)

Example 57 with OntologyTerm

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

the class OntologyServiceImpl method termsToCharacteristics.

/**
 * Convert raw ontology resources into VocabCharacteristics.
 */
@Override
public Collection<VocabCharacteristic> termsToCharacteristics(final Collection<? extends OntologyResource> terms) {
    Collection<VocabCharacteristic> results = new HashSet<>();
    if ((terms == null) || (terms.isEmpty()))
        return results;
    for (OntologyResource res : terms) {
        if (res == null)
            continue;
        VocabCharacteristic vc = VocabCharacteristic.Factory.newInstance();
        if (res instanceof OntologyTerm) {
            OntologyTerm term = (OntologyTerm) res;
            vc.setValue(term.getTerm());
            vc.setValueUri(term.getUri());
            vc.setDescription(term.getComment());
        } else if (res instanceof OntologyIndividual) {
            OntologyIndividual indi = (OntologyIndividual) res;
            vc.setValue(indi.getLabel());
            vc.setValueUri(indi.getUri());
            vc.setDescription("Individual");
        } else {
            OntologyServiceImpl.log.warn("What is it? " + res);
            continue;
        }
        if (vc.getValue() == null)
            continue;
        results.add(vc);
    }
    OntologyServiceImpl.log.debug("returning " + results.size() + " terms after filter");
    return results;
}
Also used : VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic) OntologyIndividual(ubic.basecode.ontology.model.OntologyIndividual) OntologyTerm(ubic.basecode.ontology.model.OntologyTerm) OntologyResource(ubic.basecode.ontology.model.OntologyResource) ConcurrentHashSet(org.compass.core.util.concurrent.ConcurrentHashSet)

Example 58 with OntologyTerm

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

the class OntologyServiceImpl method convert.

/**
 * Given a collection of ontology terms converts them to a collection of VocabCharacteristics
 */
private Collection<VocabCharacteristic> convert(final Collection<OntologyResource> resources) {
    Collection<VocabCharacteristic> converted = new HashSet<>();
    if ((resources == null) || (resources.isEmpty()))
        return converted;
    for (OntologyResource res : resources) {
        VocabCharacteristic vc = VocabCharacteristic.Factory.newInstance();
        // If there is no URI we don't want to send it back (ie useless)
        if ((res.getUri() == null) || StringUtils.isEmpty(res.getUri()))
            continue;
        if (res instanceof OntologyTerm) {
            OntologyTerm term = (OntologyTerm) res;
            vc.setValue(term.getTerm());
            vc.setValueUri(term.getUri());
            vc.setDescription(term.getComment());
        }
        if (res instanceof OntologyIndividual) {
            OntologyIndividual indi = (OntologyIndividual) res;
            vc.setValue(indi.getLabel());
            vc.setValueUri(indi.getUri());
            vc.setDescription("Individual");
        }
        converted.add(vc);
    }
    return converted;
}
Also used : VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic) OntologyIndividual(ubic.basecode.ontology.model.OntologyIndividual) OntologyTerm(ubic.basecode.ontology.model.OntologyTerm) OntologyResource(ubic.basecode.ontology.model.OntologyResource) ConcurrentHashSet(org.compass.core.util.concurrent.ConcurrentHashSet)

Example 59 with OntologyTerm

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

the class OntologyServiceImpl method initializeCategoryTerms.

private synchronized void initializeCategoryTerms() {
    URL termUrl = OntologyServiceImpl.class.getResource("/ubic/gemma/core/ontology/EFO.factor.categories.txt");
    OntologyServiceImpl.categoryTerms = new ConcurrentHashSet<>();
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(termUrl.openStream()))) {
        String line;
        boolean warned = false;
        while ((line = reader.readLine()) != null) {
            if (line.startsWith("#") || StringUtils.isEmpty(line))
                continue;
            String[] f = StringUtils.split(line, '\t');
            if (f.length < 2) {
                continue;
            }
            OntologyTerm t = this.getTerm(f[0]);
            if (t == null) {
                // available. Inference will not be available.
                if (!warned) {
                    OntologyServiceImpl.log.info("Ontology needed is not loaded? Using light-weight placeholder for " + f[0] + " (further warnings hidden)");
                    warned = true;
                }
                t = new OntologyTermSimple(f[0], f[1]);
            }
            OntologyServiceImpl.categoryTerms.add(t);
        }
    } catch (IOException ioe) {
        OntologyServiceImpl.log.error("Error reading from term list '" + termUrl + "'; returning general term list", ioe);
        OntologyServiceImpl.categoryTerms = null;
    }
    OntologyServiceImpl.categoryTerms = Collections.unmodifiableCollection(OntologyServiceImpl.categoryTerms);
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) OntologyTerm(ubic.basecode.ontology.model.OntologyTerm) IOException(java.io.IOException) URL(java.net.URL) OntologyTermSimple(ubic.basecode.ontology.model.OntologyTermSimple)

Example 60 with OntologyTerm

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

the class GeneOntologyServiceImpl method getParents.

@Override
public Collection<OntologyTerm> getParents(OntologyTerm entry, boolean includePartOf) {
    Collection<OntologyTerm> parents = entry.getParents(true);
    Collection<OntologyTerm> results = new HashSet<>();
    for (OntologyTerm term : parents) {
        // The isRoot() returns true for the MolecularFunction, BiologicalProcess, CellularComponent
        if (term.isRoot())
            continue;
        if (term.getUri().equalsIgnoreCase(GeneOntologyServiceImpl.ALL_ROOT))
            continue;
        // noinspection StatementWithEmptyBody // Better readability
        if (term instanceof OntologyClassRestriction) {
        // don't keep it. - for example, "ends_during" RO_0002093
        } else {
            results.add(term);
        }
    }
    if (includePartOf)
        results.addAll(this.getIsPartOf(entry));
    return results;
}
Also used : OntologyClassRestriction(ubic.basecode.ontology.model.OntologyClassRestriction) 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