Search in sources :

Example 1 with OntologyResource

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

the class GeneSetSearchImpl method goTermToGeneSets.

private Collection<GeneSet> goTermToGeneSets(OntologyTerm term, Integer maxGeneSetSize) {
    if (term == null)
        return null;
    if (term.getUri() == null)
        return null;
    Collection<OntologyResource> allMatches = new HashSet<>();
    allMatches.add(term);
    allMatches.addAll(this.geneOntologyService.getAllChildren(term));
    GeneSetSearchImpl.log.info(term);
    /*
         * Gather up uris
         */
    Collection<String> termsToFetch = new HashSet<>();
    for (OntologyResource t : allMatches) {
        String goId = this.uri2goid(t);
        termsToFetch.add(goId);
    }
    Map<Taxon, Collection<Gene>> genesByTaxon = this.gene2GoService.findByGOTermsPerTaxon(termsToFetch);
    Collection<GeneSet> results = new HashSet<>();
    for (Taxon t : genesByTaxon.keySet()) {
        Collection<Gene> genes = genesByTaxon.get(t);
        if (genes.isEmpty() || (maxGeneSetSize != null && genes.size() > maxGeneSetSize)) {
            continue;
        }
        GeneSet transientGeneSet = GeneSet.Factory.newInstance();
        transientGeneSet.setName(this.uri2goid(term));
        transientGeneSet.setDescription(term.getLabel());
        for (Gene gene : genes) {
            GeneSetMember gmember = GeneSetMember.Factory.newInstance();
            gmember.setGene(gene);
            transientGeneSet.getMembers().add(gmember);
        }
        results.add(transientGeneSet);
    }
    return results;
}
Also used : Taxon(ubic.gemma.model.genome.Taxon) GeneSetMember(ubic.gemma.model.genome.gene.GeneSetMember) Gene(ubic.gemma.model.genome.Gene) Collection(java.util.Collection) GeneSet(ubic.gemma.model.genome.gene.GeneSet) OntologyResource(ubic.basecode.ontology.model.OntologyResource) HashSet(java.util.HashSet)

Example 2 with OntologyResource

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

the class GeneSetSearchImpl method findByGoTermName.

@Override
public Collection<GeneSet> findByGoTermName(String goTermName, Taxon taxon, Integer maxGoTermsProcessed, Integer maxGeneSetSize) {
    Collection<? extends OntologyResource> matches = this.geneOntologyService.findTerm(StringUtils.strip(goTermName));
    Collection<GeneSet> results = new HashSet<>();
    for (OntologyResource t : matches) {
        assert t instanceof OntologyTerm;
        if (taxon == null) {
            Collection<GeneSet> sets = this.goTermToGeneSets((OntologyTerm) t, maxGeneSetSize);
            results.addAll(sets);
            // noinspection StatementWithEmptyBody // FIXME should we count each species as one go?
            if (maxGoTermsProcessed != null && results.size() > maxGoTermsProcessed) {
            // return results;
            }
        } else {
            GeneSet converted = this.goTermToGeneSet(t, taxon, maxGeneSetSize);
            // converted will be null if its size is more than maxGeneSetSize
            if (converted != null) {
                results.add(converted);
            }
        }
        if (maxGoTermsProcessed != null && results.size() > maxGoTermsProcessed) {
            return results;
        }
    }
    return results;
}
Also used : OntologyTerm(ubic.basecode.ontology.model.OntologyTerm) GeneSet(ubic.gemma.model.genome.gene.GeneSet) OntologyResource(ubic.basecode.ontology.model.OntologyResource) HashSet(java.util.HashSet)

Example 3 with OntologyResource

use of ubic.basecode.ontology.model.OntologyResource 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 4 with OntologyResource

use of ubic.basecode.ontology.model.OntologyResource 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 5 with OntologyResource

use of ubic.basecode.ontology.model.OntologyResource 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)

Aggregations

OntologyResource (ubic.basecode.ontology.model.OntologyResource)7 OntologyTerm (ubic.basecode.ontology.model.OntologyTerm)6 HashSet (java.util.HashSet)3 GeneSet (ubic.gemma.model.genome.gene.GeneSet)3 ConcurrentHashSet (org.compass.core.util.concurrent.ConcurrentHashSet)2 OntologyIndividual (ubic.basecode.ontology.model.OntologyIndividual)2 VocabCharacteristic (ubic.gemma.model.common.description.VocabCharacteristic)2 Gene (ubic.gemma.model.genome.Gene)2 GeneSetMember (ubic.gemma.model.genome.gene.GeneSetMember)2 Collection (java.util.Collection)1 StopWatch (org.apache.commons.lang3.time.StopWatch)1 SearchIndex (ubic.basecode.ontology.search.SearchIndex)1 Taxon (ubic.gemma.model.genome.Taxon)1