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;
}
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);
}
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;
}
Aggregations