use of ubic.basecode.dataStructure.matrix.StringMatrix 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;
}
Aggregations