Search in sources :

Example 6 with DifferentialExpressionAnalysisResult

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

the class TwoWayAnovaWithInteractionsAnalyzerTest method checkResults.

/**
 * @param resultSet the result set to check
 */
private void checkResults(ExpressionAnalysisResultSet resultSet) {
    Collection<ExperimentalFactor> factors = resultSet.getExperimentalFactors();
    for (DifferentialExpressionAnalysisResult r : resultSet.getResults()) {
        CompositeSequence probe = r.getProbe();
        Double pvalue = r.getPvalue();
        pvalue = pvalue == null ? Double.NaN : pvalue;
        Double qvalue = r.getCorrectedPvalue();
        assertNotNull(probe);
        if (factors.size() == 1) {
            ExperimentalFactor f = factors.iterator().next();
            if (f.equals(super.experimentalFactorA_Area)) {
                assertEquals(factorValueA2, resultSet.getBaselineGroup());
                switch(probe.getName()) {
                    case "probe_98":
                        assertEquals(0.8769, pvalue, 0.001);
                        assertNotNull(qvalue);
                        break;
                    case "probe_10":
                        assertEquals(5.158e-10, pvalue, 1e-12);
                        break;
                    case "probe_4":
                        assertEquals(0.0048, pvalue, 0.0001);
                        break;
                }
            } else {
                assertEquals(factorValueB2, resultSet.getBaselineGroup());
                if (probe.getName().equals("probe_98")) {
                    assertEquals(0.6888, pvalue, 0.001);
                } else if (probe.getName().equals("probe_10")) {
                    assertEquals(0.07970, pvalue, 0.00001);
                }
            }
        } else {
            assertEquals(null, resultSet.getBaselineGroup());
            switch(probe.getName()) {
                case "probe_98":
                    assertEquals(0.7893, pvalue, 0.001);
                    break;
                case "probe_10":
                    assertEquals(0.04514, pvalue, 0.00001);
                    break;
                case "probe_4":
                    assertEquals(Double.NaN, pvalue, 0.00001);
                    break;
            }
        }
    }
}
Also used : ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) DifferentialExpressionAnalysisResult(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysisResult) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence)

Example 7 with DifferentialExpressionAnalysisResult

use of ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysisResult 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 8 with DifferentialExpressionAnalysisResult

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

the class DatabaseViewGeneratorImpl method generateDifferentialExpressionView.

private void generateDifferentialExpressionView(Integer limit, Collection<ExpressionExperiment> experiments) throws IOException {
    DatabaseViewGeneratorImpl.log.info("Generating dataset diffex view");
    /*
         * Get handle to output file
         */
    File file = this.getViewFile(DatabaseViewGeneratorImpl.DATASET_DIFFEX_VIEW_BASENAME);
    DatabaseViewGeneratorImpl.log.info("Writing to " + file);
    try (Writer writer = new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(file)))) {
        /*
             * For each gene that is differentially expressed, print out a line per contrast
             */
        writer.write("GemmaDsId\tEEShortName\tGeneNCBIId\tGemmaGeneId\tFactor\tFactorURI\tBaseline\tContrasting\tDirection\n");
        int i = 0;
        for (ExpressionExperiment ee : experiments) {
            ee = expressionExperimentService.thawLite(ee);
            Collection<DifferentialExpressionAnalysis> results = differentialExpressionAnalysisService.getAnalyses(ee);
            if (results == null || results.isEmpty()) {
                DatabaseViewGeneratorImpl.log.warn("No differential expression results found for " + ee);
                continue;
            }
            // noinspection StatementWithEmptyBody // FIXME. Should probably skip for this purpose.
            if (results.size() > 1) {
            }
            DatabaseViewGeneratorImpl.log.info("Processing: " + ee.getShortName());
            for (DifferentialExpressionAnalysis analysis : results) {
                analysis = this.differentialExpressionAnalysisService.thawFully(analysis);
                for (ExpressionAnalysisResultSet ears : analysis.getResultSets()) {
                    // ears = differentialExpressionResultService.thawRawAndProcessed( ears );
                    FactorValue baselineGroup = ears.getBaselineGroup();
                    if (baselineGroup == null) {
                        // log.warn( "No baseline defined for " + ee ); // interaction
                        continue;
                    }
                    if (ExperimentalDesignUtils.isBatch(baselineGroup.getExperimentalFactor())) {
                        continue;
                    }
                    String baselineDescription = ExperimentalDesignUtils.prettyString(baselineGroup);
                    // Get the factor category name
                    StringBuilder factorName = new StringBuilder();
                    StringBuilder factorURI = new StringBuilder();
                    for (ExperimentalFactor ef : ears.getExperimentalFactors()) {
                        factorName.append(ef.getName()).append(",");
                        if (ef.getCategory() instanceof VocabCharacteristic) {
                            factorURI.append(ef.getCategory().getCategoryUri()).append(",");
                        }
                    }
                    factorName = new StringBuilder(StringUtils.removeEnd(factorName.toString(), ","));
                    factorURI = new StringBuilder(StringUtils.removeEnd(factorURI.toString(), ","));
                    if (ears.getResults() == null || ears.getResults().isEmpty()) {
                        DatabaseViewGeneratorImpl.log.warn("No  differential expression analysis results found for " + ee);
                        continue;
                    }
                    // Generate probe details
                    for (DifferentialExpressionAnalysisResult dear : ears.getResults()) {
                        if (dear == null) {
                            DatabaseViewGeneratorImpl.log.warn("Missing results for " + ee + " skipping to next. ");
                            continue;
                        }
                        if (dear.getCorrectedPvalue() == null || dear.getCorrectedPvalue() > DatabaseViewGeneratorImpl.THRESH_HOLD)
                            continue;
                        String formatted = this.formatDiffExResult(ee, dear, factorName.toString(), factorURI.toString(), baselineDescription);
                        if (StringUtils.isNotBlank(formatted))
                            writer.write(formatted);
                    }
                // dear loop
                }
            // ears loop
            }
            if (limit != null && (limit > 0 && ++i > limit))
                break;
        }
    // EE loop
    }
}
Also used : FactorValue(ubic.gemma.model.expression.experiment.FactorValue) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) DifferentialExpressionAnalysis(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis) VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic) DifferentialExpressionAnalysisResult(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysisResult) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) ExpressionAnalysisResultSet(ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet) GZIPOutputStream(java.util.zip.GZIPOutputStream)

Example 9 with DifferentialExpressionAnalysisResult

use of ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysisResult 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 10 with DifferentialExpressionAnalysisResult

use of ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysisResult 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)

Aggregations

DifferentialExpressionAnalysisResult (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysisResult)20 ExpressionAnalysisResultSet (ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet)14 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)12 ExperimentalFactor (ubic.gemma.model.expression.experiment.ExperimentalFactor)12 DifferentialExpressionAnalysis (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis)11 Test (org.junit.Test)9 ContrastResult (ubic.gemma.model.analysis.expression.diff.ContrastResult)7 AbstractGeoServiceTest (ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest)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 AlreadyExistsInSystemException (ubic.gemma.core.loader.util.AlreadyExistsInSystemException)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 List (java.util.List)1 GZIPOutputStream (java.util.zip.GZIPOutputStream)1 StopWatch (org.apache.commons.lang3.time.StopWatch)1 ByteArrayConverter (ubic.basecode.io.ByteArrayConverter)1 DoubleMatrixReader (ubic.basecode.io.reader.DoubleMatrixReader)1