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