use of ubic.gemma.model.expression.experiment.ExperimentalFactor in project Gemma by PavlidisLab.
the class SubsettedAnalysis3Test method test.
@Test
public void test() {
ee = expressionExperimentService.thawLite(ee);
Collection<ExperimentalFactor> factors = ee.getExperimentalDesign().getExperimentalFactors();
assertEquals(3, factors.size());
for (BioAssay ba : ee.getBioAssays()) {
assertEquals(3, ba.getSampleUsed().getFactorValues().size());
}
ExperimentalFactor organismpart = null;
ExperimentalFactor disease = null;
ExperimentalFactor diseasegroup = null;
for (ExperimentalFactor ef : factors) {
switch(ef.getCategory().getValue()) {
case "study design":
diseasegroup = ef;
break;
case "disease":
disease = ef;
break;
case "organism part":
organismpart = ef;
break;
}
}
assertNotNull(diseasegroup);
assertNotNull(disease);
assertNotNull(organismpart);
DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
config.getFactorsToInclude().add(disease);
config.getFactorsToInclude().add(organismpart);
config.setSubsetFactor(diseasegroup);
Collection<DifferentialExpressionAnalysis> analyses = analyzer.run(ee, config);
// a subset for each disease: SZ, PD, HD, ALS, ALZ, MS
assertEquals(6, analyses.size());
/*
* Now, within each we should have only one disease contrast,
*/
for (DifferentialExpressionAnalysis analysis : analyses) {
// there should be one for disease - tissue isn't used.
assertEquals(1, analysis.getResultSets().size());
for (ExpressionAnalysisResultSet rs : analysis.getResultSets()) {
ExperimentalFactor factor = rs.getExperimentalFactors().iterator().next();
// noinspection LoopStatementThatDoesntLoop
for (DifferentialExpressionAnalysisResult res : rs.getResults()) {
Collection<ContrastResult> contrasts = res.getContrasts();
for (ContrastResult cr : contrasts) {
log.info(analysis + " " + factor + " " + cr + " " + res);
}
break;
}
}
}
}
use of ubic.gemma.model.expression.experiment.ExperimentalFactor in project Gemma by PavlidisLab.
the class SubsettedAnalysis3Test method setup.
@Before
public void setup() throws Exception {
geoService.setGeoDomainObjectGenerator(new GeoDomainObjectGeneratorLocal(FileTools.resourceToPath("/data/analysis/expression/gse26927short")));
try {
Collection<?> results = geoService.fetchAndLoad("GSE26927", false, true, false);
ee = (ExpressionExperiment) results.iterator().next();
} catch (AlreadyExistsInSystemException e) {
ee = (ExpressionExperiment) ((Collection<?>) e.getData()).iterator().next();
}
ee = expressionExperimentService.thawLite(ee);
Collection<ExperimentalFactor> toremove = new HashSet<>(ee.getExperimentalDesign().getExperimentalFactors());
for (ExperimentalFactor ef : toremove) {
experimentalFactorService.delete(ef);
ee.getExperimentalDesign().getExperimentalFactors().remove(ef);
}
expressionExperimentService.update(ee);
processedExpressionDataVectorService.computeProcessedExpressionData(ee);
ee = expressionExperimentService.thaw(ee);
designImporter.importDesign(ee, this.getClass().getResourceAsStream("/data/analysis/expression/gse26927short/2684_GSE26927_expdesign.data.txt"));
}
use of ubic.gemma.model.expression.experiment.ExperimentalFactor in project Gemma by PavlidisLab.
the class TTestAnalyzerTest method testTTestWithExpressionExperiment.
/**
* Tests the t-test with an {@link ExpressionExperiment}.
*/
@Test
public void testTTestWithExpressionExperiment() {
if (!connected) {
log.warn("Could not establish R connection. Skipping test ...");
return;
}
this.configureMocks();
Collection<ExperimentalFactor> factors = new HashSet<>();
factors.add(super.experimentalFactorA_Area);
DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
config.setFactorsToInclude(factors);
Collection<DifferentialExpressionAnalysis> expressionAnalyses = analyzer.run(expressionExperiment, config);
DifferentialExpressionAnalysis expressionAnalysis = expressionAnalyses.iterator().next();
Collection<ExpressionAnalysisResultSet> resultSets = expressionAnalysis.getResultSets();
ExpressionAnalysisResultSet resultSet = resultSets.iterator().next();
int numResults = resultSet.getResults().size();
assertEquals(numResults, BaseAnalyzerConfigurationTest.NUM_DESIGN_ELEMENTS);
assertEquals(factorValueA2, resultSet.getBaselineGroup());
Collection<HitListSize> hitListSizes = resultSet.getHitListSizes();
assertEquals(3 * 5, hitListSizes.size());
// check
for (DifferentialExpressionAnalysisResult r : resultSet.getResults()) {
CompositeSequence probe = r.getProbe();
Double pvalue = r.getPvalue();
assertNotNull(pvalue);
Collection<ContrastResult> contrasts = r.getContrasts();
Double stat;
if (contrasts.isEmpty()) {
continue;
}
stat = contrasts.iterator().next().getTstat();
log.debug("probe: " + probe + "; p-value: " + pvalue);
switch(probe.getName()) {
case "probe_0":
assertEquals(1.48e-13, pvalue, 1e-15);
assertNotNull(stat);
assertEquals(-277.4, stat, 0.1);
break;
case "probe_4":
assertEquals(0.0001523, pvalue, 0.000001);
break;
case "probe_17":
assertEquals(8.832e-12, pvalue, 1e-15);
break;
case "probe_75":
assertEquals(0.2483, pvalue, 0.001);
break;
}
}
}
use of ubic.gemma.model.expression.experiment.ExperimentalFactor in project Gemma by PavlidisLab.
the class TTestAnalyzerTest method testOneSampleTtest.
@Test
public void testOneSampleTtest() throws Exception {
if (!connected) {
log.warn("Could not establish R connection. Skipping test ...");
return;
}
this.configureVectors(super.biomaterials, "/data/stat-tests/onesample-ttest-data.txt");
this.configureMocks();
Collection<ExperimentalFactor> factors = new HashSet<>();
factors.add(super.experimentalFactorA_Area);
/*
* Remove factorValue from all the samples.
*/
Iterator<FactorValue> iterator = experimentalFactorA_Area.getFactorValues().iterator();
FactorValue toUse = iterator.next();
FactorValue toRemove = iterator.next();
experimentalFactorA_Area.getFactorValues().remove(toRemove);
for (BioMaterial bm : super.biomaterials) {
bm.getFactorValues().remove(toRemove);
bm.getFactorValues().add(toUse);
}
// must be for one-sample to make sense.
quantitationType.setIsRatio(true);
quantitationType.setScale(ScaleType.LOG2);
DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
config.setFactorsToInclude(factors);
Collection<DifferentialExpressionAnalysis> expressionAnalyses = analyzer.run(expressionExperiment, config);
DifferentialExpressionAnalysis expressionAnalysis = expressionAnalyses.iterator().next();
Collection<ExpressionAnalysisResultSet> resultSets = expressionAnalysis.getResultSets();
ExpressionAnalysisResultSet resultSet = resultSets.iterator().next();
assertEquals(null, resultSet.getBaselineGroup());
int numResults = resultSet.getResults().size();
assertEquals(BaseAnalyzerConfigurationTest.NUM_DESIGN_ELEMENTS - 4, numResults);
// check
for (DifferentialExpressionAnalysisResult r : resultSet.getResults()) {
CompositeSequence probe = r.getProbe();
Double pvalue = r.getPvalue();
// Double stat = probeAnalysisResult.getEffectSize();
log.debug("probe: " + probe + "; p-value: " + pvalue);
assertNotNull(pvalue);
switch(probe.getName()) {
case "probe_0":
assertEquals(0.03505, pvalue, 0.00001);
break;
case "probe_16":
assertEquals(0.03476, pvalue, 0.0001);
break;
case "probe_17":
assertEquals(0.03578, pvalue, 0.0001);
break;
case "probe_75":
assertEquals(0.8897, pvalue, 0.0001);
// assertEquals( -0.1507, stat, 0.0001 );
break;
case "probe_94":
assertEquals(0.002717, pvalue, 0.0001);
// assertEquals( 6.6087, stat, 0.001 );
break;
}
}
}
use of ubic.gemma.model.expression.experiment.ExperimentalFactor in project Gemma by PavlidisLab.
the class CharacteristicServiceTest method setup.
@Before
public void setup() {
ee = this.getTestPersistentBasicExpressionExperiment();
ee.setCharacteristics(this.getTestPersistentCharacteristics(2));
Characteristic[] eeChars = ee.getCharacteristics().toArray(new Characteristic[0]);
eeChar1 = eeChars[0];
eeChar2 = eeChars[1];
eeService.update(ee);
BioAssay ba = ee.getBioAssays().toArray(new BioAssay[0])[0];
BioMaterial bm = ba.getSampleUsed();
bm.setCharacteristics(this.getTestPersistentCharacteristics(1));
bmService.update(bm);
for (ExperimentalFactor ef : testHelper.getExperimentalFactors(ee.getExperimentalDesign())) {
eeService.addFactor(ee, ef);
}
ExperimentalFactor ef = ee.getExperimentalDesign().getExperimentalFactors().iterator().next();
for (FactorValue f : testHelper.getFactorValues(ef)) {
eeService.addFactorValue(ee, f);
}
FactorValue fv = ef.getFactorValues().iterator().next();
fv.setCharacteristics(this.getTestPersistentCharacteristics(1));
fvService.update(fv);
}
Aggregations