Search in sources :

Example 21 with ByteArrayConverter

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

the class MatrixConversionTest method loopVectors.

private long loopVectors(Collection<DesignElementDataVector> vectors, List<CompositeSequence> sequencesb, QuantitationType quantType, BioAssayDimension baDimA, long j, int i2) {
    for (; j < i2; j++) {
        DesignElementDataVector vector = RawExpressionDataVector.Factory.newInstance();
        double[] data = new double[baDimA.getBioAssays().size()];
        for (int k = 0; k < data.length; k++) {
            data[k] = k;
        }
        ByteArrayConverter bconverter = new ByteArrayConverter();
        byte[] bdata = bconverter.doubleArrayToBytes(data);
        vector.setData(bdata);
        CompositeSequence cs = sequencesb.get((int) j);
        vector.setDesignElement(cs);
        vector.setQuantitationType(quantType);
        vector.setBioAssayDimension(baDimA);
        vectors.add(vector);
    }
    return j;
}
Also used : ByteArrayConverter(ubic.basecode.io.ByteArrayConverter) DesignElementDataVector(ubic.gemma.model.expression.bioAssayData.DesignElementDataVector) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence)

Example 22 with ByteArrayConverter

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

the class SimpleExpressionDataLoaderServiceImpl method convertDesignElementDataVectors.

/**
 * @return Collection<DesignElementDataVector>
 */
private Collection<RawExpressionDataVector> convertDesignElementDataVectors(ExpressionExperiment expressionExperiment, BioAssayDimension bioAssayDimension, ArrayDesign arrayDesign, QuantitationType quantitationType, DoubleMatrix<String, String> matrix) {
    ByteArrayConverter bArrayConverter = new ByteArrayConverter();
    Collection<RawExpressionDataVector> vectors = new HashSet<>();
    Map<String, CompositeSequence> csMap = new HashMap<>();
    for (CompositeSequence cs : arrayDesign.getCompositeSequences()) {
        csMap.put(cs.getName(), cs);
    }
    for (int i = 0; i < matrix.rows(); i++) {
        byte[] bdata = bArrayConverter.doubleArrayToBytes(matrix.getRow(i));
        RawExpressionDataVector vector = RawExpressionDataVector.Factory.newInstance();
        vector.setData(bdata);
        CompositeSequence cs = csMap.get(matrix.getRowName(i));
        if (cs == null) {
            continue;
        }
        vector.setDesignElement(cs);
        vector.setQuantitationType(quantitationType);
        vector.setExpressionExperiment(expressionExperiment);
        vector.setBioAssayDimension(bioAssayDimension);
        vectors.add(vector);
    }
    SimpleExpressionDataLoaderServiceImpl.log.info("Created " + vectors.size() + " data vectors");
    return vectors;
}
Also used : ByteArrayConverter(ubic.basecode.io.ByteArrayConverter) RawExpressionDataVector(ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence)

Example 23 with ByteArrayConverter

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

the class DifferentialExpressionResultDaoImpl method loadPvalueDistribution.

@Override
public Histogram loadPvalueDistribution(Long resultSetId) {
    List<?> pvds = this.getHibernateTemplate().findByNamedParam("select rs.pvalueDistribution from ExpressionAnalysisResultSet rs where rs.id=:rsid ", "rsid", resultSetId);
    if (pvds.isEmpty()) {
        return null;
    }
    assert pvds.size() == 1;
    PvalueDistribution pvd = (PvalueDistribution) pvds.get(0);
    ByteArrayConverter bac = new ByteArrayConverter();
    double[] counts = bac.byteArrayToDoubles(pvd.getBinCounts());
    Integer numBins = pvd.getNumBins();
    assert numBins == counts.length;
    Histogram hist = new Histogram(resultSetId.toString(), numBins, 0.0, 1.0);
    for (int i = 0; i < numBins; i++) {
        hist.fill(i, (int) counts[i]);
    }
    return hist;
}
Also used : BigInteger(java.math.BigInteger) Histogram(ubic.basecode.math.distribution.Histogram) ByteArrayConverter(ubic.basecode.io.ByteArrayConverter)

Example 24 with ByteArrayConverter

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

the class ExpressionDataDoubleMatrix method createMatrix.

/**
 * Fill in the data
 *
 * @return DoubleMatrixNamed
 */
private DoubleMatrix<CompositeSequence, BioMaterial> createMatrix(Collection<? extends DesignElementDataVector> vectors, int maxSize) {
    int numRows = this.rowDesignElementMapByInteger.keySet().size();
    DoubleMatrix<CompositeSequence, BioMaterial> mat = new DenseDoubleMatrix<>(numRows, maxSize);
    for (int j = 0; j < mat.columns(); j++) {
        mat.addColumnName(this.getBioMaterialForColumn(j));
    }
    // initialize the matrix to -Infinity; this marks values that are not yet initialized.
    for (int i = 0; i < mat.rows(); i++) {
        for (int j = 0; j < mat.columns(); j++) {
            mat.set(i, j, Double.NEGATIVE_INFINITY);
        }
    }
    ByteArrayConverter bac = new ByteArrayConverter();
    Map<Integer, CompositeSequence> rowNames = new TreeMap<>();
    for (DesignElementDataVector vector : vectors) {
        BioAssayDimension dimension = vector.getBioAssayDimension();
        byte[] bytes = vector.getData();
        CompositeSequence designElement = vector.getDesignElement();
        assert designElement != null : "No design element for " + vector;
        Integer rowIndex = this.rowElementMap.get(designElement);
        assert rowIndex != null;
        rowNames.put(rowIndex, designElement);
        double[] vals = bac.byteArrayToDoubles(bytes);
        Collection<BioAssay> bioAssays = dimension.getBioAssays();
        if (bioAssays.size() != vals.length)
            throw new IllegalStateException("Mismatch: " + vals.length + " values in vector ( " + bytes.length + " bytes) for " + designElement + " got " + bioAssays.size() + " bioassays in the bioAssayDimension");
        Iterator<BioAssay> it = bioAssays.iterator();
        this.setMatBioAssayValues(mat, rowIndex, ArrayUtils.toObject(vals), bioAssays, it);
    }
    /*
         * Note: these row names aren't that important unless we use the bare matrix.
         */
    for (int i = 0; i < mat.rows(); i++) {
        mat.addRowName(rowNames.get(i));
    }
    assert mat.getRowNames().size() == mat.rows();
    // fill in remaining missing values.
    for (int i = 0; i < mat.rows(); i++) {
        for (int j = 0; j < mat.columns(); j++) {
            if (mat.get(i, j) == Double.NEGATIVE_INFINITY) {
                // log.debug( "Missing value at " + i + " " + j );
                mat.set(i, j, Double.NaN);
            }
        }
    }
    ExpressionDataDoubleMatrix.log.debug("Created a " + mat.rows() + " x " + mat.columns() + " matrix");
    return mat;
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) ByteArrayConverter(ubic.basecode.io.ByteArrayConverter) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) BioAssayDimension(ubic.gemma.model.expression.bioAssayData.BioAssayDimension) DenseDoubleMatrix(ubic.basecode.dataStructure.matrix.DenseDoubleMatrix) DesignElementDataVector(ubic.gemma.model.expression.bioAssayData.DesignElementDataVector) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay)

Example 25 with ByteArrayConverter

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

the class ExpressionDataDoubleMatrix method toProcessedDataVectors.

/**
 * @return Convert this to a collection of vectors.
 */
public Collection<ProcessedExpressionDataVector> toProcessedDataVectors() {
    Collection<ProcessedExpressionDataVector> result = new HashSet<>();
    QuantitationType qt = this.getQuantitationTypes().iterator().next();
    ByteArrayConverter bac = new ByteArrayConverter();
    if (this.getQuantitationTypes().size() > 1) {
        throw new UnsupportedOperationException("Cannot convert matrix that has more than one quantitation type");
    }
    for (int i = 0; i < this.rows(); i++) {
        Double[] data = this.getRow(i);
        ProcessedExpressionDataVector v = ProcessedExpressionDataVector.Factory.newInstance();
        v.setBioAssayDimension(this.getBestBioAssayDimension());
        v.setDesignElement(this.getRowNames().get(i));
        v.setQuantitationType(qt);
        v.setData(bac.doubleArrayToBytes(data));
        v.setExpressionExperiment(this.expressionExperiment);
        // we don't fill in the ranks because we only have the mean value here.
        result.add(v);
    }
    return result;
}
Also used : ByteArrayConverter(ubic.basecode.io.ByteArrayConverter) ProcessedExpressionDataVector(ubic.gemma.model.expression.bioAssayData.ProcessedExpressionDataVector) QuantitationType(ubic.gemma.model.common.quantitationtype.QuantitationType)

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