Search in sources :

Example 11 with ExpressionAnalysisResultSet

use of ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet in project Gemma by PavlidisLab.

the class LowVarianceDataTest method checkResults.

public void checkResults(DifferentialExpressionAnalysis analysis) {
    Collection<ExpressionAnalysisResultSet> resultSets = analysis.getResultSets();
    assertEquals(2, resultSets.size());
    boolean found1 = false;
    for (ExpressionAnalysisResultSet rs : resultSets) {
        Collection<DifferentialExpressionAnalysisResult> results = rs.getResults();
        for (DifferentialExpressionAnalysisResult r : results) {
            CompositeSequence probe = r.getProbe();
            switch(probe.getName()) {
                case "1552338_at":
                    fail("Should not have found a result for constant probe: 1552338_at");
                    break;
                case "1552337_s_at":
                    fail("Should not have found a result for constant probe: 1552337_s_at");
                    break;
                case "1552391_at":
                    fail("Should not have found a result for constant probe: 1552391_at");
                    break;
                default:
                    found1 = true;
                    break;
            }
        }
    }
    assertTrue(found1);
}
Also used : DifferentialExpressionAnalysisResult(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysisResult) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) ExpressionAnalysisResultSet(ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet)

Example 12 with ExpressionAnalysisResultSet

use of ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet in project Gemma by PavlidisLab.

the class TwoWayAnovaWithInteractionTest2 method checkResults.

public void checkResults(DifferentialExpressionAnalysis analysis) {
    Collection<ExpressionAnalysisResultSet> resultSets = analysis.getResultSets();
    assertEquals(3, resultSets.size());
    boolean found1 = false, found2 = false, found3 = false, found4 = false;
    for (ExpressionAnalysisResultSet rs : resultSets) {
        boolean interaction = false;
        boolean sexFactor = false;
        Collection<DifferentialExpressionAnalysisResult> results = rs.getResults();
        if (rs.getExperimentalFactors().size() == 1) {
            ExperimentalFactor factor = rs.getExperimentalFactors().iterator().next();
            sexFactor = factor.getName().equals("Sex");
        } else {
            interaction = true;
        }
        assertEquals(8, results.size());
        /*
             * Test values here are computed in R, using anova(lm(unlist(expData["205969_at",])~Treatment*Sex )) etc.
             */
        for (DifferentialExpressionAnalysisResult r : results) {
            CompositeSequence probe = r.getProbe();
            Double pvalue = r.getPvalue();
            switch(probe.getName()) {
                case "205969_at":
                    if (sexFactor) {
                        found1 = true;
                        assertEquals(0.3333, pvalue, 0.001);
                    } else if (interaction) {
                        found2 = true;
                        assertEquals(0.8480, pvalue, 0.001);
                    } else {
                        found3 = true;
                        assertEquals(0.1323, pvalue, 0.001);
                    }
                    break;
                case "217757_at":
                    if (interaction) {
                        found4 = true;
                        assertEquals(0.7621, pvalue, 0.001);
                    }
                    break;
                case "constant":
                    fail("Should not have found a result for constant probe");
                    break;
            }
        }
    }
    assertTrue(found1 && found2 && found3 && found4);
}
Also used : ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) DifferentialExpressionAnalysisResult(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysisResult) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) ExpressionAnalysisResultSet(ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet)

Example 13 with ExpressionAnalysisResultSet

use of ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet in project Gemma by PavlidisLab.

the class TwoWayAnovaWithInteractionTest2 method test.

/*
     * NOTE I added a constant probe to this data after I set this up.
     *
     * <pre>
     * expMatFile &lt;- "GSE8441_expmat_8probes.txt"
     * expDesignFile &lt;- "606_GSE8441_expdesign.data.txt"
     * expMat &lt;- log2(read.table(expMatFile, header = TRUE, row.names = 1, sep = "\t", quote=""))
     * expDesign &lt;- read.table(expDesignFile, header = TRUE, row.names = 1, sep = "\t", quote="")
     *
     * expData &lt;- expMat[rownames(expDesign)]
     *
     * names(expData) == row.names(expDesign)
     * attach(expDesign)
     * lf&lt;-lm(unlist(expData["217757_at",])~Treatment*Sex )
     * summary(lf)
     * anova(lf)
     *
     * summary(lm(unlist(expData["202851_at",])~Treatment*Sex ))
     * anova(lm(unlist(expData["202851_at",])~Treatment*Sex ))
     *
     * # etc.
     * </pre>
     */
@Test
public void test() {
    AnalysisType aa = analysisService.determineAnalysis(ee, ee.getExperimentalDesign().getExperimentalFactors(), null, true);
    assertEquals(AnalysisType.TWO_WAY_ANOVA_WITH_INTERACTION, aa);
    DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
    Collection<ExperimentalFactor> factors = ee.getExperimentalDesign().getExperimentalFactors();
    assertEquals(2, factors.size());
    config.setAnalysisType(aa);
    config.setFactorsToInclude(factors);
    config.getInteractionsToInclude().add(factors);
    analyzer = this.getBean(DiffExAnalyzer.class);
    Collection<DifferentialExpressionAnalysis> result = analyzer.run(ee, config);
    assertEquals(1, result.size());
    DifferentialExpressionAnalysis analysis = result.iterator().next();
    this.checkResults(analysis);
    Collection<DifferentialExpressionAnalysis> persistent = differentialExpressionAnalyzerService.runDifferentialExpressionAnalyses(ee, config);
    DifferentialExpressionAnalysis refetched = differentialExpressionAnalysisService.load(persistent.iterator().next().getId());
    differentialExpressionAnalysisService.thaw(refetched);
    for (ExpressionAnalysisResultSet ears : refetched.getResultSets()) {
        differentialExpressionResultService.thaw(ears);
    }
    this.checkResults(refetched);
    differentialExpressionAnalyzerService.redoAnalysis(ee, refetched, true);
}
Also used : AnalysisType(ubic.gemma.core.analysis.expression.diff.DifferentialExpressionAnalyzerServiceImpl.AnalysisType) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) 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 14 with ExpressionAnalysisResultSet

use of ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet in project Gemma by PavlidisLab.

the class DifferentialExpressionAnalyzerServiceImpl method copyConfig.

private DifferentialExpressionAnalysisConfig copyConfig(DifferentialExpressionAnalysis copyMe) {
    DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
    if (copyMe.getSubsetFactorValue() != null) {
        config.setSubsetFactor(copyMe.getSubsetFactorValue().getExperimentalFactor());
    }
    Collection<ExpressionAnalysisResultSet> resultSets = copyMe.getResultSets();
    Collection<ExperimentalFactor> factorsFromOldExp = new HashSet<>();
    for (ExpressionAnalysisResultSet rs : resultSets) {
        Collection<ExperimentalFactor> oldfactors = rs.getExperimentalFactors();
        factorsFromOldExp.addAll(oldfactors);
        /*
             * If we included the interaction before, include it again.
             */
        if (oldfactors.size() == 2) {
            DifferentialExpressionAnalyzerServiceImpl.log.info("Including interaction term");
            config.getInteractionsToInclude().add(oldfactors);
        }
    }
    if (factorsFromOldExp.isEmpty()) {
        throw new IllegalStateException("Old analysis didn't have any factors");
    }
    config.getFactorsToInclude().addAll(factorsFromOldExp);
    return config;
}
Also used : ExpressionAnalysisResultSet(ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet)

Example 15 with ExpressionAnalysisResultSet

use of ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet in project Gemma by PavlidisLab.

the class DifferentialExpressionAnalyzerServiceImpl method extendResultSets.

private void extendResultSets(Collection<DifferentialExpressionAnalysis> results, Collection<ExpressionAnalysisResultSet> toUpdateResultSets) {
    for (DifferentialExpressionAnalysis a : results) {
        boolean found = false;
        for (ExpressionAnalysisResultSet oldrs : toUpdateResultSets) {
            assert oldrs.getId() != null;
            this.differentialExpressionResultService.thaw(oldrs);
            for (ExpressionAnalysisResultSet temprs : a.getResultSets()) {
                /*
                     * Compare the config
                     */
                if (this.configsAreEqual(temprs, oldrs)) {
                    found = true;
                    this.extendResultSet(oldrs, temprs);
                    break;
                }
            }
            if (!found)
                throw new IllegalStateException("Failed to find a matching existing result set for " + oldrs);
        }
    }
}
Also used : DifferentialExpressionAnalysis(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis) ExpressionAnalysisResultSet(ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet)

Aggregations

ExpressionAnalysisResultSet (ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet)30 DifferentialExpressionAnalysis (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis)21 Test (org.junit.Test)17 ExperimentalFactor (ubic.gemma.model.expression.experiment.ExperimentalFactor)16 DifferentialExpressionAnalysisResult (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysisResult)14 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)8 AbstractGeoServiceTest (ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest)5 ContrastResult (ubic.gemma.model.analysis.expression.diff.ContrastResult)5 StopWatch (org.apache.commons.lang3.time.StopWatch)4 HashSet (java.util.HashSet)3 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)3 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)3 FactorValue (ubic.gemma.model.expression.experiment.FactorValue)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 DoubleMatrixReader (ubic.basecode.io.reader.DoubleMatrixReader)2 AlreadyExistsInSystemException (ubic.gemma.core.loader.util.AlreadyExistsInSystemException)2 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)2 DoubleVectorValueObject (ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject)2 File (java.io.File)1