Search in sources :

Example 36 with FactorValue

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

the class ExperimentalDesignImporterTest method checkResults.

private void checkResults(Collection<BioMaterial> bms) {
    // check.
    assertEquals(4, ee.getExperimentalDesign().getExperimentalFactors().size());
    boolean foundpmi = false;
    Collection<Long> seenFactorValueIds = new HashSet<>();
    for (ExperimentalFactor ef : ee.getExperimentalDesign().getExperimentalFactors()) {
        if (ef.getName().equals("Profile")) {
            assertEquals(FactorType.CATEGORICAL, ef.getType());
            assertEquals(2, ef.getFactorValues().size());
        } else if (ef.getName().equals("PMI (h)")) {
            assertEquals(FactorType.CONTINUOUS, ef.getType());
            assertEquals(8, ef.getFactorValues().size());
        }
        for (FactorValue fv : ef.getFactorValues()) {
            ExperimentalDesignImporterTest.assertFv(fv);
            if (fv.getExperimentalFactor().getName().equals("PMI (h)")) {
                foundpmi = true;
                // continuous
                assertNotNull(fv.getMeasurement());
            }
            seenFactorValueIds.add(fv.getId());
        }
    }
    assertTrue(foundpmi);
    for (BioMaterial bm : bms) {
        assertEquals(4, bm.getFactorValues().size());
        for (FactorValue fv : bm.getFactorValues()) {
            assertTrue(seenFactorValueIds.contains(fv.getId()));
        }
    }
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) FactorValue(ubic.gemma.model.expression.experiment.FactorValue) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) HashSet(java.util.HashSet)

Example 37 with FactorValue

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

the class ExperimentalDesignImporterTestC method testUploadBadDesign.

@Test
public final void testUploadBadDesign() throws Exception {
    /*
         * The following file has a bug in it. It should fail.
         */
    try (InputStream is = this.getClass().getResourceAsStream("/data/loader/expression/geo/designLoadTests/annotationLoadFileBrain2003FirstBadFile.txt")) {
        try {
            // dry run, should fail.
            experimentalDesignImporter.importDesign(ee, is);
            fail("Should have gotten an error when loading a bad file");
        } catch (IOException ok) {
        // ok
        }
        is.close();
    }
    /*
         * make sure we didn't load anything
         */
    ee = this.expressionExperimentService.load(ee.getId());
    ee = expressionExperimentService.thawLite(ee);
    assertEquals(0, ee.getExperimentalDesign().getExperimentalFactors().size());
    /*
         * Now try the good one.
         */
    try (InputStream is = this.getClass().getResourceAsStream("/data/loader/expression/geo/designLoadTests/annotationLoadFileBrain2003SecondGoodFile.txt")) {
        // dry run, should pass
        experimentalDesignImporter.importDesign(ee, is);
    }
    /*
         * Reopen the file.
         */
    try (InputStream is = this.getClass().getResourceAsStream("/data/loader/expression/geo/designLoadTests/annotationLoadFileBrain2003SecondGoodFile.txt")) {
        // not a dry run, should pass.
        experimentalDesignImporter.importDesign(ee, is);
    }
    ee = this.expressionExperimentService.load(ee.getId());
    this.aclTestUtils.checkEEAcls(ee);
    ee = expressionExperimentService.thawLite(ee);
    assertEquals(3, ee.getExperimentalDesign().getExperimentalFactors().size());
    for (BioAssay ba : ee.getBioAssays()) {
        // noinspection ResultOfMethodCallIgnored // Checking if accessible
        ba.getSampleUsed();
    }
    this.checkResults();
    int s = ee.getExperimentalDesign().getExperimentalFactors().size();
    ExperimentalFactor toDelete = ee.getExperimentalDesign().getExperimentalFactors().iterator().next();
    for (BioAssay ba : ee.getBioAssays()) {
        BioMaterial bm = ba.getSampleUsed();
        boolean removed = false;
        for (Iterator<FactorValue> fIt = bm.getFactorValues().iterator(); fIt.hasNext(); ) {
            if (fIt.next().getExperimentalFactor().equals(toDelete)) {
                fIt.remove();
                removed = true;
            }
        }
        if (removed) {
            bioMaterialService.update(bm);
        }
    }
    ee.getExperimentalDesign().getExperimentalFactors().remove(toDelete);
    experimentalFactorService.delete(toDelete);
    experimentalDesignService.update(ee.getExperimentalDesign());
    assertEquals(s - 1, ee.getExperimentalDesign().getExperimentalFactors().size());
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) FactorValue(ubic.gemma.model.expression.experiment.FactorValue) InputStream(java.io.InputStream) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) IOException(java.io.IOException) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay) AbstractGeoServiceTest(ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest) Test(org.junit.Test)

Example 38 with FactorValue

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

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

the class BaselineDetectionTest method testFetchAndLoadGSE18162.

@Test
public void testFetchAndLoadGSE18162() {
    Map<ExperimentalFactor, FactorValue> baselineLevels = ExpressionDataMatrixColumnSort.getBaselineLevels(ee.getExperimentalDesign().getExperimentalFactors());
    // the batch DOES get a baseline. IF we change that then we change
    assertEquals(2, baselineLevels.size());
    // this test.
    for (ExperimentalFactor ef : baselineLevels.keySet()) {
        if (ef.getName().equals(ExperimentalFactorService.BATCH_FACTOR_NAME))
            continue;
        FactorValue fv = baselineLevels.get(ef);
        assertEquals("Control_group", fv.getValue());
    }
}
Also used : FactorValue(ubic.gemma.model.expression.experiment.FactorValue) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) AbstractGeoServiceTest(ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest) Test(org.junit.Test)

Example 40 with FactorValue

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

the class DifferentialExpressionAnalysisUtil method filterFactorValuesFromBiomaterials.

/**
 * Returns biomaterials with 'filtered' factor values. That is, each biomaterial will only contain those factor
 * values equivalent to a factor value from one of the input experimental factors.
 *
 * @return Collection<BioMaterial>
 */
private static Collection<BioMaterial> filterFactorValuesFromBiomaterials(Collection<ExperimentalFactor> factors, Collection<BioMaterial> biomaterials) {
    assert !biomaterials.isEmpty();
    assert !factors.isEmpty();
    Collection<FactorValue> allFactorValuesFromGivenFactors = new HashSet<>();
    for (ExperimentalFactor ef : factors) {
        allFactorValuesFromGivenFactors.addAll(ef.getFactorValues());
    }
    Collection<BioMaterial> biomaterialsWithGivenFactorValues = new HashSet<>();
    int numHaveAny = 0;
    for (BioMaterial b : biomaterials) {
        Collection<FactorValue> biomaterialFactorValues = b.getFactorValues();
        Collection<FactorValue> factorValuesToConsider = new HashSet<>(biomaterialFactorValues);
        for (FactorValue biomaterialFactorValue : biomaterialFactorValues) {
            numHaveAny++;
            if (!allFactorValuesFromGivenFactors.contains(biomaterialFactorValue)) {
                factorValuesToConsider.remove(biomaterialFactorValue);
            }
        }
        b.setFactorValues(factorValuesToConsider);
        biomaterialsWithGivenFactorValues.add(b);
    }
    if (numHaveAny == 0) {
        throw new IllegalStateException("No biomaterials had any factor values");
    }
    return biomaterialsWithGivenFactorValues;
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) FactorValue(ubic.gemma.model.expression.experiment.FactorValue) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor)

Aggregations

FactorValue (ubic.gemma.model.expression.experiment.FactorValue)55 ExperimentalFactor (ubic.gemma.model.expression.experiment.ExperimentalFactor)30 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)27 Test (org.junit.Test)12 VocabCharacteristic (ubic.gemma.model.common.description.VocabCharacteristic)8 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)8 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)8 HashSet (java.util.HashSet)7 Characteristic (ubic.gemma.model.common.description.Characteristic)6 DifferentialExpressionAnalysis (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis)5 ArrayList (java.util.ArrayList)4 AbstractGeoServiceTest (ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest)4 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)4 FactorValueValueObject (ubic.gemma.model.expression.experiment.FactorValueValueObject)4 StopWatch (org.apache.commons.lang3.time.StopWatch)3 DifferentialExpressionAnalysisResult (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysisResult)3 ExpressionAnalysisResultSet (ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet)3 AnnotationValueObject (ubic.gemma.model.common.description.AnnotationValueObject)3 Measurement (ubic.gemma.model.common.measurement.Measurement)3 BioAssaySet (ubic.gemma.model.expression.experiment.BioAssaySet)3