use of ubic.basecode.io.ByteArrayConverter 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;
}
use of ubic.basecode.io.ByteArrayConverter in project Gemma by PavlidisLab.
the class ExpressionExperimentQCController method corrDistFileToPersistent.
/**
* For conversion from legacy system.
*/
private void corrDistFileToPersistent(File file, ExpressionExperiment ee, DoubleArrayList counts) {
log.info("Converting from pvalue distribution file to persistent stored version");
ByteArrayConverter bac = new ByteArrayConverter();
Double[] countArray = (Double[]) counts.toList().toArray(new Double[] {});
byte[] bytes = bac.doubleArrayToBytes(countArray);
CoexpCorrelationDistribution coexpd = CoexpCorrelationDistribution.Factory.newInstance();
coexpd.setNumBins(counts.size());
coexpd.setBinCounts(bytes);
try {
coexpressionAnalysisService.addCoexpCorrelationDistribution(ee, coexpd);
if (file.delete()) {
log.info("Old file deleted");
} else {
log.info("Old file could not be deleted");
}
} catch (Exception e) {
log.info("Could not save the corr dist: " + e.getMessage());
}
}
use of ubic.basecode.io.ByteArrayConverter in project Gemma by PavlidisLab.
the class ExpressionExperimentQCController method getMeanVariance.
/**
* @param mvr MeanVarianceRelation object that contains the datapoints to plot
* @return XYSeriesCollection which contains the Mean-variance and Loess series
*/
private XYSeriesCollection getMeanVariance(MeanVarianceRelation mvr) {
final ByteArrayConverter bac = new ByteArrayConverter();
XYSeriesCollection dataset = new XYSeriesCollection();
if (mvr == null) {
return dataset;
}
double[] means = bac.byteArrayToDoubles(mvr.getMeans());
double[] variances = bac.byteArrayToDoubles(mvr.getVariances());
if (means == null || variances == null) {
return dataset;
}
XYSeries series = new XYSeries("Mean-variance");
for (int i = 0; i < means.length; i++) {
series.add(means[i], variances[i]);
}
dataset.addSeries(series);
return dataset;
}
use of ubic.basecode.io.ByteArrayConverter in project Gemma by PavlidisLab.
the class ExpressionExperimentQCController method getCorrelHist.
/**
* @return JFreeChart XYSeries representing the histogram.
* @throws FileNotFoundException - only if the coexp dist is being read from a file; when migration to db storage is
* complete this can be removed
* @throws IOException - only if the coexp dist is being read from a file; when migration to db storage is complete
* this can be removed
*/
private XYSeries getCorrelHist(ExpressionExperiment ee) throws IOException {
CoexpCorrelationDistribution coexpCorrelationDistribution = coexpressionAnalysisService.getCoexpCorrelationDistribution(ee);
if (coexpCorrelationDistribution == null) {
// try to get it from the file.
return this.getCorrelHistFromFile(ee);
}
XYSeries series = new XYSeries(ee.getId(), true, true);
byte[] binCountsBytes = coexpCorrelationDistribution.getBinCounts();
ByteArrayConverter bac = new ByteArrayConverter();
double[] binCounts = bac.byteArrayToDoubles(binCountsBytes);
Integer numBins = coexpCorrelationDistribution.getNumBins();
double step = 2.0 / numBins;
double lim = -1.0;
for (double d : binCounts) {
series.add(lim, d);
lim += step;
}
return series;
}
use of ubic.basecode.io.ByteArrayConverter in project Gemma by PavlidisLab.
the class TwoChannelMissingValuesImpl method computeMissingValues.
/**
* Attempt to compute 'missing value' information for a two-channel data set. We attempt to do this even if we are
* missing background intensity information or one intensity channel, though obviously it is better to have all four
* sets of values.
*
* @param bkgChannelA background channel A
* @param bkgChannelB background channel B
* @param extraMissingValueIndicators extra missing value indicators
* @param preferred preferred matrix
* @param signalChannelA signal channel A
* @param signalChannelB signal channel B
* @param signalToNoiseThreshold noise threshold
* @param source the source
* @return DesignElementDataVectors corresponding to a new PRESENTCALL quantitation type for the design elements and
* biomaterial dimension represented in the inputs.
*/
private Collection<RawExpressionDataVector> computeMissingValues(ExpressionExperiment source, ExpressionDataDoubleMatrix preferred, ExpressionDataDoubleMatrix signalChannelA, ExpressionDataDoubleMatrix signalChannelB, ExpressionDataDoubleMatrix bkgChannelA, ExpressionDataDoubleMatrix bkgChannelB, double signalToNoiseThreshold, Collection<Double> extraMissingValueIndicators) {
boolean okToProceed = this.validate(preferred, signalChannelA, signalChannelB, bkgChannelA, bkgChannelB, signalToNoiseThreshold);
Collection<RawExpressionDataVector> results = new HashSet<>();
if (!okToProceed) {
TwoChannelMissingValuesImpl.log.warn("Missing value computation cannot proceed");
return results;
}
ByteArrayConverter converter = new ByteArrayConverter();
int count = 0;
ExpressionDataDoubleMatrix baseChannel = signalChannelA == null ? signalChannelB : signalChannelA;
Double signalThreshold = Double.NaN;
if (bkgChannelA == null && bkgChannelB == null) {
signalThreshold = this.computeSignalThreshold(preferred, signalChannelA, signalChannelB, baseChannel);
}
QuantitationType present = this.getMissingDataQuantitationType(signalToNoiseThreshold, signalThreshold);
source.getQuantitationTypes().add(present);
for (ExpressionDataMatrixRowElement element : baseChannel.getRowElements()) {
count = this.examineVector(source, preferred, signalChannelA, signalChannelB, bkgChannelA, bkgChannelB, signalToNoiseThreshold, extraMissingValueIndicators, results, converter, count, baseChannel, signalThreshold, present, element);
}
TwoChannelMissingValuesImpl.log.info("Finished: " + count + " vectors examined for missing values");
results = twoChannelMissingValueHelperService.persist(source, results);
return results;
}
Aggregations