use of ubic.gemma.model.expression.biomaterial.BioMaterial in project Gemma by PavlidisLab.
the class ExperimentalDesignImporterTestB method testParseLoadDelete.
@Test
public final void testParseLoadDelete() throws Exception {
try (InputStream is = this.getClass().getResourceAsStream("/data/loader/expression/gill2007temperatureGemmaAnnotationData.txt")) {
experimentalDesignImporter.importDesign(ee, is);
}
this.checkResults();
this.aclTestUtils.checkEEAcls(ee);
ee = this.expressionExperimentService.load(ee.getId());
ee = expressionExperimentService.thawLite(ee);
int s = ee.getExperimentalDesign().getExperimentalFactors().size();
ExperimentalFactor toDelete = ee.getExperimentalDesign().getExperimentalFactors().iterator().next();
experimentalFactorService.delete(toDelete);
ee = this.expressionExperimentService.load(ee.getId());
ee = expressionExperimentService.thawLite(ee);
assertEquals(s - 1, ee.getExperimentalDesign().getExperimentalFactors().size());
for (BioAssay ba : ee.getBioAssays()) {
BioMaterial bm = ba.getSampleUsed();
for (FactorValue fv : bm.getFactorValues()) {
assertTrue(!fv.getExperimentalFactor().equals(toDelete));
}
}
}
use of ubic.gemma.model.expression.biomaterial.BioMaterial in project Gemma by PavlidisLab.
the class CharacteristicUpdateTaskImpl method removeFromParent.
private void removeFromParent(Characteristic c, Object parent) {
if (parent instanceof ExpressionExperiment) {
ExpressionExperiment ee = (ExpressionExperiment) parent;
ee = expressionExperimentService.thawLite(ee);
ee.getCharacteristics().remove(c);
expressionExperimentService.update(ee);
} else if (parent instanceof BioMaterial) {
BioMaterial bm = (BioMaterial) parent;
bm.getCharacteristics().remove(c);
bioMaterialService.update(bm);
} else if (parent instanceof FactorValue) {
FactorValue fv = (FactorValue) parent;
fv.getCharacteristics().remove(c);
factorValueService.update(fv);
}
}
use of ubic.gemma.model.expression.biomaterial.BioMaterial 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.BioMaterial in project Gemma by PavlidisLab.
the class FactorValueDaoImpl method remove.
@Override
public void remove(final FactorValue factorValue) {
if (factorValue == null)
return;
// noinspection unchecked
Collection<BioMaterial> bms = this.getSessionFactory().getCurrentSession().createQuery("select distinct bm from BioMaterial as bm join bm.factorValues fv where fv = :fv").setParameter("fv", factorValue).list();
AbstractDao.log.info("Disassociating " + factorValue + " from " + bms.size() + " biomaterials");
for (BioMaterial bioMaterial : bms) {
// temporary, debugging.
AbstractDao.log.info("Processing " + bioMaterial);
if (bioMaterial.getFactorValues().remove(factorValue)) {
this.getSessionFactory().getCurrentSession().update(bioMaterial);
} else {
AbstractDao.log.warn("Unexpectedly the factor value was not actually associated with " + bioMaterial);
}
}
List<?> efs = this.getHibernateTemplate().findByNamedParam("select ef from ExperimentalFactor ef join ef.factorValues fv where fv = :fv", "fv", factorValue);
ExperimentalFactor ef = (ExperimentalFactor) efs.iterator().next();
ef.getFactorValues().remove(factorValue);
this.getSessionFactory().getCurrentSession().update(ef);
// will get the dreaded 'already in session' error if we don't do this.
this.getSessionFactory().getCurrentSession().flush();
this.getSessionFactory().getCurrentSession().clear();
this.getSessionFactory().getCurrentSession().delete(factorValue);
}
use of ubic.gemma.model.expression.biomaterial.BioMaterial in project Gemma by PavlidisLab.
the class BioMaterialDaoImpl method copy.
@Override
public BioMaterial copy(final BioMaterial bioMaterial) {
BioMaterial newMaterial = BioMaterial.Factory.newInstance();
newMaterial.setDescription(bioMaterial.getDescription() + " [Created by Gemma]");
newMaterial.setCharacteristics(bioMaterial.getCharacteristics());
newMaterial.setSourceTaxon(bioMaterial.getSourceTaxon());
newMaterial.setTreatments(bioMaterial.getTreatments());
newMaterial.setFactorValues(bioMaterial.getFactorValues());
newMaterial.setName("Modeled after " + bioMaterial.getName());
newMaterial = this.findOrCreate(newMaterial);
return newMaterial;
}
Aggregations