use of ubic.gemma.model.expression.bioAssayData.DesignElementDataVector in project Gemma by PavlidisLab.
the class BaseExpressionDataMatrix method selectVectors.
Collection<DesignElementDataVector> selectVectors(Collection<? extends DesignElementDataVector> vectors, QuantitationType quantitationType) {
this.quantitationTypes.add(quantitationType);
Collection<DesignElementDataVector> vectorsOfInterest = new LinkedHashSet<>();
int i = 0;
for (DesignElementDataVector vector : vectors) {
QuantitationType vectorQuantitationType = vector.getQuantitationType();
if (vectorQuantitationType.equals(quantitationType)) {
if (this.expressionExperiment == null)
this.expressionExperiment = vector.getExpressionExperiment();
vectorsOfInterest.add(vector);
this.getQuantitationTypes().add(vectorQuantitationType);
CompositeSequence designElement = vector.getDesignElement();
bioAssayDimensions.put(designElement, vector.getBioAssayDimension());
this.addToRowMaps(i, designElement);
i++;
}
}
return vectorsOfInterest;
}
use of ubic.gemma.model.expression.bioAssayData.DesignElementDataVector 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.bioAssayData.DesignElementDataVector 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.bioAssayData.DesignElementDataVector in project Gemma by PavlidisLab.
the class ProcessedExpressionDataVectorCreateHelperServiceImpl method loadIntensities.
/**
* Computes expression intensities depending on which ArrayDesign TechnologyType is used.
*
* @return ExpressionDataDoubleMatrix
*/
private ExpressionDataDoubleMatrix loadIntensities(ExpressionExperiment ee, Collection<ProcessedExpressionDataVector> processedVectors) {
Collection<ArrayDesign> arrayDesignsUsed = this.eeService.getArrayDesignsUsed(ee);
assert !arrayDesignsUsed.isEmpty();
ArrayDesign arrayDesign = arrayDesignsUsed.iterator().next();
assert arrayDesign != null && arrayDesign.getTechnologyType() != null;
ExpressionDataDoubleMatrix intensities;
if (!arrayDesign.getTechnologyType().equals(TechnologyType.ONECOLOR) && !arrayDesign.getTechnologyType().equals(TechnologyType.NONE)) {
ProcessedExpressionDataVectorCreateHelperServiceImpl.log.info("Computing intensities for two-color data from underlying data");
/*
* Get vectors needed to compute intensities.
*/
Collection<QuantitationType> quantitationTypes = eeService.getQuantitationTypes(ee);
Collection<QuantitationType> usefulQuantitationTypes = ExpressionDataMatrixBuilder.getUsefulQuantitationTypes(quantitationTypes);
if (usefulQuantitationTypes.isEmpty()) {
throw new IllegalStateException("No useful quantitation types for " + ee.getShortName());
}
Collection<? extends DesignElementDataVector> vectors = rawExpressionDataVectorService.find(usefulQuantitationTypes);
if (vectors.isEmpty()) {
vectors = processedExpressionDataVectorService.find(usefulQuantitationTypes);
}
if (vectors.isEmpty()) {
throw new IllegalStateException("No vectors for useful quantitation types for " + ee.getShortName());
}
ProcessedExpressionDataVectorCreateHelperServiceImpl.log.info("Vectors loaded ...");
Collection<DesignElementDataVector> vs = new HashSet<>(vectors);
rawExpressionDataVectorService.thawRawAndProcessed(vs);
ExpressionDataMatrixBuilder builder = new ExpressionDataMatrixBuilder(processedVectors, vectors);
intensities = builder.getIntensity();
ExpressionDataBooleanMatrix missingValues = builder.getMissingValueData();
if (missingValues == null) {
ProcessedExpressionDataVectorCreateHelperServiceImpl.log.warn("Could not locate missing value matrix for " + ee + ", rank computation skipped (needed for two-color data)");
return intensities;
}
if (intensities == null) {
ProcessedExpressionDataVectorCreateHelperServiceImpl.log.warn("Could not locate intensity matrix for " + ee + ", rank computation skipped (needed for two-color data)");
return null;
}
ProcessedExpressionDataVectorCreateHelperServiceImpl.log.info("Masking ...");
this.maskMissingValues(intensities, missingValues);
} else {
ProcessedExpressionDataVectorCreateHelperServiceImpl.log.info("Computing intensities directly from processed data");
intensities = new ExpressionDataDoubleMatrix(processedVectors);
}
return intensities;
}
use of ubic.gemma.model.expression.bioAssayData.DesignElementDataVector in project Gemma by PavlidisLab.
the class ExpressionDataDoubleMatrixTest method testConstructExpressionDataDoubleMatrix.
/**
* Tests the construction of an ExpressionDataDoubleMatrix
*/
@Test
public void testConstructExpressionDataDoubleMatrix() {
/* test creating the ExpressionDataDoubleMatrix */
QuantitationType quantitationType = QuantitationType.Factory.newInstance();
quantitationType.setName(metaData.getQuantitationTypeName());
quantitationType.setIsPreferred(true);
quantitationType.setRepresentation(PrimitiveType.DOUBLE);
quantitationType.setIsMaskedPreferred(false);
quantitationType.setIsRatio(true);
quantitationType.setIsBackground(false);
quantitationType.setIsBackgroundSubtracted(true);
quantitationType.setIsNormalized(true);
Collection<RawExpressionDataVector> designElementDataVectors = ee.getRawExpressionDataVectors();
Collection<CompositeSequence> designElements = new HashSet<>();
for (DesignElementDataVector designElementDataVector : designElementDataVectors) {
CompositeSequence de = designElementDataVector.getDesignElement();
designElements.add(de);
}
/* Constructor 1 */
ExpressionDataDoubleMatrix expressionDataDoubleMatrix = new ExpressionDataDoubleMatrix(designElementDataVectors);
/* Assertions */
CompositeSequence deToQuery = designElements.iterator().next();
Double[] row = expressionDataDoubleMatrix.getRow(deToQuery);
assertNotNull(row);
for (Double aRow : row) {
log.debug(aRow);
}
Double[][] dMatrix = expressionDataDoubleMatrix.getRawMatrix();
assertEquals(dMatrix.length, 200);
assertEquals(dMatrix[0].length, 59);
}
Aggregations