Search in sources :

Example 6 with OntologyResource

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

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

the class GeneSetSearchImpl method goTermToGeneSet.

/**
 * Convert a GO term to a 'GeneSet', including genes from all child terms. Divide up by taxon.
 */
private GeneSet goTermToGeneSet(OntologyResource term, Taxon taxon, Integer maxGeneSetSize) {
    assert taxon != null;
    if (term == null)
        return null;
    if (term.getUri() == null)
        return null;
    Collection<OntologyResource> allMatches = new HashSet<>();
    allMatches.add(term);
    assert term instanceof OntologyTerm;
    allMatches.addAll(this.geneOntologyService.getAllChildren((OntologyTerm) 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);
    }
    Collection<Gene> genes = this.gene2GoService.findByGOTerms(termsToFetch, taxon);
    if (genes.isEmpty() || (maxGeneSetSize != null && genes.size() > maxGeneSetSize)) {
        return null;
    }
    GeneSet transientGeneSet = GeneSet.Factory.newInstance();
    transientGeneSet.setName(this.uri2goid(term));
    if (term.getLabel() == null) {
        GeneSetSearchImpl.log.warn(" Label for term " + term.getUri() + " was null");
    }
    // noinspection StatementWithEmptyBody // FIXME this is an individual or a 'resource', not a 'class', but it's a real GO term. How to get the text.
    if (term.getLabel() != null && term.getLabel().toUpperCase().startsWith("GO_")) {
    }
    transientGeneSet.setDescription(term.getLabel());
    for (Gene gene : genes) {
        GeneSetMember gmember = GeneSetMember.Factory.newInstance();
        gmember.setGene(gene);
        transientGeneSet.getMembers().add(gmember);
    }
    return transientGeneSet;
}
Also used : Gene(ubic.gemma.model.genome.Gene) OntologyTerm(ubic.basecode.ontology.model.OntologyTerm) GeneSetMember(ubic.gemma.model.genome.gene.GeneSetMember) GeneSet(ubic.gemma.model.genome.gene.GeneSet) OntologyResource(ubic.basecode.ontology.model.OntologyResource) HashSet(java.util.HashSet)

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