Search in sources :

Example 6 with ExpressionExperimentValueObject

use of ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject in project Gemma by PavlidisLab.

the class ProcessedExpressionDataVectorDaoImpl method makeCacheMap.

private Map<Long, Map<Long, Collection<DoubleVectorValueObject>>> makeCacheMap(Collection<DoubleVectorValueObject> newResults) {
    Map<Long, Map<Long, Collection<DoubleVectorValueObject>>> mapForCache = new HashMap<>();
    for (DoubleVectorValueObject v : newResults) {
        ExpressionExperimentValueObject e = v.getExpressionExperiment();
        if (!mapForCache.containsKey(e.getId())) {
            mapForCache.put(e.getId(), new HashMap<Long, Collection<DoubleVectorValueObject>>());
        }
        Map<Long, Collection<DoubleVectorValueObject>> innerMap = mapForCache.get(e.getId());
        for (Long g : v.getGenes()) {
            if (!innerMap.containsKey(g)) {
                innerMap.put(g, new HashSet<DoubleVectorValueObject>());
            }
            innerMap.get(g).add(v);
        }
    }
    return mapForCache;
}
Also used : ExpressionExperimentValueObject(ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject)

Example 7 with ExpressionExperimentValueObject

use of ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject in project Gemma by PavlidisLab.

the class GeneCoexpressionSearchServiceImpl method doCoexpressionSearch.

/**
 * @param genes          1 or more.
 * @param stringency;    this may be modified to control the number of results, unless "queryGenesOnly" is true.
 * @param maxResults     per gene, not including the query genes themselves. Ignored if this is 'queryGenesOnly'
 * @param queryGenesOnly will be ignored if number of genes is 1.
 * @return CoexpressionMetaValueObject, in which the results are already populated and sorted.
 */
private CoexpressionMetaValueObject doCoexpressionSearch(Collection<Long> inputEeIds, Collection<Long> genes, int stringency, final int maxResults, final boolean queryGenesOnly, final boolean quick) {
    if (genes.isEmpty()) {
        CoexpressionMetaValueObject r = new CoexpressionMetaValueObject();
        r.setErrorState("No genes selected");
        return r;
    }
    boolean actuallyUseQueryGeneOnly = queryGenesOnly && genes.size() > 1;
    Taxon taxon = this.geneService.load(genes.iterator().next()).getTaxon();
    List<ExpressionExperimentValueObject> eevos = this.getFilteredEEVos(inputEeIds, taxon);
    CoexpressionMetaValueObject result = this.initValueObject(genes, eevos);
    if (eevos.isEmpty()) {
        result = new CoexpressionMetaValueObject();
        result.setErrorState("No experiments selected");
        return result;
    }
    Collection<Long> eeIds = EntityUtils.getIds(eevos);
    Map<Long, List<CoexpressionValueObject>> allCoexpressions;
    if (genes.size() > GeneCoexpressionSearchServiceImpl.THRESHOLD_TRIGGER_QUERY_GENES_ONLY) {
        if (!actuallyUseQueryGeneOnly) {
            GeneCoexpressionSearchServiceImpl.log.info("Switching to 'query genes only'");
        }
        actuallyUseQueryGeneOnly = true;
    }
    if (stringency < 1)
        stringency = 1;
    if (!queryGenesOnly) {
        stringency = Math.max(stringency, this.chooseStringency(actuallyUseQueryGeneOnly, eeIds.size(), genes.size()));
        GeneCoexpressionSearchServiceImpl.log.info("Stringency set to " + stringency + " based on number of experiments (" + eeIds.size() + ") and genes (" + genes.size() + ") queried");
    } else {
        GeneCoexpressionSearchServiceImpl.log.info("Query gene only: stringency maintained at requested value=" + stringency);
    }
    assert stringency >= 1 || eeIds.size() == 1;
    // HACK drop the stringency until we get some results.
    int stepSize = 3;
    while (true) {
        if (actuallyUseQueryGeneOnly) {
            // note that maxResults is ignored.
            if (genes.size() < 2) {
                // should be impossible - could assert.
                throw new IllegalArgumentException("cannot do inter-gene coexpression search with only one gene");
            }
            allCoexpressions = coexpressionService.findInterCoexpressionRelationships(taxon, genes, eeIds, stringency, quick);
        } else {
            allCoexpressions = coexpressionService.findCoexpressionRelationships(taxon, genes, eeIds, stringency, maxResults, quick);
        }
        int minimum_stringency_for_requery = 2;
        if (allCoexpressions.isEmpty() && stringency > minimum_stringency_for_requery) {
            // step size completely made up.
            stringency -= stepSize;
            // keep stringency at least 2.
            stringency = Math.max(minimum_stringency_for_requery, stringency);
            GeneCoexpressionSearchServiceImpl.log.info("No results, re-querying with stringency=" + stringency);
        } else {
            // no results.
            break;
        }
    }
    GeneCoexpressionSearchServiceImpl.log.info("Final actual stringency used was " + stringency);
    result.setQueryStringency(stringency);
    result.setQueryGenesOnly(actuallyUseQueryGeneOnly);
    Set<Long> queryGeneIds = allCoexpressions.keySet();
    assert genes.containsAll(queryGeneIds);
    Map<Long, GeneValueObject> idMap = EntityUtils.getIdMap(geneService.loadValueObjectsByIds(queryGeneIds));
    int k = 0;
    for (Long queryGene : queryGeneIds) {
        Collection<CoexpressionValueObject> coexpressions = allCoexpressions.get(queryGene);
        List<CoexpressionValueObjectExt> results = this.addExtCoexpressionValueObjects(idMap.get(queryGene), coexpressions, actuallyUseQueryGeneOnly, genes);
        result.getResults().addAll(results);
        CoexpressionSummaryValueObject summary = new CoexpressionSummaryValueObject(queryGene);
        summary.setDatasetsAvailable(eevos.size());
        summary.setLinksFound(coexpressions.size());
        result.getSummaries().put(queryGene, summary);
        if (++k % 100 == 0) {
            GeneCoexpressionSearchServiceImpl.log.info("Processed results for " + k + " query genes ...");
        }
    }
    Collections.sort(result.getResults());
    // FIXME we might want to suppress this in some situations
    if (!queryGenesOnly) {
        result.trim();
    }
    this.populateNodeDegrees(result);
    return result;
}
Also used : Taxon(ubic.gemma.model.genome.Taxon) GeneValueObject(ubic.gemma.model.genome.gene.GeneValueObject) ExpressionExperimentValueObject(ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject) CoexpressionValueObject(ubic.gemma.persistence.service.association.coexpression.CoexpressionValueObject)

Example 8 with ExpressionExperimentValueObject

use of ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject in project Gemma by PavlidisLab.

the class GeneCoexpressionSearchServiceImpl method getFilteredEEVos.

/**
 * Security-filter the experiments, remove troubled ones, and retain only those that have an analysis.
 *
 * @param eeIds can be null, in which case all available (to user) IDs are gotten
 */
private List<ExpressionExperimentValueObject> getFilteredEEVos(Collection<Long> eeIds, Taxon taxon) {
    List<ExpressionExperimentValueObject> securityFilteredEevos;
    if (eeIds == null || eeIds.isEmpty()) {
        // all valid experiments for taxon.
        securityFilteredEevos = new ArrayList<>(expressionExperimentService.loadValueObjects(coexpressionAnalysisService.getExperimentsWithAnalysis(taxon), false));
    } else {
        securityFilteredEevos = new ArrayList<>(expressionExperimentService.loadValueObjects(coexpressionAnalysisService.getExperimentsWithAnalysis(eeIds), false));
    }
    List<ExpressionExperimentValueObject> eevos = new ArrayList<>();
    StopWatch timerFilterTroubled = new StopWatch();
    timerFilterTroubled.start();
    // only keep untroubled experiments
    for (ExpressionExperimentValueObject eevo : securityFilteredEevos) {
        if (!eevo.getTroubled()) {
            eevos.add(eevo);
        }
    }
    if (timerFilterTroubled.getTime() > 100) {
        GeneCoexpressionSearchServiceImpl.log.info("Filtering eevos took " + timerFilterTroubled.getTime() + "ms");
    }
    return eevos;
}
Also used : ExpressionExperimentValueObject(ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject) StopWatch(org.apache.commons.lang3.time.StopWatch)

Example 9 with ExpressionExperimentValueObject

use of ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject in project Gemma by PavlidisLab.

the class ExpressionExperimentSearchServiceImpl method searchExperimentsAndExperimentGroups.

@Override
public List<SearchResultDisplayObject> searchExperimentsAndExperimentGroups(String query, Long taxonId) {
    List<SearchResultDisplayObject> displayResults = new LinkedList<>();
    // session-bound sets (not autogen sets until handling of large searches is fixed)
    if (StringUtils.isBlank(query)) {
        return this.searchExperimentsAndExperimentGroupBlankQuery(taxonId);
    }
    Map<Class<?>, List<SearchResult>> results = this.initialSearch(query, taxonId);
    List<SearchResultDisplayObject> experimentSets = this.getExpressionExperimentSetResults(results);
    List<SearchResultDisplayObject> experiments = this.getExpressionExperimentResults(results);
    if (experimentSets.isEmpty() && experiments.isEmpty()) {
        return displayResults;
    }
    /*
         * ALL RESULTS BY TAXON GROUPS
         */
    // if >1 result, add a group whose members are all experiments returned from search
    Map<Long, Set<Long>> eeIdsByTaxonId = new HashMap<>();
    // add every individual experiment to the set, grouped by taxon and also altogether.
    for (SearchResultDisplayObject srdo : experiments) {
        // group by the Parent Taxon, for things like salmonid - see bug 3286
        Long taxId;
        if (srdo.getParentTaxonId() != null) {
            taxId = srdo.getParentTaxonId();
        } else {
            taxId = srdo.getTaxonId();
        }
        if (!eeIdsByTaxonId.containsKey(taxId)) {
            eeIdsByTaxonId.put(taxId, new HashSet<Long>());
        }
        ExpressionExperimentValueObject eevo = (ExpressionExperimentValueObject) srdo.getResultValueObject();
        eeIdsByTaxonId.get(taxId).add(eevo.getId());
    }
    // for each group
    for (SearchResultDisplayObject eesSRO : experimentSets) {
        ExpressionExperimentSetValueObject set = (ExpressionExperimentSetValueObject) eesSRO.getResultValueObject();
        /*
             * This is security filtered.
             */
        Collection<Long> ids = EntityUtils.getIds(expressionExperimentSetService.getExperimentValueObjectsInSet(set.getId()));
        // to account for security filtering.
        set.setSize(ids.size());
        if (!eeIdsByTaxonId.containsKey(set.getTaxonId())) {
            eeIdsByTaxonId.put(set.getTaxonId(), new HashSet<Long>());
        }
        eeIdsByTaxonId.get(set.getTaxonId()).addAll(ids);
    }
    // make an entry for each taxon
    Long taxonId2;
    for (Map.Entry<Long, Set<Long>> entry : eeIdsByTaxonId.entrySet()) {
        taxonId2 = entry.getKey();
        Taxon taxon = taxonService.load(taxonId2);
        if (taxon != null && entry.getValue().size() > 0) {
            FreeTextExpressionExperimentResultsValueObject ftvo = new FreeTextExpressionExperimentResultsValueObject("All " + taxon.getCommonName() + " results for '" + query + "'", "All " + taxon.getCommonName() + " experiments found for your query", taxon.getId(), taxon.getCommonName(), entry.getValue(), query);
            int numWithDifferentialExpressionAnalysis = differentialExpressionAnalysisService.getExperimentsWithAnalysis(entry.getValue()).size();
            assert numWithDifferentialExpressionAnalysis <= entry.getValue().size();
            int numWithCoexpressionAnalysis = coexpressionAnalysisService.getExperimentsWithAnalysis(entry.getValue()).size();
            ftvo.setNumWithCoexpressionAnalysis(numWithCoexpressionAnalysis);
            ftvo.setNumWithDifferentialExpressionAnalysis(numWithDifferentialExpressionAnalysis);
            displayResults.add(new SearchResultDisplayObject(ftvo));
        }
    }
    displayResults.addAll(experimentSets);
    displayResults.addAll(experiments);
    if (displayResults.isEmpty()) {
        ExpressionExperimentSearchServiceImpl.log.info("No results for search: " + query);
    } else {
        ExpressionExperimentSearchServiceImpl.log.info("Results for search: " + query + " size=" + displayResults.size() + " entry0: " + ((SearchResultDisplayObject) (displayResults.toArray())[0]).getName() + " valueObject:" + ((SearchResultDisplayObject) (displayResults.toArray())[0]).getResultValueObject().toString());
    }
    return displayResults;
}
Also used : ExpressionExperimentSet(ubic.gemma.model.analysis.expression.ExpressionExperimentSet) Taxon(ubic.gemma.model.genome.Taxon) FreeTextExpressionExperimentResultsValueObject(ubic.gemma.model.expression.experiment.FreeTextExpressionExperimentResultsValueObject) ExpressionExperimentSetValueObject(ubic.gemma.model.expression.experiment.ExpressionExperimentSetValueObject) ExpressionExperimentValueObject(ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject) SearchResultDisplayObject(ubic.gemma.core.search.SearchResultDisplayObject)

Example 10 with ExpressionExperimentValueObject

use of ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject in project Gemma by PavlidisLab.

the class ExpressionExperimentSearchServiceImpl method searchExpressionExperiments.

@Override
public Collection<ExpressionExperimentValueObject> searchExpressionExperiments(String query) {
    SearchSettings settings = SearchSettingsImpl.expressionExperimentSearch(query);
    List<SearchResult> experimentSearchResults = searchService.search(settings).get(ExpressionExperiment.class);
    if (experimentSearchResults == null || experimentSearchResults.isEmpty()) {
        ExpressionExperimentSearchServiceImpl.log.info("No experiments for search: " + query);
        return new HashSet<>();
    }
    ExpressionExperimentSearchServiceImpl.log.info("Experiment search: " + query + ", " + experimentSearchResults.size() + " found");
    Collection<ExpressionExperimentValueObject> experimentValueObjects = expressionExperimentService.loadValueObjects(EntityUtils.getIds(experimentSearchResults), true);
    ExpressionExperimentSearchServiceImpl.log.info("Experiment search: " + experimentValueObjects.size() + " value objects returned.");
    return experimentValueObjects;
}
Also used : ExpressionExperimentValueObject(ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject) SearchSettings(ubic.gemma.model.common.search.SearchSettings) SearchResult(ubic.gemma.core.search.SearchResult)

Aggregations

ExpressionExperimentValueObject (ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject)21 StopWatch (org.apache.commons.lang3.time.StopWatch)4 Test (org.junit.Test)4 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)4 Taxon (ubic.gemma.model.genome.Taxon)4 BaseSpringWebTest (ubic.gemma.web.util.BaseSpringWebTest)4 ModelAndView (org.springframework.web.servlet.ModelAndView)3 SearchResult (ubic.gemma.core.search.SearchResult)3 ExpressionExperimentSet (ubic.gemma.model.analysis.expression.ExpressionExperimentSet)3 ExpressionExperimentDetailsValueObject (ubic.gemma.model.expression.experiment.ExpressionExperimentDetailsValueObject)3 Gene (ubic.gemma.model.genome.Gene)3 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2 SearchResultDisplayObject (ubic.gemma.core.search.SearchResultDisplayObject)2 BibliographicReference (ubic.gemma.model.common.description.BibliographicReference)2 CitationValueObject (ubic.gemma.model.common.description.CitationValueObject)2 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)2 ArrayDesignValueObject (ubic.gemma.model.expression.arrayDesign.ArrayDesignValueObject)2 BioAssayDimension (ubic.gemma.model.expression.bioAssayData.BioAssayDimension)2 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)2 BioAssaySet (ubic.gemma.model.expression.experiment.BioAssaySet)2