Search in sources :

Example 6 with ExpressionExperimentSubSet

use of ubic.gemma.model.expression.experiment.ExpressionExperimentSubSet in project Gemma by PavlidisLab.

the class DiffExMetaAnalyzerServiceImpl method validate.

private void validate(ExpressionAnalysisResultSet rs) {
    if (rs.getExperimentalFactors().size() > 1) {
        throw new IllegalArgumentException("Cannot do a meta-analysis on interaction terms");
    }
    ExperimentalFactor factor = rs.getExperimentalFactors().iterator().next();
    /*
         * We need to check this just in the subset of samples actually used.
         */
    BioAssaySet experimentAnalyzed = rs.getAnalysis().getExperimentAnalyzed();
    assert experimentAnalyzed != null;
    if (experimentAnalyzed instanceof ExpressionExperimentSubSet) {
        ExpressionExperimentSubSet eesubset = (ExpressionExperimentSubSet) experimentAnalyzed;
        Collection<FactorValue> factorValuesUsed = expressionExperimentSubSetService.getFactorValuesUsed(eesubset, factor);
        if (factorValuesUsed.size() > 2) {
            throw new IllegalArgumentException("Cannot do a meta-analysis including a factor that has more than two levels: " + factor + " has " + factor.getFactorValues().size() + " levels from " + experimentAnalyzed);
        }
    } else {
        if (factor.getFactorValues().size() > 2) {
            /*
                 * Note that this doesn't account for continuous factors.
                 */
            throw new IllegalArgumentException("Cannot do a meta-analysis including a factor that has more than two levels: " + factor + " has " + factor.getFactorValues().size() + " levels from " + experimentAnalyzed);
        }
    }
}
Also used : FactorValue(ubic.gemma.model.expression.experiment.FactorValue) BioAssaySet(ubic.gemma.model.expression.experiment.BioAssaySet) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) ExpressionExperimentSubSet(ubic.gemma.model.expression.experiment.ExpressionExperimentSubSet)

Example 7 with ExpressionExperimentSubSet

use of ubic.gemma.model.expression.experiment.ExpressionExperimentSubSet 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());
        }
    }
}
Also used : InputStream(java.io.InputStream) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) ExpressionExperimentSubSet(ubic.gemma.model.expression.experiment.ExpressionExperimentSubSet) DifferentialExpressionAnalysisValueObject(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysisValueObject) DifferentialExpressionAnalysis(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis) GeoDomainObjectGeneratorLocal(ubic.gemma.core.loader.expression.geo.GeoDomainObjectGeneratorLocal) AbstractGeoServiceTest(ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest) Test(org.junit.Test)

Aggregations

ExpressionExperimentSubSet (ubic.gemma.model.expression.experiment.ExpressionExperimentSubSet)7 BioAssaySet (ubic.gemma.model.expression.experiment.BioAssaySet)3 Test (org.junit.Test)2 ExperimentalFactor (ubic.gemma.model.expression.experiment.ExperimentalFactor)2 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)2 InputStream (java.io.InputStream)1 Criteria (org.hibernate.Criteria)1 AbstractGeoServiceTest (ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest)1 GeoDomainObjectGeneratorLocal (ubic.gemma.core.loader.expression.geo.GeoDomainObjectGeneratorLocal)1 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)1 DifferentialExpressionAnalysis (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis)1 DifferentialExpressionAnalysisValueObject (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysisValueObject)1 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)1 BioAssayDimension (ubic.gemma.model.expression.bioAssayData.BioAssayDimension)1 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)1 FactorValue (ubic.gemma.model.expression.experiment.FactorValue)1 BioSequence (ubic.gemma.model.genome.biosequence.BioSequence)1