use of ubic.basecode.dataStructure.matrix.IntegerMatrix in project Gemma by PavlidisLab.
the class ExpressionDataIntegerMatrix method createMatrix.
/**
* Fill in the data
*
* @return DoubleMatrixNamed
*/
private IntegerMatrix<CompositeSequence, Integer> createMatrix(Collection<? extends DesignElementDataVector> vectors, int maxSize) {
int numRows = this.rowDesignElementMapByInteger.keySet().size();
IntegerMatrix<CompositeSequence, Integer> mat = new IntegerMatrix<>(numRows, maxSize);
for (int j = 0; j < mat.columns(); j++) {
mat.addColumnName(j);
}
// initialize the matrix to 0
for (int i = 0; i < mat.rows(); i++) {
for (int j = 0; j < mat.columns(); j++) {
mat.set(i, j, 0);
}
}
ByteArrayConverter bac = new ByteArrayConverter();
Map<Integer, CompositeSequence> rowNames = new TreeMap<>();
for (DesignElementDataVector vector : vectors) {
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);
byte[] bytes = vector.getData();
int[] vals = bac.byteArrayToInts(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();
this.setMatBioAssayValues(mat, rowIndex, ArrayUtils.toObject(vals), bioAssays, it);
}
for (int i = 0; i < mat.rows(); i++) {
mat.addRowName(rowNames.get(i));
}
ExpressionDataIntegerMatrix.log.debug("Created a " + mat.rows() + " x " + mat.columns() + " matrix");
return mat;
}
Aggregations