Search in sources :

Example 11 with DifferentialExpressionAnalysis

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

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

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

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

the class DifferentialExpressionAnalysisCli method tryToRedoBasedOnOldAnalysis.

/**
 * Run the analysis using configuration based on an old analysis.
 */
private Collection<DifferentialExpressionAnalysis> tryToRedoBasedOnOldAnalysis(ExpressionExperiment ee) {
    Collection<DifferentialExpressionAnalysis> oldAnalyses = differentialExpressionAnalysisService.findByInvestigation(ee);
    if (oldAnalyses.isEmpty()) {
        throw new IllegalArgumentException("There are no old analyses to redo");
    }
    AbstractCLI.log.info("Will attempt to redo " + oldAnalyses.size() + " analyses for " + ee);
    Collection<DifferentialExpressionAnalysis> results = new HashSet<>();
    for (DifferentialExpressionAnalysis copyMe : oldAnalyses) {
        results.addAll(this.differentialExpressionAnalyzerService.redoAnalysis(ee, copyMe, this.persist));
    }
    return results;
}
Also used : DifferentialExpressionAnalysis(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis) HashSet(java.util.HashSet)

Example 15 with DifferentialExpressionAnalysis

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

the class LowVarianceDataTest method test.

@Test
public void test() {
    ee = expressionExperimentService.thawLite(ee);
    AnalysisType aa = analysisService.determineAnalysis(ee, ee.getExperimentalDesign().getExperimentalFactors(), null, true);
    assertEquals(AnalysisType.TWO_WAY_ANOVA_NO_INTERACTION, aa);
    DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
    Collection<ExperimentalFactor> factors = ee.getExperimentalDesign().getExperimentalFactors();
    assertEquals(2, factors.size());
    config.setAnalysisType(aa);
    config.setFactorsToInclude(factors);
    analyzer = this.getBean(DiffExAnalyzer.class);
    Collection<DifferentialExpressionAnalysis> result = analyzer.run(ee, config);
    assertEquals(1, result.size());
    DifferentialExpressionAnalysis analysis = result.iterator().next();
    this.checkResults(analysis);
}
Also used : AnalysisType(ubic.gemma.core.analysis.expression.diff.DifferentialExpressionAnalyzerServiceImpl.AnalysisType) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) DifferentialExpressionAnalysis(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis) AbstractGeoServiceTest(ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest) Test(org.junit.Test)

Aggregations

DifferentialExpressionAnalysis (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis)53 Test (org.junit.Test)26 ExperimentalFactor (ubic.gemma.model.expression.experiment.ExperimentalFactor)26 ExpressionAnalysisResultSet (ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet)21 AbstractGeoServiceTest (ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest)13 DifferentialExpressionAnalysisResult (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysisResult)11 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)8 HashSet (java.util.HashSet)5 ContrastResult (ubic.gemma.model.analysis.expression.diff.ContrastResult)5 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)5 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)5 FactorValue (ubic.gemma.model.expression.experiment.FactorValue)5 AnalysisType (ubic.gemma.core.analysis.expression.diff.DifferentialExpressionAnalyzerServiceImpl.AnalysisType)4 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 Transactional (org.springframework.transaction.annotation.Transactional)3 DifferentialExpressionAnalysisConfig (ubic.gemma.core.analysis.expression.diff.DifferentialExpressionAnalysisConfig)3 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)3 DoubleMatrixReader (ubic.basecode.io.reader.DoubleMatrixReader)2 GeoDomainObjectGeneratorLocal (ubic.gemma.core.loader.expression.geo.GeoDomainObjectGeneratorLocal)2