use of ubic.gemma.model.expression.bioAssayData.BioAssayDimension 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.BioAssayDimension 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.BioAssayDimension in project Gemma by PavlidisLab.
the class BioAssayDimensionDaoImpl method find.
@Override
public BioAssayDimension find(BioAssayDimension bioAssayDimension) {
Criteria queryObject = this.getSessionFactory().getCurrentSession().createCriteria(BioAssayDimension.class);
queryObject.setReadOnly(true);
queryObject.setFlushMode(FlushMode.MANUAL);
if (StringUtils.isNotBlank(bioAssayDimension.getName())) {
queryObject.add(Restrictions.eq("name", bioAssayDimension.getName()));
}
if (StringUtils.isNotBlank(bioAssayDimension.getDescription())) {
queryObject.add(Restrictions.eq("description", bioAssayDimension.getDescription()));
}
queryObject.add(Restrictions.sizeEq("bioAssays", bioAssayDimension.getBioAssays().size()));
Collection<String> names = new HashSet<>();
assert bioAssayDimension.getBioAssays().size() > 0;
for (BioAssay bioAssay : bioAssayDimension.getBioAssays()) {
names.add(bioAssay.getName());
}
queryObject.createCriteria("bioAssays").add(Restrictions.in("name", names));
BioAssayDimension candidate = (BioAssayDimension) queryObject.uniqueResult();
if (candidate == null)
return null;
// Now check that the bioassays and order are exactly the same.
Collection<BioAssay> desiredBioAssays = bioAssayDimension.getBioAssays();
Collection<BioAssay> candidateBioAssays = candidate.getBioAssays();
assert desiredBioAssays.size() == candidateBioAssays.size();
Iterator<BioAssay> dit = desiredBioAssays.iterator();
Iterator<BioAssay> cit = candidateBioAssays.iterator();
while (dit.hasNext()) {
BioAssay d = dit.next();
BioAssay c = cit.next();
if (!c.equals(d))
return null;
}
return candidate;
}
use of ubic.gemma.model.expression.bioAssayData.BioAssayDimension in project Gemma by PavlidisLab.
the class ExpressionExperimentDaoImpl method removeProcessedVectors.
private void removeProcessedVectors(Session session, Set<BioAssayDimension> dims, Set<QuantitationType> qts, int count, Collection<ProcessedExpressionDataVector> processedVectors) {
for (ProcessedExpressionDataVector dv : processedVectors) {
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();
}
if (count % 20000 == 0) {
AbstractDao.log.info(count + " processed design Element data vectors deleted");
}
// put back..
dv.setBioAssayDimension(bad);
dv.setQuantitationType(qt);
}
}
use of ubic.gemma.model.expression.bioAssayData.BioAssayDimension 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;
}
Aggregations