Search in sources :

Example 26 with DifferentialExpressionAnalysis

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

the class ExpressionDataFileServiceImpl method deleteAllFiles.

@Override
public void deleteAllFiles(ExpressionExperiment ee) {
    ee = this.expressionExperimentService.thawLite(ee);
    // data files.
    this.deleteAndLog(this.getOutputFile(ee, true));
    this.deleteAndLog(this.getOutputFile(ee, false));
    // diff ex files
    Collection<DifferentialExpressionAnalysis> analyses = this.differentialExpressionAnalysisService.getAnalyses(ee);
    for (DifferentialExpressionAnalysis analysis : analyses) {
        this.deleteDiffExArchiveFile(analysis);
    }
    // coexpression file
    this.deleteAndLog(this.getOutputFile(this.getCoexpressionDataFilename(ee)));
    // design file
    this.deleteAndLog(this.getOutputFile(this.getDesignFileName(ee)));
}
Also used : DifferentialExpressionAnalysis(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis)

Example 27 with DifferentialExpressionAnalysis

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

the class ExpressionDataFileServiceImpl method writeOrLocateDiffExpressionDataFiles.

@Override
public Collection<File> writeOrLocateDiffExpressionDataFiles(ExpressionExperiment ee, boolean forceWrite) {
    ee = this.expressionExperimentService.thawLite(ee);
    Collection<DifferentialExpressionAnalysis> analyses = this.differentialExpressionAnalysisService.getAnalyses(ee);
    Collection<File> result = new HashSet<>();
    for (DifferentialExpressionAnalysis analysis : analyses) {
        assert analysis.getId() != null;
        result.add(this.getDiffExpressionAnalysisArchiveFile(analysis.getId(), forceWrite));
    }
    return result;
}
Also used : DifferentialExpressionAnalysis(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis)

Example 28 with DifferentialExpressionAnalysis

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

the class DifferentialExpressionAnalysisCli method processExperiment.

private void processExperiment(ExpressionExperiment ee) {
    Collection<DifferentialExpressionAnalysis> results;
    DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
    try {
        ee = this.eeService.thawLite(ee);
        if (delete) {
            AbstractCLI.log.info("Deleting any analyses for experiment=" + ee);
            differentialExpressionAnalyzerService.deleteAnalyses(ee);
            successObjects.add("Deleted analysis for: " + ee.toString());
            return;
        }
        Collection<ExperimentalFactor> experimentalFactors = ee.getExperimentalDesign().getExperimentalFactors();
        if (experimentalFactors.size() == 0) {
            if (this.expressionExperiments.size() == 1) {
                /*
                     * Only need to be noisy if this is the only ee. Batch processing should be less so.
                     */
                throw new RuntimeException("Experiment does not have an experimental design populated: " + ee.getShortName());
            }
            AbstractCLI.log.warn("Experiment does not have an experimental design populated: " + ee.getShortName());
            return;
        }
        Collection<ExperimentalFactor> factors = this.guessFactors(ee);
        if (factors.size() > 0) {
            /*
                 * Manual selection of factors
                 */
            ExperimentalFactor subsetFactor = this.getSubsetFactor(ee);
            AbstractCLI.log.info("Using " + factors.size() + " factors provided as arguments");
            if (subsetFactor != null) {
                if (factors.contains(subsetFactor)) {
                    throw new IllegalArgumentException("Subset factor cannot also be included as factor to analyze");
                }
                AbstractCLI.log.info("Subsetting by " + subsetFactor);
            }
            config.setAnalysisType(this.type);
            config.setFactorsToInclude(factors);
            config.setSubsetFactor(subsetFactor);
            config.setModerateStatistics(this.ebayes);
            config.setPersist(this.persist);
            boolean rnaSeq = super.eeService.isRNASeq(ee);
            config.setUseWeights(rnaSeq);
            /*
                 * Interactions included by default. It's actually only complicated if there is a subset factor.
                 */
            if (type == null && factors.size() == 2) {
                config.getInteractionsToInclude().add(factors);
            }
            results = this.differentialExpressionAnalyzerService.runDifferentialExpressionAnalyses(ee, config);
        } else {
            if (tryToCopyOld) {
                this.tryToRedoBasedOnOldAnalysis(ee);
            }
            Collection<ExperimentalFactor> factorsToUse = new HashSet<>();
            if (this.ignoreBatch) {
                for (ExperimentalFactor ef : experimentalFactors) {
                    if (!ExperimentalDesignUtils.isBatch(ef)) {
                        factorsToUse.add(ef);
                    }
                }
            } else {
                factorsToUse.addAll(experimentalFactors);
            }
            if (factorsToUse.isEmpty()) {
                throw new RuntimeException("No factors available for " + ee.getShortName());
            }
            if (factorsToUse.size() > 3) {
                if (!tryToCopyOld) {
                    throw new RuntimeException("Experiment has too many factors to run automatically: " + ee.getShortName() + "; try using the -redo flag to base it on an old analysis, or select factors manually");
                }
                results = this.tryToRedoBasedOnOldAnalysis(ee);
            } else {
                config.setFactorsToInclude(factorsToUse);
                config.setPersist(this.persist);
                config.setModerateStatistics(this.ebayes);
                if (factorsToUse.size() == 2) {
                    // include interactions by default
                    config.addInteractionToInclude(factorsToUse);
                }
                boolean rnaSeq = super.eeService.isRNASeq(ee);
                config.setUseWeights(rnaSeq);
                results = this.differentialExpressionAnalyzerService.runDifferentialExpressionAnalyses(ee, config);
            }
        }
        if (results == null) {
            throw new Exception("Failed to process differential expression for experiment " + ee.getShortName());
        }
        if (!this.persist) {
            AbstractCLI.log.info("Writing results to disk");
            for (DifferentialExpressionAnalysis r : results) {
                expressionDataFileService.writeDiffExArchiveFile(ee, r, config);
            }
        }
        successObjects.add(ee.toString());
    } catch (Exception e) {
        AbstractCLI.log.error("Error while processing " + ee + ": " + e.getMessage());
        ExceptionUtils.printRootCauseStackTrace(e);
        errorObjects.add(ee + ": " + e.getMessage());
    }
}
Also used : DifferentialExpressionAnalysisConfig(ubic.gemma.core.analysis.expression.diff.DifferentialExpressionAnalysisConfig) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) DifferentialExpressionAnalysis(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis) HashSet(java.util.HashSet)

Example 29 with DifferentialExpressionAnalysis

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

the class PreprocessorServiceImpl method processExceptForVectorCreate.

private ExpressionExperiment processExceptForVectorCreate(ExpressionExperiment ee) {
    // // refresh into context.
    ee = expressionExperimentService.thawLite(ee);
    assert ee.getNumberOfDataVectors() != null;
    /*
         * Redo any old diff ex analyses
         */
    Collection<DifferentialExpressionAnalysis> oldAnalyses = differentialExpressionAnalysisService.findByInvestigation(ee);
    if (!oldAnalyses.isEmpty()) {
        PreprocessorServiceImpl.log.info("Will attempt to redo " + oldAnalyses.size() + " analyses for " + ee);
        for (DifferentialExpressionAnalysis copyMe : oldAnalyses) {
            try {
                this.analyzerService.redoAnalysis(ee, copyMe, true);
            } catch (Exception e) {
                PreprocessorServiceImpl.log.error("Could not redo analysis: " + " " + copyMe + ": " + e.getMessage());
            }
        }
    }
    this.processForSampleCorrelation(ee);
    this.processForMeanVarianceRelation(ee);
    this.processForPca(ee);
    expressionExperimentService.update(ee);
    assert ee.getNumberOfDataVectors() != null;
    return ee;
}
Also used : DifferentialExpressionAnalysis(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis)

Example 30 with DifferentialExpressionAnalysis

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

the class SubsettedAnalysis3Test method test.

@Test
public void test() {
    ee = expressionExperimentService.thawLite(ee);
    Collection<ExperimentalFactor> factors = ee.getExperimentalDesign().getExperimentalFactors();
    assertEquals(3, factors.size());
    for (BioAssay ba : ee.getBioAssays()) {
        assertEquals(3, ba.getSampleUsed().getFactorValues().size());
    }
    ExperimentalFactor organismpart = null;
    ExperimentalFactor disease = null;
    ExperimentalFactor diseasegroup = null;
    for (ExperimentalFactor ef : factors) {
        switch(ef.getCategory().getValue()) {
            case "study design":
                diseasegroup = ef;
                break;
            case "disease":
                disease = ef;
                break;
            case "organism part":
                organismpart = ef;
                break;
        }
    }
    assertNotNull(diseasegroup);
    assertNotNull(disease);
    assertNotNull(organismpart);
    DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
    config.getFactorsToInclude().add(disease);
    config.getFactorsToInclude().add(organismpart);
    config.setSubsetFactor(diseasegroup);
    Collection<DifferentialExpressionAnalysis> analyses = analyzer.run(ee, config);
    // a subset for each disease: SZ, PD, HD, ALS, ALZ, MS
    assertEquals(6, analyses.size());
    /*
         * Now, within each we should have only one disease contrast,
         */
    for (DifferentialExpressionAnalysis analysis : analyses) {
        // there should be one for disease - tissue isn't used.
        assertEquals(1, analysis.getResultSets().size());
        for (ExpressionAnalysisResultSet rs : analysis.getResultSets()) {
            ExperimentalFactor factor = rs.getExperimentalFactors().iterator().next();
            // noinspection LoopStatementThatDoesntLoop
            for (DifferentialExpressionAnalysisResult res : rs.getResults()) {
                Collection<ContrastResult> contrasts = res.getContrasts();
                for (ContrastResult cr : contrasts) {
                    log.info(analysis + "   " + factor + " " + cr + " " + res);
                }
                break;
            }
        }
    }
}
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) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay) ExpressionAnalysisResultSet(ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet) ContrastResult(ubic.gemma.model.analysis.expression.diff.ContrastResult) 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