Search in sources :

Example 6 with GeneSet

use of ubic.gemma.model.genome.gene.GeneSet in project Gemma by PavlidisLab.

the class GeneSetSearchImpl method findGeneSetsByName.

@Override
public Collection<GeneSet> findGeneSetsByName(String query, Long taxonId) {
    if (StringUtils.isBlank(query)) {
        return new HashSet<>();
    }
    Collection<GeneSet> foundGeneSets;
    Taxon tax;
    tax = taxonService.load(taxonId);
    if (tax == null) {
        // throw new IllegalArgumentException( "Can't locate taxon with id=" + taxonId );
        foundGeneSets = this.findByName(query);
    } else {
        foundGeneSets = this.findByName(query, tax);
    }
    // for testing general search
    foundGeneSets.clear();
    if (query.toUpperCase().startsWith("GO")) {
        if (tax == null) {
            Collection<GeneSet> goSets = this.findByGoId(query);
            foundGeneSets.addAll(goSets);
        } else {
            GeneSet goSet = this.findByGoId(query, tax);
            if (goSet != null)
                foundGeneSets.add(goSet);
        }
    } else {
        foundGeneSets.addAll(this.findByGoTermName(query, tax));
    }
    return foundGeneSets;
}
Also used : Taxon(ubic.gemma.model.genome.Taxon) GeneSet(ubic.gemma.model.genome.gene.GeneSet) HashSet(java.util.HashSet)

Example 7 with GeneSet

use of ubic.gemma.model.genome.gene.GeneSet 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)

Example 8 with GeneSet

use of ubic.gemma.model.genome.gene.GeneSet in project Gemma by PavlidisLab.

the class SearchServiceImpl method filterByTaxon.

/**
 * @param excludeWithoutTaxon if true: If the SearchResults have no "getTaxon" method then the results will get
 *                            filtered out Results with no taxon associated will also get removed.
 */
private void filterByTaxon(SearchSettings settings, Collection<SearchResult> results, boolean excludeWithoutTaxon) {
    if (settings.getTaxon() == null) {
        return;
    }
    Collection<SearchResult> toRemove = new HashSet<>();
    Taxon t = settings.getTaxon();
    if (results == null)
        return;
    for (SearchResult sr : results) {
        Object o = sr.getResultObject();
        try {
            Taxon currentTaxon;
            if (o instanceof ExpressionExperiment) {
                ExpressionExperiment ee = (ExpressionExperiment) o;
                currentTaxon = expressionExperimentService.getTaxon(ee);
            } else if (o instanceof ExpressionExperimentSet) {
                ExpressionExperimentSet ees = (ExpressionExperimentSet) o;
                currentTaxon = ees.getTaxon();
            } else if (o instanceof Gene) {
                Gene gene = (Gene) o;
                currentTaxon = gene.getTaxon();
            } else if (o instanceof GeneSet) {
                GeneSet geneSet = (GeneSet) o;
                currentTaxon = geneSetService.getTaxon(geneSet);
            } else if (o instanceof CharacteristicValueObject) {
                CharacteristicValueObject charVO = (CharacteristicValueObject) o;
                currentTaxon = taxonDao.findByCommonName(charVO.getTaxon());
            } else {
                Method m = o.getClass().getMethod("getTaxon");
                currentTaxon = (Taxon) m.invoke(o);
            }
            if (currentTaxon == null || !currentTaxon.getId().equals(t.getId())) {
                if (currentTaxon == null) {
                    // Sanity check for bad data in db (could happen if EE has no samples). Can happen that
                    // searchResults have a vaild getTaxon method
                    // but the method returns null (shouldn't make it this far)
                    SearchServiceImpl.log.debug("Object has getTaxon method but it returns null. Obj is: " + o);
                }
                toRemove.add(sr);
            }
        } catch (SecurityException | IllegalArgumentException | InvocationTargetException | IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (NoSuchMethodException e) {
            /*
                 * In case of a programming error where the results don't have a taxon at all, we assume we should
                 * filter them out but issue a warning.
                 */
            if (excludeWithoutTaxon) {
                toRemove.add(sr);
                SearchServiceImpl.log.warn("No getTaxon method for: " + o.getClass() + ".  Filtering from results. Error was: " + e);
            }
        }
    }
    results.removeAll(toRemove);
}
Also used : CharacteristicValueObject(ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject) Taxon(ubic.gemma.model.genome.Taxon) Method(java.lang.reflect.Method) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) InvocationTargetException(java.lang.reflect.InvocationTargetException) Gene(ubic.gemma.model.genome.Gene) ExpressionExperimentSet(ubic.gemma.model.analysis.expression.ExpressionExperimentSet) BibliographicReferenceValueObject(ubic.gemma.model.common.description.BibliographicReferenceValueObject) SearchSettingsValueObject(ubic.gemma.model.common.search.SearchSettingsValueObject) BioSequenceValueObject(ubic.gemma.model.genome.sequenceAnalysis.BioSequenceValueObject) GeneEvidenceValueObject(ubic.gemma.model.genome.gene.phenotype.valueObject.GeneEvidenceValueObject) CharacteristicValueObject(ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject) GeneSet(ubic.gemma.model.genome.gene.GeneSet)

Aggregations

GeneSet (ubic.gemma.model.genome.gene.GeneSet)8 HashSet (java.util.HashSet)4 Gene (ubic.gemma.model.genome.Gene)4 Taxon (ubic.gemma.model.genome.Taxon)4 OntologyResource (ubic.basecode.ontology.model.OntologyResource)3 OntologyTerm (ubic.basecode.ontology.model.OntologyTerm)2 GeneSetMember (ubic.gemma.model.genome.gene.GeneSetMember)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Collection (java.util.Collection)1 GOGroupValueObject (ubic.gemma.core.genome.gene.GOGroupValueObject)1 ExpressionExperimentSet (ubic.gemma.model.analysis.expression.ExpressionExperimentSet)1 BibliographicReferenceValueObject (ubic.gemma.model.common.description.BibliographicReferenceValueObject)1 SearchSettingsValueObject (ubic.gemma.model.common.search.SearchSettingsValueObject)1 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)1 GeneValueObject (ubic.gemma.model.genome.gene.GeneValueObject)1 CharacteristicValueObject (ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject)1 GeneEvidenceValueObject (ubic.gemma.model.genome.gene.phenotype.valueObject.GeneEvidenceValueObject)1 BioSequenceValueObject (ubic.gemma.model.genome.sequenceAnalysis.BioSequenceValueObject)1