Search in sources :

Example 6 with MeanVarianceRelation

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);
}
Also used : MeanVarianceRelation(ubic.gemma.model.expression.bioAssayData.MeanVarianceRelation) AbstractGeoServiceTest(ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest) Test(org.junit.Test)

Example 7 with MeanVarianceRelation

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;
}
Also used : ByteArrayConverter(ubic.basecode.io.ByteArrayConverter) MeanVarianceRelation(ubic.gemma.model.expression.bioAssayData.MeanVarianceRelation) DoubleArrayList(cern.colt.list.DoubleArrayList)

Example 8 with MeanVarianceRelation

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;
}
Also used : ByteArrayConverter(ubic.basecode.io.ByteArrayConverter) DoubleMatrix2D(cern.colt.matrix.DoubleMatrix2D) DenseDoubleMatrix2D(cern.colt.matrix.impl.DenseDoubleMatrix2D) Formatter(cern.colt.matrix.doublealgo.Formatter) ModelAndView(org.springframework.web.servlet.ModelAndView) MeanVarianceRelation(ubic.gemma.model.expression.bioAssayData.MeanVarianceRelation) TextView(ubic.gemma.web.view.TextView) DenseDoubleMatrix2D(cern.colt.matrix.impl.DenseDoubleMatrix2D) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

MeanVarianceRelation (ubic.gemma.model.expression.bioAssayData.MeanVarianceRelation)8 Test (org.junit.Test)5 AbstractGeoServiceTest (ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest)5 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)3 ByteArrayConverter (ubic.basecode.io.ByteArrayConverter)2 DoubleArrayList (cern.colt.list.DoubleArrayList)1 DoubleMatrix2D (cern.colt.matrix.DoubleMatrix2D)1 Formatter (cern.colt.matrix.doublealgo.Formatter)1 DenseDoubleMatrix2D (cern.colt.matrix.impl.DenseDoubleMatrix2D)1 InputStream (java.io.InputStream)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1 DoubleMatrixReader (ubic.basecode.io.reader.DoubleMatrixReader)1 ExpressionDataDoubleMatrix (ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix)1 GeoDomainObjectGenerator (ubic.gemma.core.loader.expression.geo.GeoDomainObjectGenerator)1 AlreadyExistsInSystemException (ubic.gemma.core.loader.util.AlreadyExistsInSystemException)1 QuantitationType (ubic.gemma.model.common.quantitationtype.QuantitationType)1 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)1 TextView (ubic.gemma.web.view.TextView)1