Search in sources :

Example 31 with DesignElementDataVector

use of ubic.gemma.model.expression.bioAssayData.DesignElementDataVector 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 32 with DesignElementDataVector

use of ubic.gemma.model.expression.bioAssayData.DesignElementDataVector in project Gemma by PavlidisLab.

the class ExpressionDataDoubleMatrix method vectorsToMatrix.

/**
 * Convert {@link DesignElementDataVector}s into Double matrix.
 */
@Override
protected void vectorsToMatrix(Collection<? extends DesignElementDataVector> vectors) {
    if (vectors == null || vectors.size() == 0) {
        throw new IllegalArgumentException("No vectors!");
    }
    for (DesignElementDataVector vector : vectors) {
        if (vector instanceof ProcessedExpressionDataVector) {
            this.ranks.put(vector.getDesignElement(), ((ProcessedExpressionDataVector) vector).getRankByMean());
        }
    }
    int maxSize = this.setUpColumnElements();
    this.matrix = this.createMatrix(vectors, maxSize);
}
Also used : ProcessedExpressionDataVector(ubic.gemma.model.expression.bioAssayData.ProcessedExpressionDataVector) DesignElementDataVector(ubic.gemma.model.expression.bioAssayData.DesignElementDataVector)

Example 33 with DesignElementDataVector

use of ubic.gemma.model.expression.bioAssayData.DesignElementDataVector in project Gemma by PavlidisLab.

the class ExpressionDataBooleanMatrix method createMatrix.

/**
 * Fill in the data
 */
private ObjectMatrixImpl<CompositeSequence, Integer, Boolean> createMatrix(Collection<? extends DesignElementDataVector> vectors, int maxSize) {
    ObjectMatrixImpl<CompositeSequence, Integer, Boolean> mat = new ObjectMatrixImpl<>(vectors.size(), maxSize);
    // initialize the matrix to false
    for (int i = 0; i < mat.rows(); i++) {
        for (int j = 0; j < mat.columns(); j++) {
            mat.set(i, j, Boolean.FALSE);
        }
    }
    for (int j = 0; j < mat.columns(); j++) {
        mat.addColumnName(j);
    }
    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();
        Integer rowIndex = this.rowElementMap.get(designElement);
        assert rowIndex != null;
        rowNames.put(rowIndex, designElement);
        boolean[] vals = this.getVals(bac, vector, bytes);
        Collection<BioAssay> bioAssays = dimension.getBioAssays();
        if (bioAssays.size() != vals.length) {
            throw new IllegalStateException("Expected " + vals.length + " bioassays at design element " + designElement + ", got " + bioAssays.size());
        }
        Iterator<BioAssay> it = bioAssays.iterator();
        this.setMatBioAssayValues(mat, rowIndex, ArrayUtils.toObject(vals), bioAssays, it);
    }
    for (int i = 0; i < mat.rows(); i++) {
        mat.addRowName(rowNames.get(i));
    }
    assert mat.getRowNames().size() == mat.rows();
    return mat;
}
Also used : ByteArrayConverter(ubic.basecode.io.ByteArrayConverter) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) BioAssayDimension(ubic.gemma.model.expression.bioAssayData.BioAssayDimension) ObjectMatrixImpl(ubic.basecode.dataStructure.matrix.ObjectMatrixImpl) DesignElementDataVector(ubic.gemma.model.expression.bioAssayData.DesignElementDataVector) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay)

Aggregations

DesignElementDataVector (ubic.gemma.model.expression.bioAssayData.DesignElementDataVector)33 QuantitationType (ubic.gemma.model.common.quantitationtype.QuantitationType)18 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)18 BioAssayDimension (ubic.gemma.model.expression.bioAssayData.BioAssayDimension)15 ByteArrayConverter (ubic.basecode.io.ByteArrayConverter)9 StandardQuantitationType (ubic.gemma.model.common.quantitationtype.StandardQuantitationType)9 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)8 RawExpressionDataVector (ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector)6 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)5 ProcessedExpressionDataVector (ubic.gemma.model.expression.bioAssayData.ProcessedExpressionDataVector)5 Collection (java.util.Collection)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Test (org.junit.Test)2 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)2 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)2 InputStream (java.io.InputStream)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 StopWatch (org.apache.commons.lang3.time.StopWatch)1 DetachedCriteria (org.hibernate.criterion.DetachedCriteria)1