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()));
}
}
}
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());
}
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"));
}
}
}
}
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());
}
}
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;
}
Aggregations