use of ubic.gemma.model.expression.bioAssay.BioAssay in project Gemma by PavlidisLab.
the class ExpressionDataDoubleMatrix method toString.
@Override
public String toString() {
int columns = this.columns();
int rows = this.rows();
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(4);
StringBuilder buf = new StringBuilder();
if (rows <= ExpressionDataDoubleMatrix.MAX_ROWS_TO_STRING) {
buf.append(rows).append(" x ").append(columns).append(" matrix of double values\n");
} else {
buf.append(rows).append(" x ").append(columns).append(" matrix of double values, showing up to ").append(ExpressionDataDoubleMatrix.MAX_ROWS_TO_STRING).append(" rows\n");
}
int stop = 0;
buf.append("Probe");
for (int i = 0; i < columns; i++) {
buf.append("\t").append(this.getBioMaterialForColumn(i).getName()).append(":");
for (BioAssay ba : this.getBioAssaysForColumn(i)) {
buf.append(ba.getName()).append(",");
}
}
buf.append("\n");
for (int j = 0; j < rows; j++) {
buf.append(this.rowDesignElementMapByInteger.get(j).getName());
for (int i = 0; i < columns; i++) {
Double val = this.get(j, i);
if (Double.isNaN(val)) {
buf.append("\t").append(val);
} else {
buf.append("\t").append(nf.format(this.get(j, i)));
}
}
buf.append("\n");
if (stop++ > ExpressionDataDoubleMatrix.MAX_ROWS_TO_STRING) {
buf.append("\n(Stopping after " + ExpressionDataDoubleMatrix.MAX_ROWS_TO_STRING + " rows) ...\n");
break;
}
}
return buf.toString();
}
use of ubic.gemma.model.expression.bioAssay.BioAssay 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;
}
use of ubic.gemma.model.expression.bioAssay.BioAssay in project Gemma by PavlidisLab.
the class ExpressionDataMatrixColumnSort method orderByExperimentalDesign.
public static <R> DoubleMatrix<R, BioAssay> orderByExperimentalDesign(DoubleMatrix<R, BioAssay> mat) {
List<BioAssay> bioAssays = mat.getColNames();
List<BioMaterial> start = new ArrayList<>();
Map<BioMaterial, BioAssay> bm2ba = new HashMap<>();
for (BioAssay bioAssay : bioAssays) {
start.add(bioAssay.getSampleUsed());
bm2ba.put(bioAssay.getSampleUsed(), bioAssay);
}
List<BioMaterial> bm = ExpressionDataMatrixColumnSort.orderByExperimentalDesign(start, null);
List<BioAssay> newBioAssayOrder = new ArrayList<>();
for (BioMaterial bioMaterial : bm) {
assert bm2ba.containsKey(bioMaterial);
newBioAssayOrder.add(bm2ba.get(bioMaterial));
}
return mat.subsetColumns(newBioAssayOrder);
}
use of ubic.gemma.model.expression.bioAssay.BioAssay 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.gemma.model.expression.bioAssay.BioAssay in project Gemma by PavlidisLab.
the class DataUpdater method addData.
/**
* Add an additional data (with associated quantitation type) to the selected experiment. Will do postprocessing if
* the data quantitationType is 'preferred', but if there is already a preferred quantitation type, an error will be
* thrown.
*
* @param ee ee
* @param targetPlatform optional; if null, uses the platform already used (if there is just one; you can't use this
* for a multi-platform dataset)
* @param data to slot in
* @return ee
*/
public ExpressionExperiment addData(ExpressionExperiment ee, ArrayDesign targetPlatform, ExpressionDataDoubleMatrix data) {
if (data.rows() == 0) {
throw new IllegalArgumentException("Data had no rows");
}
Collection<QuantitationType> qts = data.getQuantitationTypes();
if (qts.size() > 1) {
throw new IllegalArgumentException("Only support a single quantitation type");
}
if (qts.isEmpty()) {
throw new IllegalArgumentException("Please supply a quantitation type with the data");
}
QuantitationType qt = qts.iterator().next();
if (qt.getIsPreferred()) {
for (QuantitationType existingQt : ee.getQuantitationTypes()) {
if (existingQt.getIsPreferred()) {
throw new IllegalArgumentException("You cannot add 'preferred' data to an experiment that already has it. You should first make the existing data non-preferred.");
}
}
}
Collection<RawExpressionDataVector> vectors = this.makeNewVectors(ee, targetPlatform, data, qt);
if (vectors.isEmpty()) {
throw new IllegalStateException("no vectors!");
}
ee = experimentService.addRawVectors(ee, vectors);
this.audit(ee, "Data vectors added for " + targetPlatform + ", " + qt, false);
// debug code.
for (BioAssay ba : ee.getBioAssays()) {
assert ba.getArrayDesignUsed().equals(targetPlatform);
}
experimentService.update(ee);
if (qt.getIsPreferred()) {
DataUpdater.log.info("Postprocessing preferred data");
ee = this.postprocess(ee);
assert ee.getNumberOfDataVectors() != null;
}
return ee;
}
Aggregations