use of ubic.gemma.model.expression.bioAssayData.MeanVarianceRelation in project Gemma by PavlidisLab.
the class MeanVarianceServiceTest method testServiceCreateOneColor.
@Test
public final void testServiceCreateOneColor() {
qt = this.createOrUpdateQt(ScaleType.LOG2);
qt.setIsNormalized(false);
quantitationTypeService.update(qt);
// update ArrayDesign to ONECOLOR
Collection<ArrayDesign> aas = eeService.getArrayDesignsUsed(ee);
assertEquals(1, aas.size());
ArrayDesign des = aas.iterator().next();
des.setTechnologyType(TechnologyType.ONECOLOR);
arrayDesignService.update(des);
// check that ArrayDesign is the right TechnologyType
aas = eeService.getArrayDesignsUsed(ee);
assertEquals(1, aas.size());
des = aas.iterator().next();
assertEquals(TechnologyType.ONECOLOR, des.getTechnologyType());
MeanVarianceRelation mvr = meanVarianceService.create(ee, true);
// convert byte[] to array[]
// warning: order may have changed
double[] means = MeanVarianceServiceTest.bac.byteArrayToDoubles(mvr.getMeans());
double[] variances = MeanVarianceServiceTest.bac.byteArrayToDoubles(mvr.getVariances());
Arrays.sort(means);
Arrays.sort(variances);
// check sizes
int expectedMeanVarianceLength = 75;
// NAs removed
int expectedLowessLength = 75;
assertEquals(expectedMeanVarianceLength, means.length);
assertEquals(expectedMeanVarianceLength, variances.length);
// check results
int idx = 0;
assertEquals(-0.3484, means[idx], 0.0001);
assertEquals(0.001569, variances[idx], 0.0001);
idx = expectedLowessLength - 1;
assertEquals(0.05115, means[idx], 0.0001);
assertEquals(0.12014, variances[idx], 0.0001);
}
use of ubic.gemma.model.expression.bioAssayData.MeanVarianceRelation in project Gemma by PavlidisLab.
the class MeanVarianceServiceTest method testServiceLinearNormalized.
@Test
public final void testServiceLinearNormalized() {
assertEquals(97, ee.getProcessedExpressionDataVectors().size());
MeanVarianceRelation mvr = meanVarianceService.create(ee, true);
// convert byte[] to array[]
// warning: order may have changed
double[] means = MeanVarianceServiceTest.bac.byteArrayToDoubles(mvr.getMeans());
double[] variances = MeanVarianceServiceTest.bac.byteArrayToDoubles(mvr.getVariances());
Arrays.sort(means);
Arrays.sort(variances);
// after filtering
int expectedLength = 97;
assertEquals(expectedLength, means.length);
assertEquals(expectedLength, variances.length);
// duplicate rows removed
expectedLength = 95;
int idx = 0;
assertEquals(-1.9858, means[idx], 0.0001);
assertEquals(0, variances[idx], 0.0001);
idx = expectedLength - 1;
assertEquals(0.02509, means[idx], 0.0001);
assertEquals(0.09943, variances[idx], 0.0001);
}
use of ubic.gemma.model.expression.bioAssayData.MeanVarianceRelation in project Gemma by PavlidisLab.
the class MeanVarianceServiceTest method testServiceCreateTwoColor.
@Test
public final void testServiceCreateTwoColor() {
qt = this.createOrUpdateQt(ScaleType.LOG2);
qt.setIsNormalized(false);
quantitationTypeService.update(qt);
// update ArrayDesign to TWOCOLOR
Collection<ArrayDesign> aas = eeService.getArrayDesignsUsed(ee);
assertEquals(1, aas.size());
ArrayDesign des = aas.iterator().next();
des.setTechnologyType(TechnologyType.TWOCOLOR);
arrayDesignService.update(des);
aclTestUtils.checkHasAcl(des);
// check that ArrayDesign is the right TechnologyType
aas = eeService.getArrayDesignsUsed(ee);
assertEquals(1, aas.size());
des = aas.iterator().next();
assertEquals(TechnologyType.TWOCOLOR, des.getTechnologyType());
MeanVarianceRelation mvr = meanVarianceService.create(ee, true);
aclTestUtils.checkEEAcls(ee);
ee = eeService.thaw(ee);
assertEquals(97, ee.getProcessedExpressionDataVectors().size());
// convert byte[] to array[]
// warning: order may have changed
double[] means = MeanVarianceServiceTest.bac.byteArrayToDoubles(mvr.getMeans());
double[] variances = MeanVarianceServiceTest.bac.byteArrayToDoubles(mvr.getVariances());
Arrays.sort(means);
Arrays.sort(variances);
// after filtering
int expectedLength = 75;
assertEquals(expectedLength, means.length);
assertEquals(expectedLength, variances.length);
int idx = 0;
assertEquals(-0.34836, means[idx], 0.0001);
assertEquals(0.001569, variances[idx], 0.0001);
idx = expectedLength - 1;
assertEquals(0.05115, means[idx], 0.0001);
assertEquals(0.12014, variances[idx], 0.0001);
}
use of ubic.gemma.model.expression.bioAssayData.MeanVarianceRelation in project Gemma by PavlidisLab.
the class MeanVarianceServiceImpl method create.
@Override
public MeanVarianceRelation create(ExpressionExperiment ee, boolean forceRecompute) {
if (ee == null) {
log.warn("Experiment is null");
return null;
}
log.info("Starting mean-variance computation");
MeanVarianceRelation mvr = ee.getMeanVarianceRelation();
if (forceRecompute || mvr == null) {
log.info("Recomputing mean-variance");
ee = expressionExperimentService.thawLiter(ee);
mvr = ee.getMeanVarianceRelation();
ExpressionDataDoubleMatrix intensities = meanVarianceServiceHelper.getIntensities(ee);
if (intensities == null) {
throw new IllegalStateException("Could not locate intensity matrix for " + ee.getShortName());
}
Collection<QuantitationType> qtList = expressionExperimentService.getPreferredQuantitationType(ee);
QuantitationType qt;
if (qtList.size() == 0) {
log.error("Did not find any preferred quantitation type. Mean-variance relation was not computed.");
} else {
qt = qtList.iterator().next();
if (qtList.size() > 1) {
// Really this should be an error condition.
log.warn("Found more than one preferred quantitation type. Only the first preferred quantitation type (" + qt + ") will be used.");
}
try {
intensities = ExpressionDataDoubleMatrixUtil.filterAndLog2Transform(qt, intensities);
} catch (UnknownLogScaleException e) {
log.warn("Problem log transforming data. Check that the appropriate log scale is used. Mean-variance will be computed as is.");
}
mvr = calculateMeanVariance(intensities, mvr);
meanVarianceServiceHelper.createMeanVariance(ee, mvr);
}
}
log.info("Mean-variance computation is complete");
return mvr;
}
use of ubic.gemma.model.expression.bioAssayData.MeanVarianceRelation in project Gemma by PavlidisLab.
the class MeanVarianceServiceTest method testServiceCreateCountData.
@Test
public final void testServiceCreateCountData() throws Exception {
// so it doesn't look for soft files
geoService.setGeoDomainObjectGenerator(new GeoDomainObjectGenerator());
ee = eeService.findByShortName("GSE29006");
if (ee != null) {
eeService.remove(ee);
}
assertNull(eeService.findByShortName("GSE29006"));
try {
Collection<?> results = geoService.fetchAndLoad("GSE29006", false, false, false);
ee = (ExpressionExperiment) results.iterator().next();
} catch (AlreadyExistsInSystemException e) {
throw new IllegalStateException("Need to remove this data set before test is run");
}
ee = eeService.thaw(ee);
qt = this.createOrUpdateQt(ScaleType.COUNT);
// Load the data from a text file.
DoubleMatrixReader reader = new DoubleMatrixReader();
try (InputStream countData = this.getClass().getResourceAsStream("/data/loader/expression/flatfileload/GSE29006_expression_count.test.txt");
InputStream rpkmData = this.getClass().getResourceAsStream("/data/loader/expression/flatfileload/GSE29006_expression_RPKM.test.txt")) {
DoubleMatrix<String, String> countMatrix = reader.read(countData);
DoubleMatrix<String, String> rpkmMatrix = reader.read(rpkmData);
List<String> probeNames = countMatrix.getRowNames();
// we have to find the right generic platform to use.
ArrayDesign targetArrayDesign = this.getTestPersistentArrayDesign(probeNames, taxonService.findByCommonName("human"));
targetArrayDesign = arrayDesignService.thaw(targetArrayDesign);
try {
dataUpdater.addCountData(ee, targetArrayDesign, countMatrix, rpkmMatrix, 36, true, false);
fail("Should have gotten an exception");
} catch (IllegalArgumentException e) {
// Expected
}
dataUpdater.addCountData(ee, targetArrayDesign, countMatrix, rpkmMatrix, 36, true, true);
}
ee = eeService.thaw(this.ee);
assertNotNull(ee.getId());
MeanVarianceRelation mvr = meanVarianceService.create(ee, true);
// convert byte[] to array[]
// warning: order may have changed
double[] means = MeanVarianceServiceTest.bac.byteArrayToDoubles(mvr.getMeans());
double[] variances = MeanVarianceServiceTest.bac.byteArrayToDoubles(mvr.getVariances());
if (means != null) {
Arrays.sort(means);
}
if (variances != null) {
Arrays.sort(variances);
}
// check sizes
int expectedMeanVarianceLength = 199;
// NAs removed
int expectedLowessLength = 197;
assert means != null;
assertEquals(expectedMeanVarianceLength, means.length);
assert variances != null;
assertEquals(expectedMeanVarianceLength, variances.length);
int idx = 0;
assertEquals(1.037011, means[idx], 0.0001);
assertEquals(0.00023724336, variances[idx], 0.000001);
idx = expectedLowessLength - 1;
assertEquals(15.23313, means[idx], 0.0001);
assertEquals(4.84529, variances[idx], 0.0001);
}
Aggregations