use of ubic.gemma.model.expression.bioAssayData.BioAssayDimensionValueObject in project Gemma by PavlidisLab.
the class ExperimentalDesignVisualizationServiceImpl method prepare.
/**
* Gets the bioassay dimensions for the experiments associated with the given vectors. These are cached for later
* re-use.
*/
private void prepare(Collection<DoubleVectorValueObject> dvvOs) {
if (dvvOs == null)
return;
for (DoubleVectorValueObject vec : dvvOs) {
if (vec == null) {
log.debug("DoubleVectorValueObject is null");
continue;
}
if (vec.isReorganized()) {
// wouldn't normally be the case...
continue;
}
ExpressionExperimentValueObject ee = vec.getExpressionExperiment();
/*
* Problem: we can't have two layouts for one experiment, which is actually required if there is more than
* one bioassay dimension. However, this rarely matters. See bug 3775
*/
if (cachedLayouts.containsKey(ee.getId())) {
continue;
} else if (vec.getClass().isInstance(ExpressionExperimentSubsetValueObject.class)) {
ExpressionExperimentSubsetValueObject eesvo = (ExpressionExperimentSubsetValueObject) vec.getExpressionExperiment();
if (eesvo.getSourceExperiment() != null && cachedLayouts.containsKey(eesvo.getSourceExperiment())) {
continue;
}
}
BioAssayDimensionValueObject bioAssayDimension = this.getBioAssayDimensionForVector(vec);
ExpressionExperiment actualEe = this.getExperimentForVector(vec, ee);
assert bioAssayDimension != null;
LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>> experimentalDesignLayout = this.getExperimentalDesignLayout(actualEe, expressionExperimentService.getBioAssayDimensions(actualEe));
cachedLayouts.put(ee.getId(), experimentalDesignLayout);
}
}
use of ubic.gemma.model.expression.bioAssayData.BioAssayDimensionValueObject in project Gemma by PavlidisLab.
the class ExperimentalDesignVisualizationServiceImpl method getExperimentalDesignLayout.
/**
* @param bds a BioAssayDimension that represents the BioAssayDimensionValueObject. This is only needed to avoid
* making ExpressionMatrix use value objects, otherwise we could use the BioAssayDimensionValueObject
* @return A "Layout": a map of bioassays to map of factors to doubles that represent the position in the layout.
*/
private LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>> getExperimentalDesignLayout(ExpressionExperiment experiment, Collection<BioAssayDimension> bds) {
LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>> result = new LinkedHashMap<>();
ExpressionDataMatrix<Object> mat = new EmptyExpressionMatrix(bds);
// This is the place the actual sort order is determined.
List<BioMaterial> bms = ExpressionDataMatrixColumnSort.orderByExperimentalDesign(mat);
Map<Long, Double> fvV = new HashMap<>();
assert experiment != null;
assert experiment.getExperimentalDesign() != null;
if (experiment.getExperimentalDesign().getExperimentalFactors().isEmpty()) {
// Case of no experimental design; just put in a dummy factor.
ExperimentalFactor dummyFactor = ExperimentalFactor.Factory.newInstance();
dummyFactor.setName("No factors");
for (BioMaterial bm : bms) {
int j = mat.getColumnIndex(bm);
Collection<BioAssay> bas = mat.getBioAssaysForColumn(j);
for (BioAssay ba : bas) {
BioAssayValueObject baVo = new BioAssayValueObject(ba, false);
result.put(baVo, new LinkedHashMap<ExperimentalFactor, Double>());
result.get(baVo).put(dummyFactor, 0.0);
}
}
return result;
}
assert !experiment.getExperimentalDesign().getExperimentalFactors().isEmpty();
// Map<ExperimentalFactor, Map<FactorValue, Double>> continuousRanges = new HashMap<>();
for (ExperimentalFactor ef : experiment.getExperimentalDesign().getExperimentalFactors()) {
if (ef.getFactorValues().isEmpty()) {
// this can happen if the design isn't complete.
continue;
}
for (FactorValue fv : ef.getFactorValues()) {
assert fv.getId() != null;
// the id is just used as a convenience.
fvV.put(fv.getId(), new Double(fv.getId()));
}
}
assert !fvV.isEmpty();
assert !bms.isEmpty();
// either bioassay dimension.
for (BioMaterial bm : bms) {
int j = mat.getColumnIndex(bm);
Collection<BioAssay> bas = mat.getBioAssaysForColumn(j);
Collection<FactorValue> fvs = bm.getFactorValues();
for (BioAssay ba : bas) {
BioAssayValueObject baVo = new BioAssayValueObject(ba, false);
result.put(baVo, new LinkedHashMap<ExperimentalFactor, Double>(fvs.size()));
for (FactorValue fv : fvs) {
assert fv.getId() != null;
assert fvV.containsKey(fv.getId());
ExperimentalFactor ef = fv.getExperimentalFactor();
Double value;
if (fv.getMeasurement() != null) {
try {
value = Double.parseDouble(fv.getMeasurement().getValue());
} catch (NumberFormatException e) {
// not good.
value = fvV.get(fv.getId());
}
} else {
value = fvV.get(fv.getId());
}
assert result.containsKey(baVo);
assert value != null;
result.get(baVo).put(ef, value);
}
}
}
return result;
}
use of ubic.gemma.model.expression.bioAssayData.BioAssayDimensionValueObject in project Gemma by PavlidisLab.
the class ExperimentalDesignVisualizationServiceImpl method extendLayout.
/**
* See bug 3775. For experiments which have more than one bioassay dimension, we typically have to "extend" the
* layout to include more bioassays. Because the ordering is defined by the factor values associated with the
* underlying biomaterials, this is going to be okay.
*/
private LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>> extendLayout(DoubleVectorValueObject vec, Long eeId) {
BioAssayDimensionValueObject bioAssayDimension = this.getBioAssayDimensionForVector(vec);
ExpressionExperimentValueObject ee = vec.getExpressionExperiment();
ExpressionExperiment actualEe = this.getExperimentForVector(vec, ee);
LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>> extension = this.getExperimentalDesignLayout(actualEe, expressionExperimentService.getBioAssayDimensions(actualEe));
for (BioAssayValueObject vbaVo : bioAssayDimension.getBioAssays()) {
assert extension.containsKey(vbaVo);
}
for (BioAssayValueObject vbaVo : vec.getBioAssays()) {
assert extension.containsKey(vbaVo);
}
cachedLayouts.get(eeId).putAll(extension);
return cachedLayouts.get(eeId);
}
Aggregations