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