Search in sources :

Example 26 with ExpressionAnalysisResultSet

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

the class AncovaTest method testAncovaContinuousCovariate.

/*
     * With a continuous covariate only
     */
@Test
public void testAncovaContinuousCovariate() {
    this.configureMocks();
    /*
         * Add a continuous factor
         */
    ExperimentalFactor experimentalFactorC = ExperimentalFactor.Factory.newInstance();
    experimentalFactorC.setName("confabulatiliationity");
    experimentalFactorC.setId(5399424551L);
    experimentalFactorC.setType(FactorType.CONTINUOUS);
    this.setupFactorValues(experimentalFactorC);
    // leave off the others.
    expressionExperiment.getExperimentalDesign().getExperimentalFactors().clear();
    expressionExperiment.getExperimentalDesign().getExperimentalFactors().add(experimentalFactorC);
    DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
    config.setFactorsToInclude(expressionExperiment.getExperimentalDesign().getExperimentalFactors());
    Collection<DifferentialExpressionAnalysis> expressionAnalyses = analyzer.run(expressionExperiment, config);
    assertTrue(!expressionAnalyses.isEmpty());
    DifferentialExpressionAnalysis expressionAnalysis = expressionAnalyses.iterator().next();
    assertNotNull(expressionAnalysis);
    Collection<ExpressionAnalysisResultSet> resultSets = expressionAnalysis.getResultSets();
    assertEquals(1, resultSets.size());
    for (ExpressionAnalysisResultSet resultSet : resultSets) {
        Collection<ExperimentalFactor> factors = resultSet.getExperimentalFactors();
        assertEquals(1, factors.size());
        assertEquals(100, resultSet.getResults().size());
        for (DifferentialExpressionAnalysisResult r : resultSet.getResults()) {
            assertNotNull(r.getCorrectedPvalue());
        }
    }
}
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) ExpressionAnalysisResultSet(ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet) Test(org.junit.Test)

Example 27 with ExpressionAnalysisResultSet

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

the class ExpressionAnalysisResultSetDaoImpl method thaw.

/**
 * @see ExpressionAnalysisResultSetDao#thaw(ExpressionAnalysisResultSet)
 */
@Override
public ExpressionAnalysisResultSet thaw(final ExpressionAnalysisResultSet resultSet) {
    StopWatch timer = new StopWatch();
    timer.start();
    this.thawLite(resultSet);
    // noinspection unchecked
    List<ExpressionAnalysisResultSet> res = this.getSessionFactory().getCurrentSession().createQuery("select r from ExpressionAnalysisResultSet r left join fetch r.results res " + " left outer join fetch res.probe left join fetch res.contrasts " + "inner join fetch r.experimentalFactors ef inner join fetch ef.factorValues " + "where r = :rs ").setParameter("rs", resultSet).list();
    if (timer.getTime() > 1000) {
        Log.info("Thaw resultSet: " + timer.getTime() + "ms");
    }
    assert !res.isEmpty();
    return res.get(0);
}
Also used : StopWatch(org.apache.commons.lang3.time.StopWatch) ExpressionAnalysisResultSet(ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet)

Example 28 with ExpressionAnalysisResultSet

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

the class ExpressionAnalysisResultSetDaoImpl method thawWithoutContrasts.

/**
 * @see ExpressionAnalysisResultSetDao#thawWithoutContrasts(ExpressionAnalysisResultSet)
 */
@Override
public ExpressionAnalysisResultSet thawWithoutContrasts(final ExpressionAnalysisResultSet resultSet) {
    StopWatch timer = new StopWatch();
    timer.start();
    this.thawLite(resultSet);
    // noinspection unchecked
    List<ExpressionAnalysisResultSet> res = this.getSessionFactory().getCurrentSession().createQuery("select r from ExpressionAnalysisResultSet r left join fetch r.results res " + " left outer join fetch res.probe " + "inner join fetch r.experimentalFactors ef inner join fetch ef.factorValues " + "where r = :rs ").setParameter("rs", resultSet).list();
    if (timer.getTime() > 1000) {
        Log.info("Thaw resultset: " + timer.getTime() + "ms");
    }
    assert !res.isEmpty();
    return res.get(0);
}
Also used : StopWatch(org.apache.commons.lang3.time.StopWatch) ExpressionAnalysisResultSet(ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet)

Example 29 with ExpressionAnalysisResultSet

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

the class DifferentialExpressionAnalyzerServiceImpl method persistAnalysis.

/**
 * Made public for testing purposes only.
 *
 * @param config               config
 * @param analysis             analysis
 * @param expressionExperiment the experiment
 * @return DEA
 */
@Override
public DifferentialExpressionAnalysis persistAnalysis(ExpressionExperiment expressionExperiment, DifferentialExpressionAnalysis analysis, DifferentialExpressionAnalysisConfig config) {
    this.deleteOldAnalyses(expressionExperiment, analysis, config.getFactorsToInclude());
    StopWatch timer = new StopWatch();
    timer.start();
    Collection<ExpressionAnalysisResultSet> resultSets = analysis.getResultSets();
    analysis.setResultSets(new HashSet<ExpressionAnalysisResultSet>());
    // first transaction, gets us an ID
    DifferentialExpressionAnalysis persistentAnalysis = helperService.persistStub(analysis);
    // second set of transactions creates the empty resultSets.
    for (ExpressionAnalysisResultSet rs : resultSets) {
        Collection<DifferentialExpressionAnalysisResult> results = rs.getResults();
        rs.setResults(new HashSet<DifferentialExpressionAnalysisResult>());
        ExpressionAnalysisResultSet prs = helperService.create(rs);
        assert prs != null;
        for (DifferentialExpressionAnalysisResult r : results) {
            r.setResultSet(prs);
        }
        analysis.getResultSets().add(prs);
        rs.getResults().addAll(results);
        this.addPvalueDistribution(prs);
    }
    // third transaction - add results.
    DifferentialExpressionAnalyzerServiceImpl.log.info("Saving results");
    helperService.addResults(persistentAnalysis, resultSets);
    // get a clean copy of the analysis object from the DB.
    analysis = differentialExpressionAnalysisService.load(analysis.getId());
    // we do this here because now we have IDs for everything.
    try {
        expressionDataFileService.writeDiffExArchiveFile(expressionExperiment, analysis, config);
    } catch (IOException e) {
        DifferentialExpressionAnalyzerServiceImpl.log.error("Unable to save the data to a file: " + e.getMessage());
    }
    // final transaction: audit.
    try {
        auditTrailService.addUpdateEvent(expressionExperiment, DifferentialExpressionAnalysisEvent.Factory.newInstance(), persistentAnalysis.getDescription() + "; analysis id=" + persistentAnalysis.getId());
    } catch (Exception e) {
        DifferentialExpressionAnalyzerServiceImpl.log.error("Error while trying to add audit event: " + e.getMessage(), e);
        DifferentialExpressionAnalyzerServiceImpl.log.error("Continuing ...");
    /*
             * We shouldn't fail completely due to this.
             */
    }
    if (timer.getTime() > 5000) {
        DifferentialExpressionAnalyzerServiceImpl.log.info("Save results: " + timer.getTime() + "ms");
    }
    return persistentAnalysis;
}
Also used : DifferentialExpressionAnalysis(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis) DifferentialExpressionAnalysisResult(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysisResult) IOException(java.io.IOException) IOException(java.io.IOException) StopWatch(org.apache.commons.lang3.time.StopWatch) ExpressionAnalysisResultSet(ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet)

Example 30 with ExpressionAnalysisResultSet

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

the class DifferentialExpressionAnalyzerServiceImpl method deleteOldAnalyses.

private void deleteOldAnalyses(ExpressionExperiment expressionExperiment, DifferentialExpressionAnalysis newAnalysis, Collection<ExperimentalFactor> factors) {
    Collection<DifferentialExpressionAnalysis> diffAnalyses = differentialExpressionAnalysisService.findByInvestigation(expressionExperiment);
    int numDeleted = 0;
    if (diffAnalyses == null || diffAnalyses.isEmpty()) {
        DifferentialExpressionAnalyzerServiceImpl.log.info("No differential expression analyses to remove for " + expressionExperiment.getShortName());
        return;
    }
    this.differentialExpressionAnalysisService.thaw(diffAnalyses);
    for (DifferentialExpressionAnalysis existingAnalysis : diffAnalyses) {
        Collection<ExperimentalFactor> factorsInAnalysis = new HashSet<>();
        for (ExpressionAnalysisResultSet resultSet : existingAnalysis.getResultSets()) {
            factorsInAnalysis.addAll(resultSet.getExperimentalFactors());
        }
        FactorValue subsetFactorValueForExisting = existingAnalysis.getSubsetFactorValue();
        /*
             * Match if: factors are the same, and if this is a subset, it's the same subset factorvalue.
             */
        if (factorsInAnalysis.size() == factors.size() && factorsInAnalysis.containsAll(factors) && (subsetFactorValueForExisting == null || subsetFactorValueForExisting.equals(newAnalysis.getSubsetFactorValue()))) {
            DifferentialExpressionAnalyzerServiceImpl.log.info("Deleting analysis with ID=" + existingAnalysis.getId());
            this.deleteAnalysis(expressionExperiment, existingAnalysis);
            numDeleted++;
        }
    }
    if (numDeleted == 0) {
        DifferentialExpressionAnalyzerServiceImpl.log.info("None of the other existing analyses were eligible for deletion");
    }
}
Also used : DifferentialExpressionAnalysis(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis) ExpressionAnalysisResultSet(ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet)

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