Search in sources :

Example 16 with CharacteristicValueObject

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

Example 17 with CharacteristicValueObject

use of ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject in project Gemma by PavlidisLab.

the class GeneController method loadGeneDetails.

/**
 * AJAX used for gene page
 */
public GeneValueObject loadGeneDetails(Long geneId) {
    // return geneCoreService.loadGeneDetails( geneId );
    GeneValueObject gvo = geneCoreService.loadGeneDetails(geneId);
    Collection<EvidenceValueObject<? extends PhenotypeAssociation>> collEVO = phenotypeAssociationManagerService.findEvidenceByGeneId(geneId, new HashSet<String>(), new EvidenceFilter(gvo.getTaxonId(), false, null));
    Iterator<EvidenceValueObject<? extends PhenotypeAssociation>> iter = collEVO.iterator();
    Collection<CharacteristicValueObject> collFilteredDVO = new HashSet<>();
    while (iter.hasNext()) {
        EvidenceValueObject evo = iter.next();
        if (!evo.isHomologueEvidence())
            collFilteredDVO.addAll(evo.getPhenotypes());
    }
    gvo.setPhenotypes(collFilteredDVO);
    gvo.setNumGoTerms(this.findGOTerms(geneId).size());
    return gvo;
}
Also used : GeneValueObject(ubic.gemma.model.genome.gene.GeneValueObject) EvidenceValueObject(ubic.gemma.model.genome.gene.phenotype.valueObject.EvidenceValueObject) CharacteristicValueObject(ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject) PhenotypeAssociation(ubic.gemma.model.association.phenotype.PhenotypeAssociation) EvidenceFilter(ubic.gemma.model.genome.gene.phenotype.EvidenceFilter)

Aggregations

CharacteristicValueObject (ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject)17 StopWatch (org.apache.commons.lang3.time.StopWatch)6 ConcurrentHashSet (org.compass.core.util.concurrent.ConcurrentHashSet)5 Gene (ubic.gemma.model.genome.Gene)5 OntologyTerm (ubic.basecode.ontology.model.OntologyTerm)3 SearchResult (ubic.gemma.core.search.SearchResult)3 Characteristic (ubic.gemma.model.common.description.Characteristic)3 Test (org.junit.Test)2 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)2 ExpressionExperimentSet (ubic.gemma.model.analysis.expression.ExpressionExperimentSet)2 PhenotypeAssociation (ubic.gemma.model.association.phenotype.PhenotypeAssociation)2 VocabCharacteristic (ubic.gemma.model.common.description.VocabCharacteristic)2 SearchSettingsValueObject (ubic.gemma.model.common.search.SearchSettingsValueObject)2 GeneValueObject (ubic.gemma.model.genome.gene.GeneValueObject)2 GeneEvidenceValueObject (ubic.gemma.model.genome.gene.phenotype.valueObject.GeneEvidenceValueObject)2 BioSequenceValueObject (ubic.gemma.model.genome.sequenceAnalysis.BioSequenceValueObject)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1