Search in sources :

Example 1 with ExpressionExperimentExperimentalFactorValueObject

use of ubic.gemma.web.controller.expression.experiment.ExpressionExperimentExperimentalFactorValueObject in project Gemma by PavlidisLab.

the class DifferentialExpressionSearchController method getFactors.

/**
 * AJAX entry.
 * Value objects returned contain experiments that have 2 factors and have had the diff analysis run on it.
 */
public Collection<ExpressionExperimentExperimentalFactorValueObject> getFactors(final Collection<Long> eeIds) {
    Collection<ExpressionExperimentExperimentalFactorValueObject> result = new HashSet<>();
    final Collection<Long> securityFilteredIds = securityFilterExpressionExperimentIds(eeIds);
    if (securityFilteredIds.size() == 0) {
        return result;
    }
    log.debug("Getting factors for experiments with ids: " + StringUtils.abbreviate(securityFilteredIds.toString(), 100));
    Collection<Long> filteredEeIds = new HashSet<>();
    Map<Long, Collection<DifferentialExpressionAnalysis>> diffAnalyses = differentialExpressionAnalysisService.findByInvestigationIds(securityFilteredIds);
    if (diffAnalyses.isEmpty()) {
        log.debug("No differential expression analyses for given ids: " + StringUtils.join(filteredEeIds, ','));
        return result;
    }
    Collection<ExpressionExperimentValueObject> eevos = this.expressionExperimentService.loadValueObjects(diffAnalyses.keySet(), false);
    Map<Long, ExpressionExperimentValueObject> eevoMap = new HashMap<>();
    for (ExpressionExperimentValueObject eevo : eevos) {
        eevoMap.put(eevo.getId(), eevo);
    }
    for (Long id : diffAnalyses.keySet()) {
        Collection<DifferentialExpressionAnalysis> analyses = diffAnalyses.get(id);
        for (DifferentialExpressionAnalysis analysis : analyses) {
            differentialExpressionAnalysisService.thaw(analysis);
            Collection<ExperimentalFactor> factors = new HashSet<>();
            for (FactorAssociatedAnalysisResultSet fars : analysis.getResultSets()) {
                // FIXME includes factors making up interaction terms, but shouldn't
                // matter, because they will be included as main effects too. If not, this will be wrong!
                factors.addAll(fars.getExperimentalFactors());
            }
            filteredEeIds.add(id);
            ExpressionExperimentValueObject eevo = eevoMap.get(id);
            ExpressionExperimentExperimentalFactorValueObject eeefvo = new ExpressionExperimentExperimentalFactorValueObject();
            eeefvo.setExpressionExperiment(eevo);
            eeefvo.setNumFactors(factors.size());
            for (ExperimentalFactor ef : factors) {
                ExperimentalFactorValueObject efvo = geneDifferentialExpressionService.configExperimentalFactorValueObject(ef);
                eeefvo.getExperimentalFactors().add(efvo);
            }
            result.add(eeefvo);
        }
    }
    log.info("Filtered experiments.  Returning factors for experiments with ids: " + StringUtils.abbreviate(filteredEeIds.toString(), 100));
    return result;
}
Also used : DifferentialExpressionAnalysis(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis) ExpressionExperimentExperimentalFactorValueObject(ubic.gemma.web.controller.expression.experiment.ExpressionExperimentExperimentalFactorValueObject) FactorAssociatedAnalysisResultSet(ubic.gemma.model.analysis.expression.FactorAssociatedAnalysisResultSet) ExpressionExperimentExperimentalFactorValueObject(ubic.gemma.web.controller.expression.experiment.ExpressionExperimentExperimentalFactorValueObject)

Aggregations

FactorAssociatedAnalysisResultSet (ubic.gemma.model.analysis.expression.FactorAssociatedAnalysisResultSet)1 DifferentialExpressionAnalysis (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis)1 ExpressionExperimentExperimentalFactorValueObject (ubic.gemma.web.controller.expression.experiment.ExpressionExperimentExperimentalFactorValueObject)1