Search in sources :

Example 11 with ByteArrayConverter

use of ubic.basecode.io.ByteArrayConverter in project Gemma by PavlidisLab.

the class ExpressionDataStringMatrix method createMatrix.

private StringMatrix<Integer, Integer> createMatrix(Collection<? extends DesignElementDataVector> vectors, int maxSize) {
    int numRows = this.rowDesignElementMapByInteger.keySet().size();
    StringMatrix<Integer, Integer> mat = new StringMatrix<>(numRows, maxSize);
    for (int j = 0; j < mat.columns(); j++) {
        mat.addColumnName(j);
    }
    // initialize the matrix to "";
    for (int i = 0; i < mat.rows(); i++) {
        for (int j = 0; j < mat.columns(); j++) {
            mat.set(i, j, "");
        }
    }
    ByteArrayConverter bac = new ByteArrayConverter();
    for (DesignElementDataVector vector : vectors) {
        CompositeSequence designElement = vector.getDesignElement();
        assert designElement != null : "No designelement for " + vector;
        Integer rowIndex = this.rowElementMap.get(designElement);
        assert rowIndex != null;
        mat.addRowName(rowIndex);
        byte[] bytes = vector.getData();
        String[] vals = bac.byteArrayToStrings(bytes);
        BioAssayDimension dimension = vector.getBioAssayDimension();
        Collection<BioAssay> bioAssays = dimension.getBioAssays();
        assert bioAssays.size() == vals.length : "Expected " + vals.length + " got " + bioAssays.size();
        Iterator<BioAssay> it = bioAssays.iterator();
        for (int j = 0; j < bioAssays.size(); j++) {
            BioAssay bioAssay = it.next();
            Integer column = this.columnAssayMap.get(bioAssay);
            assert column != null;
            mat.setByKeys(rowIndex, column, vals[j]);
        }
    }
    ExpressionDataStringMatrix.log.debug("Created a " + mat.rows() + " x " + mat.columns() + " matrix");
    return mat;
}
Also used : ByteArrayConverter(ubic.basecode.io.ByteArrayConverter) StringMatrix(ubic.basecode.dataStructure.matrix.StringMatrix) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) BioAssayDimension(ubic.gemma.model.expression.bioAssayData.BioAssayDimension) DesignElementDataVector(ubic.gemma.model.expression.bioAssayData.DesignElementDataVector) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay)

Example 12 with ByteArrayConverter

use of ubic.basecode.io.ByteArrayConverter in project Gemma by PavlidisLab.

the class ExpressionExperimentQCController method corrDistFileToPersistent.

/**
 * For conversion from legacy system.
 */
private void corrDistFileToPersistent(File file, ExpressionExperiment ee, DoubleArrayList counts) {
    log.info("Converting from pvalue distribution file to persistent stored version");
    ByteArrayConverter bac = new ByteArrayConverter();
    Double[] countArray = (Double[]) counts.toList().toArray(new Double[] {});
    byte[] bytes = bac.doubleArrayToBytes(countArray);
    CoexpCorrelationDistribution coexpd = CoexpCorrelationDistribution.Factory.newInstance();
    coexpd.setNumBins(counts.size());
    coexpd.setBinCounts(bytes);
    try {
        coexpressionAnalysisService.addCoexpCorrelationDistribution(ee, coexpd);
        if (file.delete()) {
            log.info("Old file deleted");
        } else {
            log.info("Old file could not be deleted");
        }
    } catch (Exception e) {
        log.info("Could not save the corr dist: " + e.getMessage());
    }
}
Also used : CoexpCorrelationDistribution(ubic.gemma.model.analysis.expression.coexpression.CoexpCorrelationDistribution) ByteArrayConverter(ubic.basecode.io.ByteArrayConverter)

Example 13 with ByteArrayConverter

use of ubic.basecode.io.ByteArrayConverter in project Gemma by PavlidisLab.

the class ExpressionExperimentQCController method getMeanVariance.

/**
 * @param mvr MeanVarianceRelation object that contains the datapoints to plot
 * @return XYSeriesCollection which contains the Mean-variance and Loess series
 */
private XYSeriesCollection getMeanVariance(MeanVarianceRelation mvr) {
    final ByteArrayConverter bac = new ByteArrayConverter();
    XYSeriesCollection dataset = new XYSeriesCollection();
    if (mvr == null) {
        return dataset;
    }
    double[] means = bac.byteArrayToDoubles(mvr.getMeans());
    double[] variances = bac.byteArrayToDoubles(mvr.getVariances());
    if (means == null || variances == null) {
        return dataset;
    }
    XYSeries series = new XYSeries("Mean-variance");
    for (int i = 0; i < means.length; i++) {
        series.add(means[i], variances[i]);
    }
    dataset.addSeries(series);
    return dataset;
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) ByteArrayConverter(ubic.basecode.io.ByteArrayConverter) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection)

Example 14 with ByteArrayConverter

use of ubic.basecode.io.ByteArrayConverter in project Gemma by PavlidisLab.

the class ExpressionExperimentQCController method getCorrelHist.

/**
 * @return JFreeChart XYSeries representing the histogram.
 * @throws FileNotFoundException - only if the coexp dist is being read from a file; when migration to db storage is
 *                               complete this can be removed
 * @throws IOException           - only if the coexp dist is being read from a file; when migration to db storage is complete
 *                               this can be removed
 */
private XYSeries getCorrelHist(ExpressionExperiment ee) throws IOException {
    CoexpCorrelationDistribution coexpCorrelationDistribution = coexpressionAnalysisService.getCoexpCorrelationDistribution(ee);
    if (coexpCorrelationDistribution == null) {
        // try to get it from the file.
        return this.getCorrelHistFromFile(ee);
    }
    XYSeries series = new XYSeries(ee.getId(), true, true);
    byte[] binCountsBytes = coexpCorrelationDistribution.getBinCounts();
    ByteArrayConverter bac = new ByteArrayConverter();
    double[] binCounts = bac.byteArrayToDoubles(binCountsBytes);
    Integer numBins = coexpCorrelationDistribution.getNumBins();
    double step = 2.0 / numBins;
    double lim = -1.0;
    for (double d : binCounts) {
        series.add(lim, d);
        lim += step;
    }
    return series;
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) CoexpCorrelationDistribution(ubic.gemma.model.analysis.expression.coexpression.CoexpCorrelationDistribution) ByteArrayConverter(ubic.basecode.io.ByteArrayConverter)

Example 15 with ByteArrayConverter

use of ubic.basecode.io.ByteArrayConverter in project Gemma by PavlidisLab.

the class TwoChannelMissingValuesImpl method computeMissingValues.

/**
 * Attempt to compute 'missing value' information for a two-channel data set. We attempt to do this even if we are
 * missing background intensity information or one intensity channel, though obviously it is better to have all four
 * sets of values.
 *
 * @param bkgChannelA                 background channel A
 * @param bkgChannelB                 background channel B
 * @param extraMissingValueIndicators extra missing value indicators
 * @param preferred                   preferred matrix
 * @param signalChannelA              signal channel A
 * @param signalChannelB              signal channel B
 * @param signalToNoiseThreshold      noise threshold
 * @param source                      the source
 * @return DesignElementDataVectors corresponding to a new PRESENTCALL quantitation type for the design elements and
 * biomaterial dimension represented in the inputs.
 */
private Collection<RawExpressionDataVector> computeMissingValues(ExpressionExperiment source, ExpressionDataDoubleMatrix preferred, ExpressionDataDoubleMatrix signalChannelA, ExpressionDataDoubleMatrix signalChannelB, ExpressionDataDoubleMatrix bkgChannelA, ExpressionDataDoubleMatrix bkgChannelB, double signalToNoiseThreshold, Collection<Double> extraMissingValueIndicators) {
    boolean okToProceed = this.validate(preferred, signalChannelA, signalChannelB, bkgChannelA, bkgChannelB, signalToNoiseThreshold);
    Collection<RawExpressionDataVector> results = new HashSet<>();
    if (!okToProceed) {
        TwoChannelMissingValuesImpl.log.warn("Missing value computation cannot proceed");
        return results;
    }
    ByteArrayConverter converter = new ByteArrayConverter();
    int count = 0;
    ExpressionDataDoubleMatrix baseChannel = signalChannelA == null ? signalChannelB : signalChannelA;
    Double signalThreshold = Double.NaN;
    if (bkgChannelA == null && bkgChannelB == null) {
        signalThreshold = this.computeSignalThreshold(preferred, signalChannelA, signalChannelB, baseChannel);
    }
    QuantitationType present = this.getMissingDataQuantitationType(signalToNoiseThreshold, signalThreshold);
    source.getQuantitationTypes().add(present);
    for (ExpressionDataMatrixRowElement element : baseChannel.getRowElements()) {
        count = this.examineVector(source, preferred, signalChannelA, signalChannelB, bkgChannelA, bkgChannelB, signalToNoiseThreshold, extraMissingValueIndicators, results, converter, count, baseChannel, signalThreshold, present, element);
    }
    TwoChannelMissingValuesImpl.log.info("Finished: " + count + " vectors examined for missing values");
    results = twoChannelMissingValueHelperService.persist(source, results);
    return results;
}
Also used : ExpressionDataMatrixRowElement(ubic.gemma.core.datastructure.matrix.ExpressionDataMatrixRowElement) ByteArrayConverter(ubic.basecode.io.ByteArrayConverter) RawExpressionDataVector(ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector) ExpressionDataDoubleMatrix(ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix) HashSet(java.util.HashSet)

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