Search in sources :

Example 46 with DifferentialExpressionAnalysis

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

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

Example 48 with DifferentialExpressionAnalysis

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

the class FactorValueDeletionImpl method deleteFactorValues.

@Override
@Transactional
public void deleteFactorValues(Collection<Long> fvIds) {
    Collection<FactorValue> fvsToDelete = new ArrayList<>();
    for (Long fvId : fvIds) {
        FactorValue fv = factorValueService.load(fvId);
        if (fv == null) {
            throw new IllegalArgumentException("No factor value with id=" + fvId + " could be loaded");
        }
        if (fv.getExperimentalFactor() == null) {
            throw new IllegalStateException("No experimental factor for factor value " + fv.getId());
        }
        /*
             * Delete any diff ex analyses that use this factor.
             */
        ExperimentalFactor ef = experimentalFactorService.load(fv.getExperimentalFactor().getId());
        Collection<DifferentialExpressionAnalysis> analyses = differentialExpressionAnalysisService.findByFactor(ef);
        // Warning: slow.
        for (DifferentialExpressionAnalysis a : analyses) {
            differentialExpressionAnalysisService.remove(a);
        }
        // this gets done by the factorValueService as well, but can't hurt.
        ef.getFactorValues().remove(fv);
        fvsToDelete.add(fv);
    }
    for (FactorValue fv : fvsToDelete) {
        factorValueService.remove(fv);
    }
}
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) Transactional(org.springframework.transaction.annotation.Transactional)

Example 49 with DifferentialExpressionAnalysis

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

the class DifferentialExpressionAnalysisController method refreshStats.

public String refreshStats(Long eeId, Long id) {
    ExpressionExperiment ee = expressionExperimentService.load(eeId);
    if (ee == null) {
        throw new IllegalArgumentException("Cannot access experiment with id=" + eeId);
    }
    DifferentialExpressionAnalysis toRefresh = differentialExpressionAnalysisService.load(id);
    if (toRefresh == null) {
        throw new IllegalArgumentException("Cannot access analysis with id=" + id);
    }
    this.experimentReportService.evictFromCache(ee.getId());
    DifferentialExpressionAnalysisTaskCommand cmd = new DifferentialExpressionAnalysisTaskCommand(ee, toRefresh);
    return taskRunningService.submitLocalTask(cmd);
}
Also used : DifferentialExpressionAnalysisTaskCommand(ubic.gemma.core.tasks.analysis.diffex.DifferentialExpressionAnalysisTaskCommand) DifferentialExpressionAnalysis(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment)

Example 50 with DifferentialExpressionAnalysis

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

the class DifferentialExpressionAnalysisController method redo.

/**
 * AJAX entry point to redo an analysis.
 *
 * @param eeId ee id
 * @param id   id
 * @return string
 * @throws Exception exception
 */
public String redo(Long eeId, Long id) {
    ExpressionExperiment ee = expressionExperimentService.load(eeId);
    if (ee == null) {
        throw new IllegalArgumentException("Cannot access experiment with id=" + eeId);
    }
    DifferentialExpressionAnalysis toRedo = differentialExpressionAnalysisService.load(id);
    if (toRedo == null) {
        throw new IllegalArgumentException("Cannot access analysis with id=" + id);
    }
    this.experimentReportService.evictFromCache(ee.getId());
    DifferentialExpressionAnalysisTaskCommand cmd = new DifferentialExpressionAnalysisTaskCommand(ee, toRedo);
    return taskRunningService.submitRemoteTask(cmd);
}
Also used : DifferentialExpressionAnalysisTaskCommand(ubic.gemma.core.tasks.analysis.diffex.DifferentialExpressionAnalysisTaskCommand) DifferentialExpressionAnalysis(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment)

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