Search in sources :

Example 1 with Condition

use of ubic.gemma.core.tasks.visualization.DifferentialExpressionGenesConditionsValueObject.Condition in project Gemma by PavlidisLab.

the class DifferentialExpressionSearchTaskImpl method addConditionsToSearchResultValueObject.

/**
 * Get information on the conditions to be searched. This is not part of the query for the results themselves, but
 * uses the database to get metadata/summaries about the analyses that will be used. Initializes the searchResult
 * value object. Later, values which are non-missing will be replaced with either 'non-significant' or 'significant'
 * results.
 *
 * @param searchResult to be initialized
 * @return list of the resultSets that should be queried.
 */
private List<DiffExResultSetSummaryValueObject> addConditionsToSearchResultValueObject(DifferentialExpressionGenesConditionsValueObject searchResult) {
    StopWatch watch = new StopWatch("addConditionsToSearchResultValueObject");
    watch.start("Add conditions to search result value object");
    List<DiffExResultSetSummaryValueObject> usedResultSets = new LinkedList<>();
    int i = 0;
    DifferentialExpressionSearchTaskImpl.log.info("Loading " + experimentGroupName + " experiments...");
    // database hit: important that this be fast.
    Map<ExpressionExperimentDetailsValueObject, Collection<DifferentialExpressionAnalysisValueObject>> analyses = differentialExpressionAnalysisService.getAnalysesByExperiment(EntityUtils.getIds(experimentGroup));
    experiment: for (ExpressionExperimentDetailsValueObject bas : analyses.keySet()) {
        Collection<DifferentialExpressionAnalysisValueObject> analysesForExperiment = this.filterAnalyses(analyses.get(bas));
        if (analysesForExperiment.isEmpty()) {
            continue;
        }
        /*
             * There will often just be one analysis for the experiment. Exception would be when there is subsetting.
             */
        for (DifferentialExpressionAnalysisValueObject analysis : analysesForExperiment) {
            List<DiffExResultSetSummaryValueObject> resultSets = this.filterResultSets(analysis);
            usedResultSets.addAll(resultSets);
            if (resultSets.isEmpty()) {
                DifferentialExpressionSearchTaskImpl.log.info("No resultSets usable for " + bas.getId());
            }
            for (DiffExResultSetSummaryValueObject resultSet : resultSets) {
                // sanity check.
                assert resultSet.getNumberOfDiffExpressedProbes() != null;
                // interactions not okay
                assert resultSet.getExperimentalFactors().size() == 1;
                ExperimentalFactorValueObject factor = resultSet.getExperimentalFactors().iterator().next();
                Collection<FactorValueValueObject> factorValues = this.filterFactorValues(analysis, factor.getValues(), resultSet.getBaselineGroup().getId());
                if (factorValues.isEmpty()) {
                    /*
                         * This can only happen if there is just a baseline factorvalue. Even for one-sided tests //
                         * that // won't be the case.
                         */
                    DifferentialExpressionSearchTaskImpl.log.warn("Nothing usable for resultSet=" + resultSet.getResultSetId());
                    continue;
                }
                for (FactorValueValueObject factorValue : factorValues) {
                    Condition condition = searchResult.new Condition(bas, analysis, resultSet, factorValue);
                    condition.setExperimentGroupName(experimentGroupName);
                    /*
                         * SANITY CHECKS these fields should be filled in. If not, we are going to skip the results.
                         */
                    if (condition.getNumberDiffExpressedProbes() == -1) {
                        DifferentialExpressionSearchTaskImpl.log.warn(bas + ": Error: No hit list sizes for resultSet with ID=" + resultSet.getResultSetId());
                        continue;
                    }
                    if (condition.getNumberOfProbesOnArray() == null || condition.getNumberDiffExpressedProbes() == null) {
                        DifferentialExpressionSearchTaskImpl.log.error(bas + ": Error: Null counts for # diff ex probe or # probes on array, Skipping");
                        continue experiment;
                    } else if (condition.getNumberOfProbesOnArray() < condition.getNumberDiffExpressedProbes()) {
                        DifferentialExpressionSearchTaskImpl.log.error(bas + ": Error: More diff expressed probes than probes on array. Skipping.");
                        continue experiment;
                    }
                    searchResult.addCondition(condition);
                    i++;
                }
            }
        }
    }
    watch.stop();
    if (watch.getTotalTimeMillis() > 100) {
        // This does not include getting the actual diff ex results.
        DifferentialExpressionSearchTaskImpl.log.info("Get information on conditions/analyses for " + i + " factorValues: " + watch.getTotalTimeMillis() + "ms");
    }
    return usedResultSets;
}
Also used : FactorValueValueObject(ubic.gemma.model.expression.experiment.FactorValueValueObject) Condition(ubic.gemma.core.tasks.visualization.DifferentialExpressionGenesConditionsValueObject.Condition) ExpressionExperimentDetailsValueObject(ubic.gemma.model.expression.experiment.ExpressionExperimentDetailsValueObject) ExperimentalFactorValueObject(ubic.gemma.model.expression.experiment.ExperimentalFactorValueObject) StopWatch(org.springframework.util.StopWatch)

Aggregations

StopWatch (org.springframework.util.StopWatch)1 Condition (ubic.gemma.core.tasks.visualization.DifferentialExpressionGenesConditionsValueObject.Condition)1 ExperimentalFactorValueObject (ubic.gemma.model.expression.experiment.ExperimentalFactorValueObject)1 ExpressionExperimentDetailsValueObject (ubic.gemma.model.expression.experiment.ExpressionExperimentDetailsValueObject)1 FactorValueValueObject (ubic.gemma.model.expression.experiment.FactorValueValueObject)1