Search in sources :

Example 1 with ExperimentalFactor

use of ubic.gemma.model.expression.experiment.ExperimentalFactor in project Gemma by PavlidisLab.

the class VisualizationValueObject method setUpFactorProfiles.

/**
 * Initialize the factor profiles.
 */
public void setUpFactorProfiles(LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>> layout) {
    if (layout == null) {
        VisualizationValueObject.log.warn("Null layout, ignoring");
        return;
    }
    Collection<ExperimentalFactor> efs = new HashSet<>();
    for (LinkedHashMap<ExperimentalFactor, Double> maps : layout.values()) {
        efs.addAll(maps.keySet());
    }
    this.factorProfiles = new ArrayList<>();
    for (ExperimentalFactor experimentalFactor : efs) {
        this.factorProfiles.add(new FactorProfile(experimentalFactor, layout));
    }
}
Also used : ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor)

Example 2 with ExperimentalFactor

use of ubic.gemma.model.expression.experiment.ExperimentalFactor 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 3 with ExperimentalFactor

use of ubic.gemma.model.expression.experiment.ExperimentalFactor 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 4 with ExperimentalFactor

use of ubic.gemma.model.expression.experiment.ExperimentalFactor in project Gemma by PavlidisLab.

the class AncovaTest method testAncovaCovariate.

/*
     * With a continuous covariate + two categorical
     */
@Test
public void testAncovaCovariate() {
    this.configureMocks();
    /*
         * Add a continuous factor
         */
    ExperimentalFactor experimentalFactorC = ExperimentalFactor.Factory.newInstance();
    experimentalFactorC.setName("confabulatiliationity");
    experimentalFactorC.setId(5399424551L);
    experimentalFactorC.setType(FactorType.CONTINUOUS);
    this.setupFactorValues(experimentalFactorC);
    expressionExperiment.getExperimentalDesign().getExperimentalFactors().add(experimentalFactorC);
    DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
    config.setFactorsToInclude(expressionExperiment.getExperimentalDesign().getExperimentalFactors());
    Collection<DifferentialExpressionAnalysis> expressionAnalyses = analyzer.run(expressionExperiment, config);
    DifferentialExpressionAnalysis expressionAnalysis = expressionAnalyses.iterator().next();
    assertNotNull(expressionAnalysis);
    Collection<ExpressionAnalysisResultSet> resultSets = expressionAnalysis.getResultSets();
    assertEquals(3, resultSets.size());
    for (ExpressionAnalysisResultSet resultSet : resultSets) {
        Collection<ExperimentalFactor> factors = resultSet.getExperimentalFactors();
        assertEquals(1, factors.size());
        for (DifferentialExpressionAnalysisResult r : resultSet.getResults()) {
            CompositeSequence probe = r.getProbe();
            Double pvalue = r.getPvalue();
            assertNotNull(probe);
            // log.debug( "probe: " + probe + "; Factor="
            // + resultSet.getExperimentalFactors().iterator().next().getName() + "; p-value: " + pvalue
            // + "; T=" + stat );
            ExperimentalFactor f = factors.iterator().next();
            if (f.equals(super.experimentalFactorA_Area)) {
                switch(probe.getName()) {
                    case "probe_98":
                        assertEquals(0.8673, pvalue, 0.001);
                        break;
                    case "probe_10":
                        assertEquals(4.062e-09, pvalue, 1e-10);
                        break;
                    case "probe_4":
                        // too few samples
                        assertEquals(null, pvalue);
                        // assertEquals( null, stat );
                        break;
                }
            } else if (f.equals(super.experimentalFactorB)) {
                if (probe.getName().equals("probe_98")) {
                    assertEquals(0.6665, pvalue, 0.001);
                } else if (probe.getName().equals("probe_10")) {
                    assertEquals(0.2356, pvalue, 0.001);
                }
            } else {
                // our new one.
                if (probe.getName().equals("probe_98")) {
                    assertEquals(0.4977, pvalue, 0.001);
                } else if (probe.getName().equals("probe_10")) {
                    assertEquals(0.57347, 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) Test(org.junit.Test)

Example 5 with ExperimentalFactor

use of ubic.gemma.model.expression.experiment.ExperimentalFactor 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)

Aggregations

ExperimentalFactor (ubic.gemma.model.expression.experiment.ExperimentalFactor)88 Test (org.junit.Test)31 FactorValue (ubic.gemma.model.expression.experiment.FactorValue)30 DifferentialExpressionAnalysis (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis)26 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)22 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)18 HashSet (java.util.HashSet)17 AbstractGeoServiceTest (ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest)17 ExpressionAnalysisResultSet (ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet)16 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)14 DifferentialExpressionAnalysisResult (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysisResult)12 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)11 GeoDomainObjectGeneratorLocal (ubic.gemma.core.loader.expression.geo.GeoDomainObjectGeneratorLocal)10 AlreadyExistsInSystemException (ubic.gemma.core.loader.util.AlreadyExistsInSystemException)10 Before (org.junit.Before)8 Collection (java.util.Collection)7 ContrastResult (ubic.gemma.model.analysis.expression.diff.ContrastResult)6 AnalysisType (ubic.gemma.core.analysis.expression.diff.DifferentialExpressionAnalyzerServiceImpl.AnalysisType)5 ExperimentalFactorValueObject (ubic.gemma.model.expression.experiment.ExperimentalFactorValueObject)5 InputStream (java.io.InputStream)4