Search in sources :

Example 1 with DifferentialExpressionAnalysisConfig

use of ubic.gemma.core.analysis.expression.diff.DifferentialExpressionAnalysisConfig in project Gemma by PavlidisLab.

the class AclAdviceTest method testAnalysisAcl.

@Test
public void testAnalysisAcl() {
    /*
         * Create an analysis, add a result set, persist. Problem is: what if we do things in a funny order. Must call
         * update on the Analysis.
         */
    ExpressionExperiment ee = this.getTestPersistentCompleteExpressionExperiment(false);
    DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
    DifferentialExpressionAnalysis diffExpressionAnalysis = config.toAnalysis();
    ExpressionAnalysisResultSet resultSet = ExpressionAnalysisResultSet.Factory.newInstance();
    resultSet.setAnalysis(diffExpressionAnalysis);
    resultSet.setExperimentalFactors(ee.getExperimentalDesign().getExperimentalFactors());
    diffExpressionAnalysis.getResultSets().add(resultSet);
    diffExpressionAnalysis.setExperimentAnalyzed(ee);
    diffExpressionAnalysis = differentialExpressionAnalyzerService.persistAnalysis(ee, diffExpressionAnalysis, config);
    aclTestUtils.checkHasAcl(ee);
    aclTestUtils.checkHasAcl(diffExpressionAnalysis);
    aclTestUtils.checkLacksAcl(resultSet);
    aclTestUtils.checkHasAces(ee);
    aclTestUtils.checkLacksAces(diffExpressionAnalysis);
    aclTestUtils.checkHasAclParent(diffExpressionAnalysis, ee);
}
Also used : DifferentialExpressionAnalysisConfig(ubic.gemma.core.analysis.expression.diff.DifferentialExpressionAnalysisConfig) DifferentialExpressionAnalysis(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis) ExpressionAnalysisResultSet(ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet) BaseSpringContextTest(ubic.gemma.core.testing.BaseSpringContextTest) Test(org.junit.Test)

Example 2 with DifferentialExpressionAnalysisConfig

use of ubic.gemma.core.analysis.expression.diff.DifferentialExpressionAnalysisConfig in project Gemma by PavlidisLab.

the class SampleCoexpressionMatrixServiceImpl method regressMajorFactors.

/**
 * Regress out any 'major' factors, work with residuals only
 *
 * @param ee  the experiment to load the factors from
 * @param mat the double matrix of processed vectors to regress
 * @return regressed double matrix
 */
private ExpressionDataDoubleMatrix regressMajorFactors(ExpressionExperiment ee, ExpressionDataDoubleMatrix mat) {
    double importanceThreshold = 0.01;
    Set<ExperimentalFactor> importantFactors = svdService.getImportantFactors(ee, ee.getExperimentalDesign().getExperimentalFactors(), importanceThreshold);
    /* Remove 'batch' from important factors */
    ExperimentalFactor batch = null;
    for (ExperimentalFactor factor : importantFactors) {
        if (factor.getName().toLowerCase().equals("batch"))
            batch = factor;
    }
    if (batch != null) {
        importantFactors.remove(batch);
        SampleCoexpressionMatrixServiceImpl.log.info("Removed 'batch' from the list of significant factors.");
    }
    if (!importantFactors.isEmpty()) {
        SampleCoexpressionMatrixServiceImpl.log.info("Regressing out covariates");
        DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
        config.setFactorsToInclude(importantFactors);
        mat = lma.regressionResiduals(mat, config, true);
    }
    return mat;
}
Also used : DifferentialExpressionAnalysisConfig(ubic.gemma.core.analysis.expression.diff.DifferentialExpressionAnalysisConfig) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor)

Example 3 with DifferentialExpressionAnalysisConfig

use of ubic.gemma.core.analysis.expression.diff.DifferentialExpressionAnalysisConfig in project Gemma by PavlidisLab.

the class DifferentialExpressionAnalysisCli method processExperiment.

private void processExperiment(ExpressionExperiment ee) {
    Collection<DifferentialExpressionAnalysis> results;
    DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
    try {
        ee = this.eeService.thawLite(ee);
        if (delete) {
            AbstractCLI.log.info("Deleting any analyses for experiment=" + ee);
            differentialExpressionAnalyzerService.deleteAnalyses(ee);
            successObjects.add("Deleted analysis for: " + ee.toString());
            return;
        }
        Collection<ExperimentalFactor> experimentalFactors = ee.getExperimentalDesign().getExperimentalFactors();
        if (experimentalFactors.size() == 0) {
            if (this.expressionExperiments.size() == 1) {
                /*
                     * Only need to be noisy if this is the only ee. Batch processing should be less so.
                     */
                throw new RuntimeException("Experiment does not have an experimental design populated: " + ee.getShortName());
            }
            AbstractCLI.log.warn("Experiment does not have an experimental design populated: " + ee.getShortName());
            return;
        }
        Collection<ExperimentalFactor> factors = this.guessFactors(ee);
        if (factors.size() > 0) {
            /*
                 * Manual selection of factors
                 */
            ExperimentalFactor subsetFactor = this.getSubsetFactor(ee);
            AbstractCLI.log.info("Using " + factors.size() + " factors provided as arguments");
            if (subsetFactor != null) {
                if (factors.contains(subsetFactor)) {
                    throw new IllegalArgumentException("Subset factor cannot also be included as factor to analyze");
                }
                AbstractCLI.log.info("Subsetting by " + subsetFactor);
            }
            config.setAnalysisType(this.type);
            config.setFactorsToInclude(factors);
            config.setSubsetFactor(subsetFactor);
            config.setModerateStatistics(this.ebayes);
            config.setPersist(this.persist);
            boolean rnaSeq = super.eeService.isRNASeq(ee);
            config.setUseWeights(rnaSeq);
            /*
                 * Interactions included by default. It's actually only complicated if there is a subset factor.
                 */
            if (type == null && factors.size() == 2) {
                config.getInteractionsToInclude().add(factors);
            }
            results = this.differentialExpressionAnalyzerService.runDifferentialExpressionAnalyses(ee, config);
        } else {
            if (tryToCopyOld) {
                this.tryToRedoBasedOnOldAnalysis(ee);
            }
            Collection<ExperimentalFactor> factorsToUse = new HashSet<>();
            if (this.ignoreBatch) {
                for (ExperimentalFactor ef : experimentalFactors) {
                    if (!ExperimentalDesignUtils.isBatch(ef)) {
                        factorsToUse.add(ef);
                    }
                }
            } else {
                factorsToUse.addAll(experimentalFactors);
            }
            if (factorsToUse.isEmpty()) {
                throw new RuntimeException("No factors available for " + ee.getShortName());
            }
            if (factorsToUse.size() > 3) {
                if (!tryToCopyOld) {
                    throw new RuntimeException("Experiment has too many factors to run automatically: " + ee.getShortName() + "; try using the -redo flag to base it on an old analysis, or select factors manually");
                }
                results = this.tryToRedoBasedOnOldAnalysis(ee);
            } else {
                config.setFactorsToInclude(factorsToUse);
                config.setPersist(this.persist);
                config.setModerateStatistics(this.ebayes);
                if (factorsToUse.size() == 2) {
                    // include interactions by default
                    config.addInteractionToInclude(factorsToUse);
                }
                boolean rnaSeq = super.eeService.isRNASeq(ee);
                config.setUseWeights(rnaSeq);
                results = this.differentialExpressionAnalyzerService.runDifferentialExpressionAnalyses(ee, config);
            }
        }
        if (results == null) {
            throw new Exception("Failed to process differential expression for experiment " + ee.getShortName());
        }
        if (!this.persist) {
            AbstractCLI.log.info("Writing results to disk");
            for (DifferentialExpressionAnalysis r : results) {
                expressionDataFileService.writeDiffExArchiveFile(ee, r, config);
            }
        }
        successObjects.add(ee.toString());
    } catch (Exception e) {
        AbstractCLI.log.error("Error while processing " + ee + ": " + e.getMessage());
        ExceptionUtils.printRootCauseStackTrace(e);
        errorObjects.add(ee + ": " + e.getMessage());
    }
}
Also used : DifferentialExpressionAnalysisConfig(ubic.gemma.core.analysis.expression.diff.DifferentialExpressionAnalysisConfig) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) DifferentialExpressionAnalysis(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis) HashSet(java.util.HashSet)

Example 4 with DifferentialExpressionAnalysisConfig

use of ubic.gemma.core.analysis.expression.diff.DifferentialExpressionAnalysisConfig in project Gemma by PavlidisLab.

the class DifferentialExpressionAnalysisTaskImpl method doAnalysis.

private Collection<DifferentialExpressionAnalysis> doAnalysis() {
    ExpressionExperiment ee = taskCommand.getExpressionExperiment();
    if (taskCommand.getToRedo() != null) {
        log.info("Redoing analysis");
        ee = expressionExperimentService.thawLite(ee);
        return differentialExpressionAnalyzerService.redoAnalysis(ee, taskCommand.getToRedo(), true);
    }
    ee = expressionExperimentService.thawLite(ee);
    Collection<DifferentialExpressionAnalysis> diffAnalyses = differentialExpressionAnalysisService.getAnalyses(ee);
    if (!diffAnalyses.isEmpty()) {
        log.info("This experiment has some existing analyses; if they overlap with the new analysis they will be deleted after the run.");
    }
    Collection<DifferentialExpressionAnalysis> results;
    Collection<ExperimentalFactor> factors = taskCommand.getFactors();
    DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
    boolean rnaSeq = expressionExperimentService.isRNASeq(ee);
    config.setUseWeights(rnaSeq);
    config.setFactorsToInclude(factors);
    config.setSubsetFactor(taskCommand.getSubsetFactor());
    if (taskCommand.isIncludeInteractions() && factors.size() == 2) {
        /*
             * We should not include 'batch' in an interaction. But I don't want to enforce that here.
             */
        for (ExperimentalFactor ef : factors) {
            if (BatchInfoPopulationServiceImpl.isBatchFactor(ef)) {
                log.warn("Batch is included in the interaction!");
            }
        }
        // might get dropped.
        config.addInteractionToInclude(factors);
    }
    DifferentialExpressionAnalyzerServiceImpl.AnalysisType analyzer = analysisSelectionAndExecutionService.determineAnalysis(ee, config);
    if (analyzer == null) {
        throw new IllegalStateException("Data set cannot be analyzed");
    }
    config.setAnalysisType(analyzer);
    results = differentialExpressionAnalyzerService.runDifferentialExpressionAnalyses(ee, config);
    return results;
}
Also used : DifferentialExpressionAnalysisConfig(ubic.gemma.core.analysis.expression.diff.DifferentialExpressionAnalysisConfig) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) DifferentialExpressionAnalysis(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) DifferentialExpressionAnalyzerServiceImpl(ubic.gemma.core.analysis.expression.diff.DifferentialExpressionAnalyzerServiceImpl)

Aggregations

DifferentialExpressionAnalysisConfig (ubic.gemma.core.analysis.expression.diff.DifferentialExpressionAnalysisConfig)4 DifferentialExpressionAnalysis (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis)3 ExperimentalFactor (ubic.gemma.model.expression.experiment.ExperimentalFactor)3 HashSet (java.util.HashSet)1 Test (org.junit.Test)1 DifferentialExpressionAnalyzerServiceImpl (ubic.gemma.core.analysis.expression.diff.DifferentialExpressionAnalyzerServiceImpl)1 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)1 ExpressionAnalysisResultSet (ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet)1 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)1