use of ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis in project Gemma by PavlidisLab.
the class SubsettedAnalysisTest method testWithSubset.
@Test
public final void testWithSubset() {
this.configureMocks();
DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
config.getFactorsToInclude().add(this.experimentalFactorA_Area);
config.setSubsetFactor(this.experimentalFactorB);
Collection<DifferentialExpressionAnalysis> expressionAnalyses = analyzer.run(expressionExperiment, config);
assertEquals(2, expressionAnalyses.size());
for (DifferentialExpressionAnalysis expressionAnalysis : expressionAnalyses) {
assertNotNull(expressionAnalysis.getExperimentAnalyzed());
assertEquals(4, expressionAnalysis.getExperimentAnalyzed().getBioAssays().size());
Collection<ExpressionAnalysisResultSet> resultSets = expressionAnalysis.getResultSets();
ExpressionAnalysisResultSet resultSet = resultSets.iterator().next();
int numResults = resultSet.getResults().size();
// we should have filtered some out.
assertTrue(numResults < 100);
}
}
use of ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis in project Gemma by PavlidisLab.
the class TwoWayAnovaWithInteractionsTest2 method test.
@Test
public void test() {
ee = expressionExperimentService.thawLite(ee);
Collection<ExperimentalFactor> factors = ee.getExperimentalDesign().getExperimentalFactors();
assertEquals(2, factors.size());
for (BioAssay ba : ee.getBioAssays()) {
assertEquals(2, ba.getSampleUsed().getFactorValues().size());
}
AnalysisType aa = analysisService.determineAnalysis(ee, ee.getExperimentalDesign().getExperimentalFactors(), null, true);
assertEquals(AnalysisType.TWO_WAY_ANOVA_WITH_INTERACTION, aa);
DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
config.setAnalysisType(aa);
config.setFactorsToInclude(factors);
config.addInteractionToInclude(factors);
analyzer = this.getBean(DiffExAnalyzer.class);
Collection<DifferentialExpressionAnalysis> result = analyzer.run(ee, config);
assertEquals(1, result.size());
DifferentialExpressionAnalysis analysis = result.iterator().next();
assertNotNull(analysis);
assertEquals(3, analysis.getResultSets().size());
}
use of ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis in project Gemma by PavlidisLab.
the class DiffExTest method testGSE35930.
/**
* Test where probes have constant values. See bug 3177.
*/
@Test
public void testGSE35930() throws Exception {
ExpressionExperiment ee;
// eeService.remove( eeService.findByShortName( "GSE35930" ) );
try {
geoService.setGeoDomainObjectGenerator(new GeoDomainObjectGeneratorLocal(this.getTestFileBasePath("GSE35930")));
Collection<?> results = geoService.fetchAndLoad("GSE35930", false, true, false);
ee = (ExpressionExperiment) results.iterator().next();
} catch (AlreadyExistsInSystemException e) {
// OK.
if (e.getData() instanceof List) {
ee = (ExpressionExperiment) ((List<?>) e.getData()).iterator().next();
} else {
ee = (ExpressionExperiment) e.getData();
}
}
ee = this.eeService.thawLite(ee);
processedExpressionDataVectorService.computeProcessedExpressionData(ee);
if (ee.getExperimentalDesign().getExperimentalFactors().isEmpty()) {
ee = eeService.load(ee.getId());
ee = this.eeService.thawLite(ee);
try (InputStream is = this.getClass().getResourceAsStream("/data/loader/expression/geo/GSE35930/design.txt")) {
experimentalDesignImporter.importDesign(ee, is);
}
ee = eeService.load(ee.getId());
ee = this.eeService.thawLite(ee);
}
DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
config.setFactorsToInclude(ee.getExperimentalDesign().getExperimentalFactors());
Collection<DifferentialExpressionAnalysis> analyses = analyzer.run(ee, config);
assertNotNull(analyses);
assertEquals(1, analyses.size());
DifferentialExpressionAnalysis results = analyses.iterator().next();
boolean found = false;
ExpressionAnalysisResultSet resultSet = results.getResultSets().iterator().next();
for (DifferentialExpressionAnalysisResult r : resultSet.getResults()) {
// this probe has a constant value
if (r.getProbe().getName().equals("1622910_at")) {
fail("Should not have found a result for constant probe");
// found = true;
// assertTrue( "Got: " + pvalue, pvalue == null || pvalue.equals( Double.NaN ) );
} else {
// got to have something...
found = true;
}
}
assertTrue(found);
}
use of ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis in project Gemma by PavlidisLab.
the class DiffExTest method testCountData.
/**
* Test differential expression analysis on RNA-seq data. See bug 3383. R code in voomtest.R
*/
@Test
public void testCountData() throws Exception {
geoService.setGeoDomainObjectGenerator(new GeoDomainObjectGenerator());
ExpressionExperiment ee = eeService.findByShortName("GSE29006");
if (ee != null) {
eeService.remove(ee);
}
assertTrue(eeService.findByShortName("GSE29006") == null);
try {
Collection<?> results = geoService.fetchAndLoad("GSE29006", false, false, false);
ee = (ExpressionExperiment) results.iterator().next();
} catch (AlreadyExistsInSystemException e) {
throw new IllegalStateException("Need to remove this data set before test is run");
}
ee = eeService.thaw(ee);
try (InputStream is = this.getClass().getResourceAsStream("/data/loader/expression/flatfileload/GSE29006_design.txt")) {
assertNotNull(is);
experimentalDesignImporter.importDesign(ee, is);
}
// Load the data from a text file.
DoubleMatrixReader reader = new DoubleMatrixReader();
ArrayDesign targetArrayDesign;
try (InputStream countData = this.getClass().getResourceAsStream("/data/loader/expression/flatfileload/GSE29006_expression_count.test.txt")) {
DoubleMatrix<String, String> countMatrix = reader.read(countData);
Collection<ExperimentalFactor> experimentalFactors = ee.getExperimentalDesign().getExperimentalFactors();
assertEquals(1, experimentalFactors.size());
List<String> probeNames = countMatrix.getRowNames();
assertEquals(199, probeNames.size());
// we have to find the right generic platform to use.
targetArrayDesign = this.getTestPersistentArrayDesign(probeNames, taxonService.findByCommonName("human"));
targetArrayDesign = arrayDesignService.thaw(targetArrayDesign);
// the experiment has 8 samples but the data has 4 columns so allow missing samples
// GSM718707 GSM718708 GSM718709 GSM718710
dataUpdater.addCountData(ee, targetArrayDesign, countMatrix, null, 36, true, true);
}
// make sure to do a thawRawAndProcessed() to get the addCountData() updates
ee = eeService.thaw(ee);
// verify rows and columns
Collection<DoubleVectorValueObject> processedDataArrays = processedExpressionDataVectorService.getProcessedDataArrays(ee);
assertEquals(199, processedDataArrays.size());
for (DoubleVectorValueObject v : processedDataArrays) {
assertEquals(4, v.getBioAssays().size());
}
// I confirmed that log2cpm is working same as voom here; not bothering to test directly.
TestUtils.assertBAs(ee, targetArrayDesign, "GSM718709", 320383);
// DE analysis without weights to assist comparison to R
DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
config.setUseWeights(false);
config.setFactorsToInclude(ee.getExperimentalDesign().getExperimentalFactors());
Collection<DifferentialExpressionAnalysis> analyses = analyzer.run(ee, config);
assertNotNull(analyses);
assertEquals(1, analyses.size());
DifferentialExpressionAnalysis results = analyses.iterator().next();
boolean found = false;
ExpressionAnalysisResultSet resultSet = results.getResultSets().iterator().next();
for (DifferentialExpressionAnalysisResult r : resultSet.getResults()) {
if (r.getProbe().getName().equals("ENSG00000000938")) {
found = true;
ContrastResult contrast = r.getContrasts().iterator().next();
assertEquals(0.007055717, r.getPvalue(), // R: 0.006190738; coeff = 2.2695215; t=12.650422; R with our weights: 0.009858270, 2.2317534; t=9.997007
0.00001);
// up to sign
assertEquals(2.2300049, Math.abs(contrast.getCoefficient()), 0.001);
break;
}
}
assertTrue(found);
// With weights
config = new DifferentialExpressionAnalysisConfig();
// <----
config.setUseWeights(true);
config.setFactorsToInclude(ee.getExperimentalDesign().getExperimentalFactors());
analyses = analyzer.run(ee, config);
results = analyses.iterator().next();
resultSet = results.getResultSets().iterator().next();
for (DifferentialExpressionAnalysisResult r : resultSet.getResults()) {
if (r.getProbe().getName().equals("ENSG00000000938")) {
assertEquals(1, r.getContrasts().size());
ContrastResult contrast = r.getContrasts().iterator().next();
// yes!
assertEquals(2.232816, Math.abs(contrast.getCoefficient()), 0.001);
assertEquals(0.000311, contrast.getPvalue(), 0.00001);
assertEquals(56.66342, Math.abs(contrast.getTstat()), 0.001);
assertEquals(0.007068, r.getPvalue(), 0.00001);
break;
}
}
}
use of ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis 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());
}
}
}
Aggregations