Search in sources :

Example 61 with ExperimentalFactor

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

the class BatchInfoPopulationServiceIntegrationTest method testLoadCommandConsoleFormat.

/*
     * Another Affymetrix format - GCOS
     */
@Test
public void testLoadCommandConsoleFormat() throws Exception {
    geoService.setGeoDomainObjectGenerator(new GeoDomainObjectGeneratorLocal(this.getTestFileBasePath()));
    ExpressionExperiment newee;
    try {
        Collection<?> results = geoService.fetchAndLoad("GSE20219", false, true, false);
        newee = (ExpressionExperiment) results.iterator().next();
    } catch (AlreadyExistsInSystemException e) {
        newee = (ExpressionExperiment) ((List<?>) e.getData()).iterator().next();
    }
    assertNotNull(newee);
    newee = eeService.thawLite(newee);
    assertTrue(batchInfoPopulationService.fillBatchInformation(newee, true));
    newee = eeService.thawLite(newee);
    for (ExperimentalFactor ef : newee.getExperimentalDesign().getExperimentalFactors()) {
        if (ef.getName().equals(ExperimentalFactorService.BATCH_FACTOR_NAME)) {
            for (FactorValue fv : ef.getFactorValues()) {
                assertNotNull(fv.getValue());
                // Batch_01, Batch_02 etc.
                assertTrue(fv.getValue().startsWith("Batch_0"));
            }
        }
    }
}
Also used : FactorValue(ubic.gemma.model.expression.experiment.FactorValue) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) List(java.util.List) AlreadyExistsInSystemException(ubic.gemma.core.loader.util.AlreadyExistsInSystemException) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) GeoDomainObjectGeneratorLocal(ubic.gemma.core.loader.expression.geo.GeoDomainObjectGeneratorLocal) AbstractGeoServiceTest(ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest) Test(org.junit.Test)

Example 62 with ExperimentalFactor

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

the class DiffExWithInvalidInteractionTest method setup.

@Before
public void setup() throws Exception {
    geoService.setGeoDomainObjectGenerator(new GeoDomainObjectGeneratorLocal(FileTools.resourceToPath("/data/analysis/expression")));
    try {
        Collection<?> results = geoService.fetchAndLoad("GSE50664", 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/8165_GSE50664_expdesign.data.txt"));
}
Also used : ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) Collection(java.util.Collection) AlreadyExistsInSystemException(ubic.gemma.core.loader.util.AlreadyExistsInSystemException) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) GeoDomainObjectGeneratorLocal(ubic.gemma.core.loader.expression.geo.GeoDomainObjectGeneratorLocal) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 63 with ExperimentalFactor

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

the class DiffExWithInvalidInteractionTest method test.

/**
 * This should automatically drop the interaction. If it fails on a 'no residual degrees of freedom' it means we're
 * not detecting thatS
 */
@Test
public void test() {
    ee = expressionExperimentService.thawLite(ee);
    Collection<ExperimentalFactor> factors = ee.getExperimentalDesign().getExperimentalFactors();
    // includes batch
    assertEquals(3, factors.size());
    for (BioAssay ba : ee.getBioAssays()) {
        assertEquals(3, ba.getSampleUsed().getFactorValues().size());
    }
    ExperimentalFactor timepoint = null;
    ExperimentalFactor treatment = null;
    for (ExperimentalFactor ef : factors) {
        if (ef.getCategory().getValue().equals("timepoint")) {
            timepoint = ef;
        } else if (ef.getCategory().getValue().equals("treatment")) {
            treatment = ef;
        }
    }
    assertNotNull(treatment);
    assertNotNull(timepoint);
    DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
    config.getFactorsToInclude().add(timepoint);
    config.getFactorsToInclude().add(treatment);
    config.addInteractionToInclude(treatment, timepoint);
    analyzer = this.getBean(AnalysisSelectionAndExecutionService.class);
    Collection<DifferentialExpressionAnalysis> result = analyzer.analyze(ee, config);
    assertEquals(1, result.size());
}
Also used : ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) DifferentialExpressionAnalysis(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay) AbstractGeoServiceTest(ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest) Test(org.junit.Test)

Example 64 with ExperimentalFactor

use of ubic.gemma.model.expression.experiment.ExperimentalFactor 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);
}
Also used : ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) DifferentialExpressionAnalysis(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis) DoubleMatrixReader(ubic.basecode.io.reader.DoubleMatrixReader) ExpressionAnalysisResultSet(ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet) File(java.io.File) AbstractGeoServiceTest(ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest) Test(org.junit.Test)

Example 65 with ExperimentalFactor

use of ubic.gemma.model.expression.experiment.ExperimentalFactor 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

ExperimentalFactor (ubic.gemma.model.expression.experiment.ExperimentalFactor)88 Test (org.junit.Test)31 FactorValue (ubic.gemma.model.expression.experiment.FactorValue)30 DifferentialExpressionAnalysis (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis)26 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)22 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)18 HashSet (java.util.HashSet)17 AbstractGeoServiceTest (ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest)17 ExpressionAnalysisResultSet (ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet)16 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)14 DifferentialExpressionAnalysisResult (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysisResult)12 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)11 GeoDomainObjectGeneratorLocal (ubic.gemma.core.loader.expression.geo.GeoDomainObjectGeneratorLocal)10 AlreadyExistsInSystemException (ubic.gemma.core.loader.util.AlreadyExistsInSystemException)10 Before (org.junit.Before)8 Collection (java.util.Collection)7 ContrastResult (ubic.gemma.model.analysis.expression.diff.ContrastResult)6 AnalysisType (ubic.gemma.core.analysis.expression.diff.DifferentialExpressionAnalyzerServiceImpl.AnalysisType)5 ExperimentalFactorValueObject (ubic.gemma.model.expression.experiment.ExperimentalFactorValueObject)5 InputStream (java.io.InputStream)4