Search in sources :

Example 6 with ExpressionAnalysisResultSet

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

Example 7 with ExpressionAnalysisResultSet

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

the class AclAdviceTest method testAnalysisAcl.

@Test
public void testAnalysisAcl() {
    /*
         * Create an analysis, add a result set, persist. Problem is: what if we do things in a funny order. Must call
         * update on the Analysis.
         */
    ExpressionExperiment ee = this.getTestPersistentCompleteExpressionExperiment(false);
    DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
    DifferentialExpressionAnalysis diffExpressionAnalysis = config.toAnalysis();
    ExpressionAnalysisResultSet resultSet = ExpressionAnalysisResultSet.Factory.newInstance();
    resultSet.setAnalysis(diffExpressionAnalysis);
    resultSet.setExperimentalFactors(ee.getExperimentalDesign().getExperimentalFactors());
    diffExpressionAnalysis.getResultSets().add(resultSet);
    diffExpressionAnalysis.setExperimentAnalyzed(ee);
    diffExpressionAnalysis = differentialExpressionAnalyzerService.persistAnalysis(ee, diffExpressionAnalysis, config);
    aclTestUtils.checkHasAcl(ee);
    aclTestUtils.checkHasAcl(diffExpressionAnalysis);
    aclTestUtils.checkLacksAcl(resultSet);
    aclTestUtils.checkHasAces(ee);
    aclTestUtils.checkLacksAces(diffExpressionAnalysis);
    aclTestUtils.checkHasAclParent(diffExpressionAnalysis, ee);
}
Also used : DifferentialExpressionAnalysisConfig(ubic.gemma.core.analysis.expression.diff.DifferentialExpressionAnalysisConfig) 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 8 with ExpressionAnalysisResultSet

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

the class TwoWayAnovaWithInteractionsAnalyzerTest method testTwoWayAnova.

@Test
public void testTwoWayAnova() {
    log.debug("Testing TwoWayAnova method in " + DiffExAnalyzer.class.getName());
    if (!connected) {
        log.warn("Could not establish R connection.  Skipping test ...");
        return;
    }
    this.configureMocks();
    Collection<ExperimentalFactor> factors = new HashSet<>();
    factors.add(experimentalFactorA_Area);
    factors.add(experimentalFactorB);
    DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
    config.setFactorsToInclude(factors);
    config.addInteractionToInclude(factors);
    Collection<DifferentialExpressionAnalysis> expressionAnalyses = analyzer.run(expressionExperiment, config);
    DifferentialExpressionAnalysis expressionAnalysis = expressionAnalyses.iterator().next();
    Collection<ExpressionAnalysisResultSet> resultSets = expressionAnalysis.getResultSets();
    assertEquals(BaseAnalyzerConfigurationTest.NUM_TWA_RESULT_SETS, resultSets.size());
    for (ExpressionAnalysisResultSet resultSet : resultSets) {
        this.checkResults(resultSet);
    }
}
Also used : ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) DifferentialExpressionAnalysis(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis) HashSet(java.util.HashSet) ExpressionAnalysisResultSet(ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet) Test(org.junit.Test)

Example 9 with ExpressionAnalysisResultSet

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

the class TwoWayAnovaWithoutInteractionsAnalyzerTest method testTwoWayAnova.

/**
 * Tests the TwoWayAnova method.
 */
@Test
public void testTwoWayAnova() {
    log.debug("Testing getPValues method in " + DiffExAnalyzer.class.getName());
    if (!connected) {
        log.warn("Could not establish R connection.  Skipping test ...");
        return;
    }
    this.configureMocks();
    List<ExperimentalFactor> factors = Arrays.asList(experimentalFactorA_Area, experimentalFactorB);
    DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
    config.setFactorsToInclude(factors);
    Collection<DifferentialExpressionAnalysis> expressionAnalyses = analyzer.run(expressionExperiment, config);
    DifferentialExpressionAnalysis expressionAnalysis = expressionAnalyses.iterator().next();
    Collection<ExpressionAnalysisResultSet> resultSets = expressionAnalysis.getResultSets();
    assertEquals(2, resultSets.size());
    for (ExpressionAnalysisResultSet resultSet : resultSets) {
        this.checkResults(resultSet);
    }
}
Also used : ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) DifferentialExpressionAnalysis(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis) ExpressionAnalysisResultSet(ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet) Test(org.junit.Test)

Example 10 with ExpressionAnalysisResultSet

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

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