Search in sources :

Example 1 with ContrastResult

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

the class AncovaTest method testAncovaWithInteraction.

/*
     * Two factors with interactions.
     */
@Test
public void testAncovaWithInteraction() {
    this.configureMocks();
    DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
    config.getFactorsToInclude().add(this.experimentalFactorA_Area);
    config.getFactorsToInclude().add(this.experimentalFactorB);
    config.getInteractionsToInclude().add(config.getFactorsToInclude());
    Collection<DifferentialExpressionAnalysis> expressionAnalyses = analyzer.run(expressionExperiment, config);
    DifferentialExpressionAnalysis expressionAnalysis = expressionAnalyses.iterator().next();
    assertNotNull(expressionAnalysis);
    Collection<ExpressionAnalysisResultSet> resultSets = expressionAnalysis.getResultSets();
    assertEquals(3, resultSets.size());
    boolean foundInteractions = false;
    boolean foundContrast = false;
    for (ExpressionAnalysisResultSet resultSet : resultSets) {
        Collection<ExperimentalFactor> factors = resultSet.getExperimentalFactors();
        for (DifferentialExpressionAnalysisResult r : resultSet.getResults()) {
            CompositeSequence probe = r.getProbe();
            Double pvalue = r.getPvalue();
            assertNotNull(probe);
            Collection<ContrastResult> contrasts = r.getContrasts();
            Double stat;
            if (contrasts.isEmpty()) {
                continue;
            }
            stat = contrasts.iterator().next().getTstat();
            if (factors.size() == 2) {
                // interaction
                foundInteractions = true;
                switch(probe.getName()) {
                    case "probe_98":
                        assertEquals(0.7893, pvalue, 0.001);
                        break;
                    case "probe_10":
                        assertEquals(0.04514, pvalue, 0.0001);
                        break;
                    case "probe_4":
                        assertEquals(null, pvalue);
                        break;
                }
            } else {
                ExperimentalFactor f = factors.iterator().next();
                assertNotNull(f);
                if (f.equals(super.experimentalFactorA_Area)) {
                    switch(probe.getName()) {
                        case "probe_98":
                            assertEquals(0.8769, pvalue, 0.001);
                            break;
                        case "probe_10":
                            assertEquals(5.158e-10, pvalue, 1e-12);
                            break;
                        case "probe_4":
                            assertEquals(0.0048, pvalue, 0.0001);
                            assertNotNull(stat);
                            assertEquals(-125.746, stat, 0.001);
                            break;
                        case "probe_0":
                            assertEquals(1, r.getContrasts().size());
                            ContrastResult contrast = r.getContrasts().iterator().next();
                            assertEquals(super.factorValueA1, contrast.getFactorValue());
                            assertEquals(-202.5587, contrast.getLogFoldChange(), 0.001);
                            foundContrast = true;
                            break;
                    }
                } else {
                    if (probe.getName().equals("probe_98")) {
                        assertEquals(0.6888, pvalue, 0.001);
                    } else if (probe.getName().equals("probe_10")) {
                        assertEquals(0.07970, pvalue, 0.001);
                    }
                }
            }
        }
    }
    assertTrue(foundInteractions);
    assertTrue(foundContrast);
}
Also used : ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) DifferentialExpressionAnalysis(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis) DifferentialExpressionAnalysisResult(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysisResult) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) ExpressionAnalysisResultSet(ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet) ContrastResult(ubic.gemma.model.analysis.expression.diff.ContrastResult) Test(org.junit.Test)

Example 2 with ContrastResult

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

the class AncovaTest method testAncovaTriLevel.

/*
     * Two fixed-level parameters, one of which has three levels
     */
@Test
public void testAncovaTriLevel() {
    this.configureMocks();
    /*
         * Add a factor with three levels (same one used in onewayanovaanalyzertest)
         */
    ExperimentalFactor experimentalFactorC = ExperimentalFactor.Factory.newInstance();
    experimentalFactorC.setName("threeLevFactor");
    experimentalFactorC.setId(5003L);
    experimentalFactorC.setType(FactorType.CATEGORICAL);
    expressionExperiment.getExperimentalDesign().getExperimentalFactors().add(experimentalFactorC);
    FactorValue fcbase = null;
    for (int i = 1; i <= 3; i++) {
        FactorValue factorValueC = FactorValue.Factory.newInstance();
        factorValueC.setId(2000L + i);
        if (i == 3) {
            factorValueC.setValue("control_group");
            fcbase = factorValueC;
        } else {
            factorValueC.setValue(i + "_group");
        }
        factorValueC.setExperimentalFactor(experimentalFactorC);
        experimentalFactorC.getFactorValues().add(factorValueC);
    }
    List<FactorValue> facV = new ArrayList<>(experimentalFactorC.getFactorValues());
    for (int i = 0; i < 8; i++) {
        super.biomaterials.get(i).getFactorValues().add(facV.get(i % 3));
    }
    List<ExperimentalFactor> factors = new ArrayList<>();
    factors.add(experimentalFactorA_Area);
    factors.add(experimentalFactorC);
    DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
    config.setFactorsToInclude(factors);
    Collection<DifferentialExpressionAnalysis> expressionAnalyses = analyzer.run(expressionExperiment, config);
    DifferentialExpressionAnalysis expressionAnalysis = expressionAnalyses.iterator().next();
    assertNotNull(expressionAnalysis);
    Collection<ExpressionAnalysisResultSet> resultSets = expressionAnalysis.getResultSets();
    assertEquals(2, resultSets.size());
    boolean found14 = false;
    boolean found198 = false;
    boolean found3 = false;
    boolean found4 = false;
    for (ExpressionAnalysisResultSet resultSet : resultSets) {
        assertEquals(1, resultSet.getExperimentalFactors().size());
        log.info(resultSet.getBaselineGroup());
        assertTrue(resultSet.getBaselineGroup().equals(factorValueA2) || resultSet.getBaselineGroup().equals(fcbase));
        ExperimentalFactor f = resultSet.getExperimentalFactors().iterator().next();
        for (DifferentialExpressionAnalysisResult r : resultSet.getResults()) {
            CompositeSequence probe = r.getProbe();
            Double pvalue = r.getPvalue();
            if (f.equals(super.experimentalFactorA_Area)) {
                if (probe.getName().equals("probe_98")) {
                    assertEquals(0.8060, pvalue, 0.001);
                    found198 = true;
                }
            } else if (probe.getName().equals("probe_10")) {
                assertEquals(0.9088, pvalue, 0.001);
                found3 = true;
            }
            Collection<ContrastResult> contrasts = r.getContrasts();
            Double stat;
            if (contrasts.isEmpty()) {
                continue;
            }
            stat = contrasts.iterator().next().getTstat();
            assertNotNull(probe);
            if (stat == null)
                continue;
            if (f.equals(super.experimentalFactorA_Area)) {
                if (probe.getName().equals("probe_10")) {
                    assertEquals(9.215e-09, pvalue, 1e-11);
                    assertEquals(-152.812, stat, 0.001);
                } else if (probe.getName().equals("probe_4")) {
                    assertEquals(0.006278, pvalue, 0.0001);
                    assertEquals(-95.118, stat, 0.001);
                    found14 = true;
                }
            } else {
                if (contrasts.size() == 2) {
                    found4 = true;
                }
                if (probe.getName().equals("probe_98")) {
                    assertEquals(0.2171, pvalue, 0.001);
                }
            }
        }
    }
    assertTrue("Didn't find results", found14 && found198 && found3);
    assertTrue("Didn't find the right number of contrasts", found4);
}
Also used : FactorValue(ubic.gemma.model.expression.experiment.FactorValue) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) ArrayList(java.util.ArrayList) DifferentialExpressionAnalysis(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis) DifferentialExpressionAnalysisResult(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysisResult) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) ExpressionAnalysisResultSet(ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet) ContrastResult(ubic.gemma.model.analysis.expression.diff.ContrastResult) Test(org.junit.Test)

Example 3 with ContrastResult

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

the class AncovaTest method testAncovaTwoway.

/*
     * Two fixed-level parameters
     */
@Test
public void testAncovaTwoway() {
    this.configureMocks();
    DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
    config.setFactorsToInclude(super.experimentalFactors);
    Collection<DifferentialExpressionAnalysis> expressionAnalyses = analyzer.run(expressionExperiment, config);
    DifferentialExpressionAnalysis expressionAnalysis = expressionAnalyses.iterator().next();
    assertNotNull(expressionAnalysis);
    Collection<ExpressionAnalysisResultSet> resultSets = expressionAnalysis.getResultSets();
    assertEquals(2, resultSets.size());
    for (ExpressionAnalysisResultSet resultSet : resultSets) {
        Collection<ExperimentalFactor> factors = resultSet.getExperimentalFactors();
        assertEquals(1, factors.size());
        for (DifferentialExpressionAnalysisResult probeAnalysisResult : resultSet.getResults()) {
            CompositeSequence probe = probeAnalysisResult.getProbe();
            Double pvalue = probeAnalysisResult.getPvalue();
            Collection<ContrastResult> contrasts = probeAnalysisResult.getContrasts();
            Double stat;
            if (contrasts.isEmpty()) {
                continue;
            }
            stat = contrasts.iterator().next().getTstat();
            assertNotNull(probe);
            // log.debug( "probe: " + probe + "; p-value: " + pvalue + "; T=" + stat );
            ExperimentalFactor f = factors.iterator().next();
            if (f.equals(super.experimentalFactorA_Area)) {
                switch(probe.getName()) {
                    case "probe_98":
                        assertEquals(0.8572, pvalue, 0.001);
                        break;
                    case "probe_10":
                        assertEquals(4.69e-11, pvalue, 1e-12);
                        break;
                    case "probe_4":
                        assertEquals(0.0048, pvalue, 0.0001);
                        assertNotNull(stat);
                        assertEquals(-125.746, stat, 0.001);
                        // factor1a
                        assertEquals(0.00506, contrasts.iterator().next().getPvalue(), 0.0001);
                        break;
                }
            } else {
                if (probe.getName().equals("probe_98")) {
                    assertEquals(0.6417, pvalue, 0.001);
                } else if (probe.getName().equals("probe_10")) {
                    assertEquals(0.196, pvalue, 0.001);
                }
            }
        }
    }
}
Also used : ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) DifferentialExpressionAnalysis(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis) DifferentialExpressionAnalysisResult(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysisResult) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) ExpressionAnalysisResultSet(ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet) ContrastResult(ubic.gemma.model.analysis.expression.diff.ContrastResult) Test(org.junit.Test)

Example 4 with ContrastResult

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

the class TwoWayAnovaWithoutInteractionsAnalyzerTest method checkResults.

/**
 * @param resultSet the result set to check
 */
private void checkResults(ExpressionAnalysisResultSet resultSet) {
    Collection<ExperimentalFactor> factors = resultSet.getExperimentalFactors();
    assertEquals("Should not have an interaction term", 1, factors.size());
    ExperimentalFactor f = factors.iterator().next();
    boolean found = false;
    for (DifferentialExpressionAnalysisResult r : resultSet.getResults()) {
        CompositeSequence probe = r.getProbe();
        Double pvalue = r.getPvalue();
        if (f.equals(super.experimentalFactorB) && probe.getName().equals("probe_1")) {
            assertEquals(0.501040, pvalue, 0.001);
            found = true;
        }
        Collection<ContrastResult> contrasts = r.getContrasts();
        Double stat;
        if (contrasts.isEmpty()) {
            continue;
        }
        stat = contrasts.iterator().next().getTstat();
        assertNotNull(probe);
        if (f.equals(super.experimentalFactorA_Area)) {
            assertEquals(factorValueA2, resultSet.getBaselineGroup());
            switch(probe.getName()) {
                case // id=1001
                "probe_1":
                    assertEquals(0.001814, pvalue, 0.00001);
                    assertNotNull(stat);
                    assertEquals(-287.061, stat, 0.001);
                    found = true;
                    break;
                case // id 1097
                "probe_97":
                    assertEquals(0.3546, pvalue, 0.001);
                    break;
                case "probe_0":
                    assertEquals(1.36e-12, pvalue, 1e-10);
                    assertNotNull(stat);
                    assertEquals(-425.3, stat, 0.1);
                    break;
            }
        } else {
            assertEquals(factorValueB2, resultSet.getBaselineGroup());
            if (probe.getName().equals("probe_97")) {
                assertEquals(0.4449, pvalue, 0.001);
            }
        }
    }
    assertTrue("Did not find expected results for probe_1", found);
}
Also used : ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) DifferentialExpressionAnalysisResult(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysisResult) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) ContrastResult(ubic.gemma.model.analysis.expression.diff.ContrastResult)

Example 5 with ContrastResult

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

the class DatabaseViewGeneratorImpl method formatDiffExResult.

private String formatDiffExResult(ExpressionExperiment ee, DifferentialExpressionAnalysisResult probeAnalysisResult, String factorName, String factorURI, String baselineDescription) {
    CompositeSequence cs = probeAnalysisResult.getProbe();
    Collection<Gene> genes = compositeSequenceService.getGenes(cs);
    if (genes.isEmpty() || genes.size() > 1) {
        return null;
    }
    Gene g = genes.iterator().next();
    if (g.getNcbiGeneId() == null)
        return null;
    Collection<ContrastResult> contrasts = probeAnalysisResult.getContrasts();
    StringBuilder buf = new StringBuilder();
    for (ContrastResult cr : contrasts) {
        FactorValue factorValue = cr.getFactorValue();
        String direction = cr.getLogFoldChange() < 0 ? "-" : "+";
        String factorValueDescription = ExperimentalDesignUtils.prettyString(factorValue);
        buf.append(String.format("%d\t%s\t%s\t%d\t%s\t%s\t%s\t%s\t%s\n", ee.getId(), ee.getShortName(), g.getNcbiGeneId().toString(), g.getId(), factorName, factorURI, baselineDescription, factorValueDescription, direction));
    }
    return buf.toString();
}
Also used : FactorValue(ubic.gemma.model.expression.experiment.FactorValue) Gene(ubic.gemma.model.genome.Gene) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) ContrastResult(ubic.gemma.model.analysis.expression.diff.ContrastResult)

Aggregations

ContrastResult (ubic.gemma.model.analysis.expression.diff.ContrastResult)8 DifferentialExpressionAnalysisResult (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysisResult)7 ExperimentalFactor (ubic.gemma.model.expression.experiment.ExperimentalFactor)6 Test (org.junit.Test)5 DifferentialExpressionAnalysis (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis)5 ExpressionAnalysisResultSet (ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet)5 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)5 AbstractGeoServiceTest (ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest)2 FactorValue (ubic.gemma.model.expression.experiment.FactorValue)2 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 DoubleMatrixReader (ubic.basecode.io.reader.DoubleMatrixReader)1 GeoDomainObjectGenerator (ubic.gemma.core.loader.expression.geo.GeoDomainObjectGenerator)1 AlreadyExistsInSystemException (ubic.gemma.core.loader.util.AlreadyExistsInSystemException)1 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)1 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)1 DoubleVectorValueObject (ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject)1 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)1 Gene (ubic.gemma.model.genome.Gene)1