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;
}
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");
}
}
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);
}
}
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);
}
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);
}
Aggregations