use of ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector in project Gemma by PavlidisLab.
the class ExpressionExperimentServiceImpl method addRawVectors.
@Override
@Transactional
public ExpressionExperiment addRawVectors(ExpressionExperiment ee, Collection<RawExpressionDataVector> newVectors) {
Collection<BioAssayDimension> BADs = new HashSet<>();
Collection<QuantitationType> qts = new HashSet<>();
for (RawExpressionDataVector vec : newVectors) {
BADs.add(vec.getBioAssayDimension());
qts.add(vec.getQuantitationType());
}
if (BADs.size() > 1) {
throw new IllegalArgumentException("Vectors must share a common bioassay dimension");
}
if (qts.size() > 1) {
throw new UnsupportedOperationException("Can only replace with one type of vector (only one quantitation type)");
}
BioAssayDimension bad = BADs.iterator().next();
bad = this.bioAssayDimensionService.findOrCreate(bad);
assert bad.getBioAssays().size() > 0;
QuantitationType newQt = qts.iterator().next();
if (newQt.getId() == null) {
newQt = this.quantitationTypeDao.create(newQt);
} else {
AbstractService.log.warn("Quantitation type already had an ID...:" + newQt);
}
/*
* This is probably a more or less redundant setting, but doesn't hurt to make sure.
*/
ArrayDesign vectorAd = newVectors.iterator().next().getDesignElement().getArrayDesign();
for (BioAssay ba : bad.getBioAssays()) {
ba.setArrayDesignUsed(vectorAd);
}
for (RawExpressionDataVector vec : newVectors) {
vec.setBioAssayDimension(bad);
vec.setQuantitationType(newQt);
}
ee = rawExpressionDataVectorDao.addVectors(ee.getId(), newVectors);
// this is a denormalization; easy to forget to update this.
ee.getQuantitationTypes().add(newQt);
AbstractService.log.info(ee.getRawExpressionDataVectors().size() + " vectors for experiment");
return ee;
}
use of ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector in project Gemma by PavlidisLab.
the class ExpressionExperimentServiceImpl method replaceRawVectors.
@Override
@Transactional
public ExpressionExperiment replaceRawVectors(ExpressionExperiment ee, Collection<RawExpressionDataVector> newVectors) {
if (newVectors == null || newVectors.isEmpty()) {
throw new UnsupportedOperationException("Only use this method for replacing vectors, not erasing them");
}
// to attach to session correctly.
ExpressionExperiment eeToUpdate = this.load(ee.getId());
Collection<QuantitationType> qtsToRemove = new HashSet<>();
for (RawExpressionDataVector oldV : eeToUpdate.getRawExpressionDataVectors()) {
qtsToRemove.add(oldV.getQuantitationType());
}
rawExpressionDataVectorDao.remove(eeToUpdate.getRawExpressionDataVectors());
processedVectorService.remove(eeToUpdate.getProcessedExpressionDataVectors());
eeToUpdate.getProcessedExpressionDataVectors().clear();
eeToUpdate.getRawExpressionDataVectors().clear();
// These QTs might still be getting used by the replaced vectors.
for (RawExpressionDataVector newVec : newVectors) {
qtsToRemove.remove(newVec.getQuantitationType());
}
for (QuantitationType oldQt : qtsToRemove) {
quantitationTypeDao.remove(oldQt);
}
// Split the vectors up by bioassay dimension, if need be. This could be modified to handle multiple quantitation types if need be.
Map<BioAssayDimension, Collection<RawExpressionDataVector>> BADs = new HashMap<>();
for (RawExpressionDataVector vec : newVectors) {
BioAssayDimension b = vec.getBioAssayDimension();
if (!BADs.containsKey(b)) {
BADs.put(b, new HashSet<RawExpressionDataVector>());
}
BADs.get(b).add(vec);
}
for (Collection<RawExpressionDataVector> vectors : BADs.values()) {
ee = this.addRawVectors(eeToUpdate, vectors);
}
return ee;
}
use of ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector in project Gemma by PavlidisLab.
the class ExpressionExperimentDaoImpl method removeDataVectors.
private int removeDataVectors(Session session, Set<BioAssayDimension> dims, Set<QuantitationType> qts, Collection<RawExpressionDataVector> designElementDataVectors, int count) {
AbstractDao.log.info("Removing Design Element Data Vectors ...");
for (RawExpressionDataVector dv : designElementDataVectors) {
BioAssayDimension bad = dv.getBioAssayDimension();
dims.add(bad);
QuantitationType qt = dv.getQuantitationType();
qts.add(qt);
dv.setBioAssayDimension(null);
dv.setQuantitationType(null);
session.delete(dv);
if (++count % 1000 == 0) {
session.flush();
}
// put back...
dv.setBioAssayDimension(bad);
dv.setQuantitationType(qt);
if (count % 20000 == 0) {
AbstractDao.log.info(count + " design Element data vectors deleted");
}
}
count = 0;
return count;
}
use of ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector in project Gemma by PavlidisLab.
the class RawExpressionDataVectorDaoImpl method find.
@Override
public RawExpressionDataVector find(RawExpressionDataVector designElementDataVector) {
BusinessKey.checkKey(designElementDataVector);
DetachedCriteria crit = DetachedCriteria.forClass(RawExpressionDataVector.class);
crit.createCriteria("designElement").add(Restrictions.eq("name", designElementDataVector.getDesignElement().getName())).createCriteria("arrayDesign").add(Restrictions.eq("name", designElementDataVector.getDesignElement().getArrayDesign().getName()));
crit.createCriteria("quantitationType").add(Restrictions.eq("name", designElementDataVector.getQuantitationType().getName()));
crit.createCriteria("expressionExperiment").add(Restrictions.eq("name", designElementDataVector.getExpressionExperiment().getName()));
List<?> results = this.getHibernateTemplate().findByCriteria(crit);
Object result = null;
if (results != null) {
if (results.size() > 1) {
throw new org.springframework.dao.InvalidDataAccessResourceUsageException("More than one instance of '" + DesignElementDataVector.class.getName() + "' was found when executing query");
} else if (results.size() == 1) {
result = results.iterator().next();
}
}
return (RawExpressionDataVector) result;
}
use of ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector in project Gemma by PavlidisLab.
the class PersistentDummyObjectHelper method getTestPersistentExpressionExperiment.
/**
* Convenience method to provide an ExpressionExperiment that can be used to fill non-nullable associations in test
* objects. This implementation does NOT fill in associations of the created object except for the creation of
* persistent BioMaterials and BioAssays so that database taxon lookups for this experiment will work.
*
* @param taxon the experiment will have this taxon
* @return EE
*/
public ExpressionExperiment getTestPersistentExpressionExperiment(Taxon taxon) {
BioAssay ba;
BioMaterial bm;
ArrayDesign ad;
bm = this.getTestPersistentBioMaterial(taxon);
ad = this.getTestPersistentArrayDesign(4, true, true);
ba = this.getTestPersistentBioAssay(ad, bm);
Set<BioAssay> bas1 = new HashSet<>();
bas1.add(ba);
ExpressionExperiment ee = ExpressionExperiment.Factory.newInstance();
ee.setName(RandomStringUtils.randomNumeric(PersistentDummyObjectHelper.RANDOM_STRING_LENGTH) + "_testee");
ee.setShortName(RandomStringUtils.randomNumeric(PersistentDummyObjectHelper.RANDOM_STRING_LENGTH) + "_testee");
ee.setBioAssays(bas1);
Collection<FactorValue> allFactorValues = new HashSet<>();
ExperimentalDesign ed = this.getExperimentalDesign(allFactorValues);
ee.setExperimentalDesign(ed);
ee.setOwner(this.getTestPersistentContact());
log.debug("expression experiment => design element data vectors");
Collection<RawExpressionDataVector> vectors = new HashSet<>();
Collection<QuantitationType> quantitationTypes = this.addQuantitationTypes(new HashSet<QuantitationType>());
assert quantitationTypes.size() > 0;
ee.setQuantitationTypes(quantitationTypes);
ee.setRawExpressionDataVectors(vectors);
ArrayDesignsForExperimentCache c = persisterHelper.prepare(ee);
return persisterHelper.persist(ee, c);
}
Aggregations