use of ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis in project Gemma by PavlidisLab.
the class DifferentialExpressionAnalyzerServiceTest method testAnalyzeAndDelete.
@Test
public void testAnalyzeAndDelete() throws Exception {
assert ee.getId() != null;
DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
Collection<ExperimentalFactor> factors = ee.getExperimentalDesign().getExperimentalFactors();
config.setFactorsToInclude(factors);
config.addInteractionToInclude(factors);
Collection<DifferentialExpressionAnalysis> analyses = differentialExpressionAnalyzerService.runDifferentialExpressionAnalyses(ee, config);
assertNotNull(analyses);
assertTrue(!analyses.isEmpty());
assertNotNull(analyses.iterator().next());
DifferentialExpressionAnalysis analysis = differentialExpressionAnalysisService.thawFully(analyses.iterator().next());
aclTestUtils.checkHasAcl(analysis);
aclTestUtils.checkLacksAces(analysis);
aclTestUtils.checkHasAclParent(analysis, ee);
for (ExpressionAnalysisResultSet rs : analysis.getResultSets()) {
assertTrue(!rs.getResults().isEmpty());
assertEquals(99, rs.getResults().size());
}
// avoid adding annotations for genes, it confuses the reader.
for (ArrayDesign ad : expressionExperimentService.getArrayDesignsUsed(ee)) {
this.arrayDesignAnnotationService.deleteExistingFiles(ad);
}
Collection<File> outputLocations = expressionDataFileService.writeOrLocateDiffExpressionDataFiles(ee, true);
assertEquals(1, outputLocations.size());
File outputLocation = outputLocations.iterator().next();
// NOte that this reader generally won't work for experiment files because of the gene annotations.
DoubleMatrixReader r = new DoubleMatrixReader();
assertTrue(outputLocation.canRead());
DoubleMatrix<String, String> readIn = r.read(outputLocation.getAbsolutePath());
assertEquals(99, readIn.rows());
System.out.println(readIn.toString());
assertEquals(9, readIn.columns());
expressionDataFileService.deleteAllFiles(ee);
// / remove the analysis
int numDeleted = differentialExpressionAnalyzerService.deleteAnalyses(ee);
assertTrue(numDeleted > 0);
}
use of ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis in project Gemma by PavlidisLab.
the class DifferentialExpressionAnalyzerServiceTest method testAnalyzeWithSubsetWhenOneIsNotUsableAndWithInteractionInTheOther.
/**
* Test inspired by bug 2605
*/
@Test
public void testAnalyzeWithSubsetWhenOneIsNotUsableAndWithInteractionInTheOther() throws Exception {
ee = expressionExperimentService.findByShortName("GSE32136");
if (ee == null) {
geoService.setGeoDomainObjectGenerator(new GeoDomainObjectGeneratorLocal(this.getTestFileBasePath()));
Collection<?> results = geoService.fetchAndLoad("GSE32136", false, true, false);
ee = (ExpressionExperiment) results.iterator().next();
}
processedDataVectorService.createProcessedDataVectors(ee);
ee = expressionExperimentService.thawLite(ee);
Collection<ExperimentalFactor> experimentalFactors = ee.getExperimentalDesign().getExperimentalFactors();
for (ExperimentalFactor experimentalFactor : experimentalFactors) {
experimentalFactorService.delete(experimentalFactor);
}
ee = expressionExperimentService.thawLite(ee);
try (InputStream is = this.getClass().getResourceAsStream("/data/loader/expression/geo/GSE32136.design.txt")) {
assertNotNull(is);
experimentalDesignImporter.importDesign(ee, is);
}
experimentalFactors = ee.getExperimentalDesign().getExperimentalFactors();
assertEquals(3, experimentalFactors.size());
differentialExpressionAnalyzerService.deleteAnalyses(ee);
// Done with setting it up.
Collection<ExperimentalFactor> factors = new HashSet<>();
ExperimentalFactor subsetFactor = null;
for (ExperimentalFactor ef : experimentalFactors) {
if (ef.getName().equals("PooledTreatment")) {
subsetFactor = ef;
} else {
factors.add(ef);
}
}
assertNotNull(subsetFactor);
assertEquals(2, factors.size());
DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
config.setFactorsToInclude(factors);
config.setSubsetFactor(subsetFactor);
HashSet<Collection<ExperimentalFactor>> ifacts = new HashSet<>();
ifacts.add(factors);
config.setInteractionsToInclude(ifacts);
Collection<DifferentialExpressionAnalysis> analyses = differentialExpressionAnalyzerService.runDifferentialExpressionAnalyses(ee, config);
assertEquals("Should have quietly ignored one of the subsets that is not analyzable", 1, analyses.size());
DifferentialExpressionAnalysis analysis = analyses.iterator().next();
assertEquals("Subsetting was not done correctly", subsetFactor, analysis.getSubsetFactorValue().getExperimentalFactor());
assertEquals("Interaction was not retained in the analyzed subset", 3, analysis.getResultSets().size());
ExpressionExperimentSubSet eeset = (ExpressionExperimentSubSet) analysis.getExperimentAnalyzed();
aclTestUtils.checkEESubSetAcls(eeset);
aclTestUtils.checkHasAcl(analysis);
aclTestUtils.checkLacksAces(eeset);
aclTestUtils.checkLacksAces(analysis);
// check that we read it back correctly.
{
Map<ExpressionExperimentDetailsValueObject, Collection<DifferentialExpressionAnalysisValueObject>> vos = differentialExpressionAnalysisService.getAnalysesByExperiment(Collections.singleton(ee.getId()));
// it will retrieve the analysis of the subset.
assertEquals(1, vos.size());
}
// retrieve the analysis of the subset directly.
{
Map<ExpressionExperimentDetailsValueObject, Collection<DifferentialExpressionAnalysisValueObject>> vos = differentialExpressionAnalysisService.getAnalysesByExperiment(Collections.singleton(eeset.getId()));
assertEquals(1, vos.size());
for (DifferentialExpressionAnalysisValueObject vo : vos.entrySet().iterator().next().getValue()) {
assertNotNull(vo.getSubsetFactorValue());
}
}
}
use of ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis in project Gemma by PavlidisLab.
the class DifferentialExpressionAnalyzerServiceTest method testAnalyzeAndDeleteSpecificAnalysisWithSubset.
/**
* Tests running with a subset factor, then deleting.
*/
@Test
public void testAnalyzeAndDeleteSpecificAnalysisWithSubset() {
ExperimentalFactor[] factors = ee.getExperimentalDesign().getExperimentalFactors().toArray(new ExperimentalFactor[] {});
List<ExperimentalFactor> factorsToUse = Collections.singletonList(factors[0]);
ExperimentalFactor subsetFactor = factors[1];
DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
config.setFactorsToInclude(factorsToUse);
config.setSubsetFactor(subsetFactor);
Collection<DifferentialExpressionAnalysis> analyses = differentialExpressionAnalyzerService.runDifferentialExpressionAnalyses(ee, config);
assertTrue(!analyses.isEmpty());
differentialExpressionAnalyzerService.deleteAnalysis(ee, analyses.iterator().next());
}
use of ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis in project Gemma by PavlidisLab.
the class DifferentialExpressionAnalyzerServiceTest method testWritePValuesHistogram.
@Test
public void testWritePValuesHistogram() {
DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
Collection<ExperimentalFactor> factors = ee.getExperimentalDesign().getExperimentalFactors();
config.setFactorsToInclude(factors);
Collection<DifferentialExpressionAnalysis> analyses = differentialExpressionAnalyzerService.runDifferentialExpressionAnalyses(ee, config);
for (DifferentialExpressionAnalysis analysis : analyses) {
differentialExpressionAnalysisService.thaw(analysis);
for (ExpressionAnalysisResultSet resultSet : analysis.getResultSets()) {
Histogram hist = resultService.loadPvalueDistribution(resultSet.getId());
assertNotNull(hist);
}
}
}
use of ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis in project Gemma by PavlidisLab.
the class SubsettedAnalysis2Test method test.
@Test
public void test() {
ee = expressionExperimentService.thawLite(ee);
Collection<ExperimentalFactor> factors = ee.getExperimentalDesign().getExperimentalFactors();
// includes batch
assertEquals(4, factors.size());
for (BioAssay ba : ee.getBioAssays()) {
assertEquals(4, ba.getSampleUsed().getFactorValues().size());
}
ExperimentalFactor strainOrLine = null;
ExperimentalFactor genotype = null;
ExperimentalFactor phenotype = null;
for (ExperimentalFactor ef : factors) {
switch(ef.getCategory().getValue()) {
case "genotype":
genotype = ef;
break;
case "strain":
strainOrLine = ef;
break;
case "phenotype":
phenotype = ef;
break;
}
}
assertNotNull(strainOrLine);
assertNotNull(phenotype);
assertNotNull(genotype);
DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
config.getFactorsToInclude().add(genotype);
config.getFactorsToInclude().add(phenotype);
config.setSubsetFactor(strainOrLine);
analyzer = this.getBean(DiffExAnalyzer.class);
Collection<DifferentialExpressionAnalysis> result = analyzer.run(ee, config);
// two subsets
assertEquals(2, result.size());
}
Aggregations