Search in sources :

Example 31 with ByteArrayConverter

use of ubic.basecode.io.ByteArrayConverter 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 32 with ByteArrayConverter

use of ubic.basecode.io.ByteArrayConverter 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

ByteArrayConverter (ubic.basecode.io.ByteArrayConverter)32 BioAssayDimension (ubic.gemma.model.expression.bioAssayData.BioAssayDimension)11 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)11 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)10 DesignElementDataVector (ubic.gemma.model.expression.bioAssayData.DesignElementDataVector)9 RawExpressionDataVector (ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector)6 ProcessedExpressionDataVector (ubic.gemma.model.expression.bioAssayData.ProcessedExpressionDataVector)5 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)5 Test (org.junit.Test)4 QuantitationType (ubic.gemma.model.common.quantitationtype.QuantitationType)4 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)4 DoubleArrayList (cern.colt.list.DoubleArrayList)3 Transactional (org.springframework.transaction.annotation.Transactional)3 AbstractGeoServiceTest (ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest)3 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 XYSeries (org.jfree.data.xy.XYSeries)2