use of ubic.gemma.model.expression.bioAssayData.MeanVarianceRelation in project Gemma by PavlidisLab.
the class MeanVarianceServiceTest method testServiceCreateExistingEe.
@Test
public final void testServiceCreateExistingEe() {
// no MeanVarianceRelation exists yet
ee = eeService.load(ee.getId());
assertNotNull(ee.getId());
MeanVarianceRelation oldMvr = ee.getMeanVarianceRelation();
assertNull(oldMvr);
Long oldEeId = ee.getId();
// first time we create a MeanVarianceRelation
ee = eeService.load(ee.getId());
MeanVarianceRelation mvr = meanVarianceService.create(ee, true);
assertEquals(oldEeId, ee.getId());
assertNotNull(mvr);
oldMvr = mvr;
// now that the MeanVarianceRelation exists
// try loading ee again by just using an eeId
// and see if we get a no Session error
ee = eeService.load(ee.getId());
mvr = meanVarianceService.create(ee, true);
assertEquals(oldEeId, ee.getId());
assertTrue(oldMvr != mvr);
}
use of ubic.gemma.model.expression.bioAssayData.MeanVarianceRelation in project Gemma by PavlidisLab.
the class ExpressionExperimentQCController method removeMVOutliers.
/**
* Remove outliers from the MeanVarianceRelation by removing those points which have: (zscore(mean) > zscoreMax ||
* zscore(variance) > zscoreMax)
*/
@SuppressWarnings("unused")
private MeanVarianceRelation removeMVOutliers(MeanVarianceRelation mvr, double zscoreMax) {
MeanVarianceRelation ret = MeanVarianceRelation.Factory.newInstance();
ByteArrayConverter bac = new ByteArrayConverter();
DoubleArrayList vars = new DoubleArrayList(bac.byteArrayToDoubles(mvr.getVariances()));
DoubleArrayList means = new DoubleArrayList(bac.byteArrayToDoubles(mvr.getMeans()));
DoubleArrayList filteredMeans = new DoubleArrayList();
DoubleArrayList filteredVars = new DoubleArrayList();
DoubleArrayList zVars = this.zscore(vars);
DoubleArrayList zMeans = this.zscore(means);
// clip outliers
for (int i = 0; i < zMeans.size(); i++) {
if (Math.abs(zMeans.getQuick(i)) > zscoreMax || Math.abs(zVars.getQuick(i)) > zscoreMax) {
continue;
}
filteredMeans.add(means.getQuick(i));
filteredVars.add(vars.getQuick(i));
}
log.debug(filteredMeans.size() + " (out of " + means.size() + ") MV points had mean or variance zscore < " + zscoreMax + ". Max mean,variance is ( " + Descriptive.max(filteredMeans) + "," + Descriptive.max(filteredVars) + ").");
ret.setVariances(bac.doubleArrayToBytes(filteredVars));
ret.setMeans(bac.doubleArrayToBytes(filteredMeans));
return ret;
}
use of ubic.gemma.model.expression.bioAssayData.MeanVarianceRelation in project Gemma by PavlidisLab.
the class ExpressionExperimentQCController method visualizeMeanVariance.
/**
* @param id of experiment
* @param size Multiplier on the cell size. 1 or null for standard small size.
* @param text if true, output a tabbed file instead of a png
* @param os response output stream
* @return ModelAndView object if text is true, otherwise null
*/
@RequestMapping("/expressionExperiment/visualizeMeanVariance.html")
public ModelAndView visualizeMeanVariance(Long id, Double size, Boolean text, OutputStream os) throws Exception {
if (id == null) {
log.warn("No id!");
return null;
}
ExpressionExperiment ee = expressionExperimentService.load(id);
if (ee == null) {
log.warn("Could not load experiment with id " + id);
return null;
}
MeanVarianceRelation mvr = meanVarianceService.find(ee);
if (mvr == null) {
return null;
}
if (text != null && text) {
final ByteArrayConverter bac = new ByteArrayConverter();
double[] means = bac.byteArrayToDoubles(mvr.getMeans());
double[] variances = bac.byteArrayToDoubles(mvr.getVariances());
DoubleMatrix2D matrix = new DenseDoubleMatrix2D(means.length, 2);
matrix.viewColumn(0).assign(means);
matrix.viewColumn(1).assign(variances);
String matrixString = new Formatter("%1.2G").toTitleString(matrix, null, new String[] { "mean", "variance" }, null, null, null, null);
ModelAndView mav = new ModelAndView(new TextView());
mav.addObject(TextView.TEXT_PARAM, matrixString);
return mav;
}
this.writeMeanVariance(os, mvr, size);
return null;
}
Aggregations