Search in sources :

Example 6 with CompositeSequence

use of ubic.gemma.model.expression.designElement.CompositeSequence 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 7 with CompositeSequence

use of ubic.gemma.model.expression.designElement.CompositeSequence 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 8 with CompositeSequence

use of ubic.gemma.model.expression.designElement.CompositeSequence 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 9 with CompositeSequence

use of ubic.gemma.model.expression.designElement.CompositeSequence in project Gemma by PavlidisLab.

the class DiffExMetaAnalyzerServiceTest method extraTests1.

private void extraTests1(ExpressionExperiment ds1) {
    Collection<Gene> geneCollection = geneService.findByOfficialSymbol("ACTA2");
    assertTrue(!geneCollection.isEmpty());
    Gene g = geneCollection.iterator().next();
    assertNotNull(g);
    long count = geneService.getCompositeSequenceCountById(g.getId());
    assertTrue(count != 0);
    Collection<CompositeSequence> compSequences = geneService.getCompositeSequencesById(g.getId());
    assertTrue(compSequences.size() != 0);
    Collection<CompositeSequence> collection = compositeSequenceService.findByGene(g);
    assertEquals(1, collection.size());
    ArrayDesign ad = experimentService.getArrayDesignsUsed(ds1).iterator().next();
    collection = compositeSequenceService.findByGene(g, ad);
    assertEquals(1, collection.size());
    Collection<CompositeSequence> css = compositeSequenceService.findByName("200974_at");
    assertTrue(!css.isEmpty());
    CompositeSequence cs = css.iterator().next();
    Collection<Gene> genes = compositeSequenceService.getGenes(cs);
    assertEquals(1, genes.size());
    assertEquals(g, genes.iterator().next());
    tableMaintenanceUtil.disableEmail();
    tableMaintenanceUtil.updateGene2CsEntries();
    Map<CompositeSequence, Collection<Gene>> gm = compositeSequenceService.getGenes(css);
    assertEquals(1, gm.size());
    assertEquals(g, gm.values().iterator().next().iterator().next());
}
Also used : Gene(ubic.gemma.model.genome.Gene) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence)

Example 10 with CompositeSequence

use of ubic.gemma.model.expression.designElement.CompositeSequence in project Gemma by PavlidisLab.

the class OneWayAnovaAnalyzerTest method testOnewayAnovaB.

@Test
public void testOnewayAnovaB() throws Exception {
    if (!connected) {
        log.warn("Could not establish R connection.  Skipping test ...");
        return;
    }
    super.configureTestDataForOneWayAnova();
    this.configureMocks();
    /*
         * Add a factor with three levels
         */
    ExperimentalFactor experimentalFactorC = ExperimentalFactor.Factory.newInstance();
    experimentalFactorC.setName("groupash");
    experimentalFactorC.setId(5399424551L);
    experimentalFactorC.setType(FactorType.CATEGORICAL);
    expressionExperiment.getExperimentalDesign().getExperimentalFactors().add(experimentalFactorC);
    FactorValue controlGroup = null;
    for (int i = 1; i <= 3; i++) {
        FactorValue f = FactorValue.Factory.newInstance();
        f.setId(2000L + i);
        if (i != 2) {
            f.setValue(i + "_group");
        } else {
            f.setValue("control_group");
            controlGroup = f;
        }
        f.setExperimentalFactor(experimentalFactorC);
        experimentalFactorC.getFactorValues().add(f);
    }
    List<FactorValue> facV = new ArrayList<>(experimentalFactorC.getFactorValues());
    for (int i = 0; i < 8; i++) {
        super.biomaterials.get(i).getFactorValues().add(facV.get(i % 3));
    }
    Collection<ExperimentalFactor> factors = new HashSet<>();
    factors.add(experimentalFactorC);
    DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
    config.setFactorsToInclude(factors);
    Collection<DifferentialExpressionAnalysis> expressionAnalyses = analyzer.run(expressionExperiment, config);
    DifferentialExpressionAnalysis expressionAnalysis = expressionAnalyses.iterator().next();
    Collection<ExpressionAnalysisResultSet> resultSets = expressionAnalysis.getResultSets();
    ExpressionAnalysisResultSet resultSet = resultSets.iterator().next();
    int numResults = resultSet.getResults().size();
    assertEquals(100, numResults);
    assertEquals(controlGroup, resultSet.getBaselineGroup());
    factors = resultSet.getExperimentalFactors();
    assertEquals(1, factors.size());
    for (DifferentialExpressionAnalysisResult r : resultSet.getResults()) {
        CompositeSequence probe = r.getProbe();
        Double pvalue = r.getPvalue();
        // if ( pvalue != null ) assertNotNull( stat );
        assertNotNull(probe);
        switch(probe.getName()) {
            case "probe_98":
                assertEquals(0.1604, pvalue, 0.001);
                break;
            case "probe_10":
                assertEquals(0.8014, pvalue, 0.0001);
                break;
            case "probe_4":
                assertEquals(0.6531, pvalue, 0.0001);
                break;
        }
    }
}
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) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)206 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)43 BioSequence (ubic.gemma.model.genome.biosequence.BioSequence)40 Gene (ubic.gemma.model.genome.Gene)32 Test (org.junit.Test)30 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)19 ExpressionDataDoubleMatrix (ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix)18 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)18 DesignElementDataVector (ubic.gemma.model.expression.bioAssayData.DesignElementDataVector)18 RawExpressionDataVector (ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector)18 StopWatch (org.apache.commons.lang3.time.StopWatch)17 HashSet (java.util.HashSet)15 BioAssayDimension (ubic.gemma.model.expression.bioAssayData.BioAssayDimension)15 CompositeSequenceValueObject (ubic.gemma.model.expression.designElement.CompositeSequenceValueObject)15 ArrayList (java.util.ArrayList)14 QuantitationType (ubic.gemma.model.common.quantitationtype.QuantitationType)14 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)13 Taxon (ubic.gemma.model.genome.Taxon)12 Collection (java.util.Collection)11 ByteArrayConverter (ubic.basecode.io.ByteArrayConverter)11