use of ubic.gemma.model.expression.biomaterial.BioMaterialValueObject in project Gemma by PavlidisLab.
the class BioAssayDimensionValueObject method makeDummyBioAssayDimension.
private BioAssayDimension makeDummyBioAssayDimension() {
assert this.id == null;
BioAssayDimension fakeBd = BioAssayDimension.Factory.newInstance("Placeholder representing: " + name, description, new ArrayList<BioAssay>());
Map<Long, ExperimentalFactor> fakeEfs = new HashMap<>();
for (BioAssayValueObject bav : this.bioAssays) {
BioAssay ba = BioAssay.Factory.newInstance();
ba.setId(bav.getId());
ba.setName(bav.getName());
ba.setDescription("Fake placeholder");
BioMaterial sampleUsed = BioMaterial.Factory.newInstance();
BioMaterialValueObject bmVo = bav.getSample();
assert bmVo != null;
sampleUsed.setId(bmVo.getId());
sampleUsed.setName(bmVo.getName());
sampleUsed.setDescription("Fake placeholder");
for (IdentifiableValueObject iVo : bmVo.getFactorValueObjects()) {
FactorValueValueObject fvVo = (FactorValueValueObject) iVo;
FactorValue fv = FactorValue.Factory.newInstance();
assert fvVo.getId() != null;
fv.setId(fvVo.getId());
assert fvVo.getValue() != null;
fv.setValue(fvVo.getValue());
Long efId = fvVo.getFactorId();
ExperimentalFactor ef;
if (fakeEfs.containsKey(efId)) {
ef = fakeEfs.get(efId);
} else {
ef = ExperimentalFactor.Factory.newInstance();
ef.setId(efId);
ef.setName(fvVo.getCategory());
ef.setType(fvVo.isMeasurement() ? FactorType.CONTINUOUS : FactorType.CATEGORICAL);
fakeEfs.put(efId, ef);
}
ef.getFactorValues().add(fv);
fv.setExperimentalFactor(ef);
sampleUsed.getFactorValues().add(fv);
}
ba.setSampleUsed(sampleUsed);
ArrayDesign ad = ArrayDesign.Factory.newInstance();
ArrayDesignValueObject adVo = bav.getArrayDesign();
assert adVo != null;
ad.setId(adVo.getId());
ad.setShortName(adVo.getShortName());
ad.setDescription("Fake placeholder");
ba.setArrayDesignUsed(ad);
fakeBd.getBioAssays().add(ba);
}
return fakeBd;
}
use of ubic.gemma.model.expression.biomaterial.BioMaterialValueObject in project Gemma by PavlidisLab.
the class DoubleVectorValueObject method addGaps.
private void addGaps(BioAssayDimension dimToMatch) {
BioAssayDimensionValueObject sourceBioAssayDimension = new BioAssayDimensionValueObject(dimToMatch);
List<BioAssayValueObject> dimToMatchBioAssays = sourceBioAssayDimension.getBioAssays();
double[] expandedData = new double[dimToMatch.getBioAssays().size()];
BioAssayDimension expandedDim = BioAssayDimension.Factory.newInstance();
expandedDim.setDescription("Expanded bioassay dimension based on " + this.getBioAssayDimension().getName());
expandedDim.setName("Expanded bioassay dimension based on " + this.getBioAssayDimension().getName());
Map<BioMaterialValueObject, BioAssayValueObject> bmap = new HashMap<>();
ArrayDesignValueObject arrayDesign = null;
for (BioAssayValueObject b : this.getBioAssays()) {
bmap.put(b.getSample(), b);
arrayDesign = b.getArrayDesign();
}
List<BioAssayValueObject> expandedBioAssays = new ArrayList<>();
int i = 0;
int indexInUngappedData = 0;
for (BioAssayValueObject b : dimToMatchBioAssays) {
BioMaterialValueObject bm = b.getSample();
if (!bmap.containsKey(bm)) {
/*
* This is one where we have to put in a gap.
*/
expandedData[i] = Double.NaN;
BioAssayValueObject placeholder = new BioAssayValueObject(-1L);
placeholder.setName("Missing bioassay for biomaterial=" + bm + " that was not run on " + arrayDesign);
placeholder.setDescription("This is to represent a biomaterial that was not run on the platform for the rest of the bioassay dimension.");
placeholder.setArrayDesign(arrayDesign);
placeholder.setSample(bm);
expandedBioAssays.add(placeholder);
} else {
expandedBioAssays.add(this.getBioAssays().get(indexInUngappedData));
expandedData[i] = data[indexInUngappedData];
indexInUngappedData++;
}
i++;
}
assert dimToMatchBioAssays.size() == expandedBioAssays.size();
this.data = expandedData;
this.setBioAssayDimension(new BioAssayDimensionValueObject(-1L));
this.getBioAssayDimension().setSourceBioAssayDimension(sourceBioAssayDimension);
// not exactly, but have to make clear it's not real.
this.getBioAssayDimension().setIsSubset(true);
this.getBioAssayDimension().clearBioAssays();
this.getBioAssayDimension().addBioAssays(expandedBioAssays);
this.getBioAssayDimension().setName("Expanded bioassay dimension based on " + this.getBioAssayDimension().getName());
assert this.getBioAssays() != null;
}
use of ubic.gemma.model.expression.biomaterial.BioMaterialValueObject in project Gemma by PavlidisLab.
the class DEDVController method getSampleNames.
/**
* Get the names we'll use for the columns of the vectors.
*/
private void getSampleNames(Collection<DoubleVectorValueObject> vectors, VisualizationValueObject vvo, Map<Long, LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>>> layouts) {
for (DoubleVectorValueObject vec : vectors) {
List<String> sampleNames = new ArrayList<>();
if (layouts != null && layouts.get(vec.getExpressionExperiment().getId()) != null) {
// if same sample was run more than
Collection<BioMaterialValueObject> seenSamples = new HashSet<>();
for (BioAssayValueObject ba : layouts.get(vec.getExpressionExperiment().getId()).keySet()) {
if (seenSamples.contains(ba.getSample())) {
continue;
}
seenSamples.add(ba.getSample());
sampleNames.add(ba.getName());
}
if (sampleNames.size() > 0) {
assert sampleNames.size() == vec.getData().length;
log.debug(sampleNames.size() + " sample names!");
vvo.setSampleNames(sampleNames);
}
} else {
sampleNames = getSampleNames(vec);
if (sampleNames.size() > 0) {
log.debug(sampleNames.size() + " sample names!");
vvo.setSampleNames(sampleNames);
}
}
}
}
use of ubic.gemma.model.expression.biomaterial.BioMaterialValueObject in project Gemma by PavlidisLab.
the class ExperimentalDesignControllerImpl method getBioMaterials.
@Override
public Collection<BioMaterialValueObject> getBioMaterials(EntityDelegator e) {
if (e == null || e.getId() == null)
return null;
ExpressionExperiment ee = expressionExperimentService.load(e.getId());
ee = expressionExperimentService.thawLite(ee);
Collection<BioMaterialValueObject> result = new HashSet<>();
for (BioAssay assay : ee.getBioAssays()) {
BioMaterial sample = assay.getSampleUsed();
BioMaterialValueObject bmvo = new BioMaterialValueObject(sample, assay);
result.add(bmvo);
}
return result;
}
Aggregations