use of ubic.gemma.model.expression.bioAssay.BioAssay in project Gemma by PavlidisLab.
the class ExpressionDataDoubleMatrixUtil method scalarDivideMatrix.
/**
* Divide all values by the dividend
*
* @param matrix matrix
* @param dividend dividend
* @throws IllegalArgumentException if dividend == 0.
*/
public static void scalarDivideMatrix(ExpressionDataDoubleMatrix matrix, double dividend) {
if (dividend == 0)
throw new IllegalArgumentException("Can't divide by zero");
int columns = matrix.columns();
for (ExpressionDataMatrixRowElement el : matrix.getRowElements()) {
CompositeSequence del = el.getDesignElement();
for (int i = 0; i < columns; i++) {
BioAssay bm = matrix.getBioAssaysForColumn(i).iterator().next();
double valA = matrix.get(del, bm);
matrix.set(del, bm, valA / dividend);
}
}
}
use of ubic.gemma.model.expression.bioAssay.BioAssay in project Gemma by PavlidisLab.
the class ExpressionDataWriterUtils method constructBioAssayName.
/**
* Constructs a bioassay name. This is useful when writing out data to a file.
*
* @param matrix matrix
* @param assayColumnIndex The column index in the matrix.
* @return BA name
*/
public static String constructBioAssayName(ExpressionDataMatrix<?> matrix, int assayColumnIndex) {
BioMaterial bioMaterialForColumn = matrix.getBioMaterialForColumn(assayColumnIndex);
Collection<BioAssay> bioAssaysForColumn = matrix.getBioAssaysForColumn(assayColumnIndex);
return constructBioAssayName(bioMaterialForColumn, bioAssaysForColumn);
}
use of ubic.gemma.model.expression.bioAssay.BioAssay in project Gemma by PavlidisLab.
the class BaseExpressionDataMatrix method getBioMaterialGroupsForAssays.
private void getBioMaterialGroupsForAssays(Map<BioMaterial, Collection<BioAssay>> bioMaterialMap, List<BioAssay> bioAssays) {
for (BioAssay ba : bioAssays) {
if (BaseExpressionDataMatrix.log.isDebugEnabled())
BaseExpressionDataMatrix.log.debug(" " + ba);
BioMaterial bm = ba.getSampleUsed();
if (!bioMaterialMap.containsKey(bm)) {
bioMaterialMap.put(bm, new HashSet<BioAssay>());
}
bioMaterialMap.get(bm).add(ba);
}
}
use of ubic.gemma.model.expression.bioAssay.BioAssay in project Gemma by PavlidisLab.
the class BaseExpressionDataMatrix method getBestBioAssayDimension.
@Override
public BioAssayDimension getBestBioAssayDimension() {
Collection<BioAssayDimension> dims = new HashSet<>(this.bioAssayDimensions.values());
BioAssayDimension b = dims.iterator().next();
if (dims.size() > 1) {
/*
* Special complication if there is more than one BioAssayDimension
*/
int s = -1;
Collection<BioMaterial> allBioMaterials = new HashSet<>();
// find the largest BioAssayDimension
for (BioAssayDimension bioAssayDimension : dims) {
if (bioAssayDimension.getBioAssays().size() > s) {
s = bioAssayDimension.getBioAssays().size();
b = bioAssayDimension;
}
for (BioAssay ba : b.getBioAssays()) {
allBioMaterials.add(ba.getSampleUsed());
}
}
for (BioAssay ba : b.getBioAssays()) {
if (!allBioMaterials.contains(ba.getSampleUsed())) {
/*
* In rare cases none of the usual ones has all the samples.
*
* This can also happen if the data are not sample-matched or vector-merged
*/
throw new IllegalStateException("Could not find an appropriate BioAssayDimension to represent the data matrix; data might need to be matched or merged");
}
}
}
return b;
}
use of ubic.gemma.model.expression.bioAssay.BioAssay in project Gemma by PavlidisLab.
the class BaseExpressionDataMatrix method setUpColumnElements.
/**
* <p>
* Note: In the current versions of Gemma, we require that there can be only a single BioAssayDimension. Thus this
* code is overly complex. If an experiment has multiple BioAssayDimensions (due to multiple arrays), we merge the
* vectors (e.g., needed in the last case shown below). However, the issue of having multiple "BioMaterials" per
* "BioAssay" still exists.
* <p>
* Deals with the fact that the bioassay dimensions can vary in size, and don't even need to overlap in the
* biomaterials used. In the case where there is a single BioAssayDimension this reduces to simply associating each
* column with a bioassay (though we are forced to use an integer under the hood).
* <p>
* For example, in the following diagram "-" indicates a biomaterial, while "*" indicates a bioassay. Each row of
* "*" indicates samples run on a different microarray design (a different bio assay material). In the examples we
* assume there is just a single biomaterial dimension.
* <pre>
* ---------------
* ***** -- only a few samples run on this platform
* ********** -- ditto
* **** -- these samples were not run on any of the other platforms .
* </pre>
* <p>
* A simpler case:
* </p>
* <pre>
* ---------------
* ***************
* ***********
* *******
* </pre>
* <p>
* A more typical and easy case (one microarray design used):
* </p>
* <pre>
* ----------------
* ****************
* </pre>
* <p>
* If every sample was run on two different array designs:
* </p>
* <pre>
* ----------------
* ****************
* ****************
* </pre>
* <p>
* Every sample was run on a different array design:
* <pre>
* -----------------------
* ******
* *********
* ********
* </pre>
* <p>
* Because there can be limited or no overlap between the bioassay dimensions, we cannot assume the dimensions of
* the matrix will be defined by the longest BioAssayDimension. Note that later in processing, this possible lack of
* overlap is fixed by sample matching or vector merging; this class has to deal with the general case.
* </p>
*/
int setUpColumnElements() {
BaseExpressionDataMatrix.log.debug("Setting up column elements");
assert this.bioAssayDimensions != null && this.bioAssayDimensions.size() > 0 : "No bioAssayDimensions defined";
Map<BioMaterial, Collection<BioAssay>> bioMaterialMap = new LinkedHashMap<>();
for (BioAssayDimension dimension : this.bioAssayDimensions.values()) {
List<BioAssay> bioAssays = dimension.getBioAssays();
BaseExpressionDataMatrix.log.debug("Processing: " + dimension + " with " + bioAssays.size() + " assays");
this.getBioMaterialGroupsForAssays(bioMaterialMap, bioAssays);
}
if (BaseExpressionDataMatrix.log.isDebugEnabled())
BaseExpressionDataMatrix.log.debug(bioMaterialMap.size() + " biomaterialGroups (correspond to columns)");
int column = 0;
for (BioMaterial bioMaterial : bioMaterialMap.keySet()) {
if (BaseExpressionDataMatrix.log.isDebugEnabled())
BaseExpressionDataMatrix.log.debug("Column " + column + " **--->>>> " + bioMaterial);
for (BioAssay assay : bioMaterialMap.get(bioMaterial)) {
if (this.columnBioMaterialMap.containsKey(bioMaterial)) {
int existingColumn = columnBioMaterialMap.get(bioMaterial);
this.columnAssayMap.put(assay, existingColumn);
if (BaseExpressionDataMatrix.log.isDebugEnabled())
BaseExpressionDataMatrix.log.debug(assay + " --> column " + existingColumn);
if (columnBioAssayMapByInteger.get(existingColumn) == null) {
columnBioAssayMapByInteger.put(existingColumn, new HashSet<BioAssay>());
}
columnBioAssayMapByInteger.get(existingColumn).add(assay);
} else {
if (BaseExpressionDataMatrix.log.isDebugEnabled()) {
BaseExpressionDataMatrix.log.debug(bioMaterial + " --> column " + column);
BaseExpressionDataMatrix.log.debug(assay + " --> column " + column);
}
this.columnBioMaterialMap.put(bioMaterial, column);
this.columnAssayMap.put(assay, column);
if (columnBioAssayMapByInteger.get(column) == null) {
columnBioAssayMapByInteger.put(column, new HashSet<BioAssay>());
}
columnBioMaterialMapByInteger.put(column, bioMaterial);
columnBioAssayMapByInteger.get(column).add(assay);
}
}
column++;
}
if (BaseExpressionDataMatrix.log.isDebugEnabled()) {
for (BioAssay o : this.columnAssayMap.keySet()) {
BaseExpressionDataMatrix.log.debug(o + " " + this.columnAssayMap.get(o));
}
}
assert bioMaterialMap.size() == columnBioMaterialMapByInteger.keySet().size();
return columnBioMaterialMapByInteger.keySet().size();
}
Aggregations