use of ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet in project Gemma by PavlidisLab.
the class LowVarianceDataTest method checkResults.
public void checkResults(DifferentialExpressionAnalysis analysis) {
Collection<ExpressionAnalysisResultSet> resultSets = analysis.getResultSets();
assertEquals(2, resultSets.size());
boolean found1 = false;
for (ExpressionAnalysisResultSet rs : resultSets) {
Collection<DifferentialExpressionAnalysisResult> results = rs.getResults();
for (DifferentialExpressionAnalysisResult r : results) {
CompositeSequence probe = r.getProbe();
switch(probe.getName()) {
case "1552338_at":
fail("Should not have found a result for constant probe: 1552338_at");
break;
case "1552337_s_at":
fail("Should not have found a result for constant probe: 1552337_s_at");
break;
case "1552391_at":
fail("Should not have found a result for constant probe: 1552391_at");
break;
default:
found1 = true;
break;
}
}
}
assertTrue(found1);
}
use of ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet in project Gemma by PavlidisLab.
the class TwoWayAnovaWithInteractionTest2 method checkResults.
public void checkResults(DifferentialExpressionAnalysis analysis) {
Collection<ExpressionAnalysisResultSet> resultSets = analysis.getResultSets();
assertEquals(3, resultSets.size());
boolean found1 = false, found2 = false, found3 = false, found4 = false;
for (ExpressionAnalysisResultSet rs : resultSets) {
boolean interaction = false;
boolean sexFactor = false;
Collection<DifferentialExpressionAnalysisResult> results = rs.getResults();
if (rs.getExperimentalFactors().size() == 1) {
ExperimentalFactor factor = rs.getExperimentalFactors().iterator().next();
sexFactor = factor.getName().equals("Sex");
} else {
interaction = true;
}
assertEquals(8, results.size());
/*
* Test values here are computed in R, using anova(lm(unlist(expData["205969_at",])~Treatment*Sex )) etc.
*/
for (DifferentialExpressionAnalysisResult r : results) {
CompositeSequence probe = r.getProbe();
Double pvalue = r.getPvalue();
switch(probe.getName()) {
case "205969_at":
if (sexFactor) {
found1 = true;
assertEquals(0.3333, pvalue, 0.001);
} else if (interaction) {
found2 = true;
assertEquals(0.8480, pvalue, 0.001);
} else {
found3 = true;
assertEquals(0.1323, pvalue, 0.001);
}
break;
case "217757_at":
if (interaction) {
found4 = true;
assertEquals(0.7621, pvalue, 0.001);
}
break;
case "constant":
fail("Should not have found a result for constant probe");
break;
}
}
}
assertTrue(found1 && found2 && found3 && found4);
}
use of ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet in project Gemma by PavlidisLab.
the class TwoWayAnovaWithInteractionTest2 method test.
/*
* NOTE I added a constant probe to this data after I set this up.
*
* <pre>
* expMatFile <- "GSE8441_expmat_8probes.txt"
* expDesignFile <- "606_GSE8441_expdesign.data.txt"
* expMat <- log2(read.table(expMatFile, header = TRUE, row.names = 1, sep = "\t", quote=""))
* expDesign <- read.table(expDesignFile, header = TRUE, row.names = 1, sep = "\t", quote="")
*
* expData <- expMat[rownames(expDesign)]
*
* names(expData) == row.names(expDesign)
* attach(expDesign)
* lf<-lm(unlist(expData["217757_at",])~Treatment*Sex )
* summary(lf)
* anova(lf)
*
* summary(lm(unlist(expData["202851_at",])~Treatment*Sex ))
* anova(lm(unlist(expData["202851_at",])~Treatment*Sex ))
*
* # etc.
* </pre>
*/
@Test
public void test() {
AnalysisType aa = analysisService.determineAnalysis(ee, ee.getExperimentalDesign().getExperimentalFactors(), null, true);
assertEquals(AnalysisType.TWO_WAY_ANOVA_WITH_INTERACTION, aa);
DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
Collection<ExperimentalFactor> factors = ee.getExperimentalDesign().getExperimentalFactors();
assertEquals(2, factors.size());
config.setAnalysisType(aa);
config.setFactorsToInclude(factors);
config.getInteractionsToInclude().add(factors);
analyzer = this.getBean(DiffExAnalyzer.class);
Collection<DifferentialExpressionAnalysis> result = analyzer.run(ee, config);
assertEquals(1, result.size());
DifferentialExpressionAnalysis analysis = result.iterator().next();
this.checkResults(analysis);
Collection<DifferentialExpressionAnalysis> persistent = differentialExpressionAnalyzerService.runDifferentialExpressionAnalyses(ee, config);
DifferentialExpressionAnalysis refetched = differentialExpressionAnalysisService.load(persistent.iterator().next().getId());
differentialExpressionAnalysisService.thaw(refetched);
for (ExpressionAnalysisResultSet ears : refetched.getResultSets()) {
differentialExpressionResultService.thaw(ears);
}
this.checkResults(refetched);
differentialExpressionAnalyzerService.redoAnalysis(ee, refetched, true);
}
use of ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet in project Gemma by PavlidisLab.
the class DifferentialExpressionAnalyzerServiceImpl method copyConfig.
private DifferentialExpressionAnalysisConfig copyConfig(DifferentialExpressionAnalysis copyMe) {
DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
if (copyMe.getSubsetFactorValue() != null) {
config.setSubsetFactor(copyMe.getSubsetFactorValue().getExperimentalFactor());
}
Collection<ExpressionAnalysisResultSet> resultSets = copyMe.getResultSets();
Collection<ExperimentalFactor> factorsFromOldExp = new HashSet<>();
for (ExpressionAnalysisResultSet rs : resultSets) {
Collection<ExperimentalFactor> oldfactors = rs.getExperimentalFactors();
factorsFromOldExp.addAll(oldfactors);
/*
* If we included the interaction before, include it again.
*/
if (oldfactors.size() == 2) {
DifferentialExpressionAnalyzerServiceImpl.log.info("Including interaction term");
config.getInteractionsToInclude().add(oldfactors);
}
}
if (factorsFromOldExp.isEmpty()) {
throw new IllegalStateException("Old analysis didn't have any factors");
}
config.getFactorsToInclude().addAll(factorsFromOldExp);
return config;
}
use of ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet in project Gemma by PavlidisLab.
the class DifferentialExpressionAnalyzerServiceImpl method extendResultSets.
private void extendResultSets(Collection<DifferentialExpressionAnalysis> results, Collection<ExpressionAnalysisResultSet> toUpdateResultSets) {
for (DifferentialExpressionAnalysis a : results) {
boolean found = false;
for (ExpressionAnalysisResultSet oldrs : toUpdateResultSets) {
assert oldrs.getId() != null;
this.differentialExpressionResultService.thaw(oldrs);
for (ExpressionAnalysisResultSet temprs : a.getResultSets()) {
/*
* Compare the config
*/
if (this.configsAreEqual(temprs, oldrs)) {
found = true;
this.extendResultSet(oldrs, temprs);
break;
}
}
if (!found)
throw new IllegalStateException("Failed to find a matching existing result set for " + oldrs);
}
}
}
Aggregations