use of ubic.gemma.model.common.quantitationtype.QuantitationType in project Gemma by PavlidisLab.
the class ExpressionExperimentServiceImpl method getPreferredQuantitationType.
@Override
@Transactional(readOnly = true)
public Collection<QuantitationType> getPreferredQuantitationType(final ExpressionExperiment ee) {
Collection<QuantitationType> preferredQuantitationTypes = new HashSet<>();
Collection<QuantitationType> quantitationTypes = this.getQuantitationTypes(ee);
for (QuantitationType qt : quantitationTypes) {
if (qt.getIsPreferred()) {
preferredQuantitationTypes.add(qt);
}
}
return preferredQuantitationTypes;
}
use of ubic.gemma.model.common.quantitationtype.QuantitationType 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.common.quantitationtype.QuantitationType in project Gemma by PavlidisLab.
the class ProcessedExpressionDataVectorDaoImpl method createProcessedDataVectors.
@Override
public ExpressionExperiment createProcessedDataVectors(ExpressionExperiment ee) {
if (ee == null) {
throw new IllegalStateException("ExpressionExperiment cannot be null");
}
ExpressionExperiment expressionExperiment = (ExpressionExperiment) this.getSessionFactory().getCurrentSession().get(ExpressionExperiment.class, ee.getId());
assert expressionExperiment != null;
this.removeProcessedDataVectors(expressionExperiment);
Hibernate.initialize(expressionExperiment);
Hibernate.initialize(expressionExperiment.getQuantitationTypes());
Hibernate.initialize(expressionExperiment.getProcessedExpressionDataVectors());
expressionExperiment.getProcessedExpressionDataVectors().clear();
AbstractDao.log.info("Computing processed expression vectors for " + expressionExperiment);
boolean isTwoChannel = this.isTwoChannel(expressionExperiment);
Collection<RawExpressionDataVector> missingValueVectors = new HashSet<>();
if (isTwoChannel) {
missingValueVectors = this.getMissingValueVectors(expressionExperiment);
}
Collection<RawExpressionDataVector> preferredDataVectors = this.getPreferredDataVectors(expressionExperiment);
if (preferredDataVectors.isEmpty()) {
throw new IllegalArgumentException("No preferred data vectors for " + expressionExperiment);
}
Map<CompositeSequence, DoubleVectorValueObject> maskedVectorObjects = this.maskAndUnpack(preferredDataVectors, missingValueVectors);
/*
* Create the vectors. Do a sanity check that we don't have more than we should
*/
Collection<CompositeSequence> seenDes = new HashSet<>();
RawExpressionDataVector preferredDataVectorExemplar = preferredDataVectors.iterator().next();
QuantitationType preferredMaskedDataQuantitationType = this.getPreferredMaskedDataQuantitationType(preferredDataVectorExemplar.getQuantitationType());
/*
* Note that we used to not normalize count data, but we've removed this restriction; and in any case we have
* moved to using non-count summaries for the primary data type.
*/
if (preferredMaskedDataQuantitationType.getType().equals(StandardQuantitationType.COUNT)) {
/*
* Backfill target
*/
AbstractDao.log.warn("Preferred data are counts; please convert to log2cpm");
}
if (!preferredMaskedDataQuantitationType.getIsRatio() && maskedVectorObjects.size() > ProcessedExpressionDataVectorDaoImpl.MIN_SIZE_FOR_RENORMALIZATION) {
AbstractDao.log.info("Normalizing the data");
this.renormalize(maskedVectorObjects);
} else {
AbstractDao.log.info("Normalization skipped for this data set (not suitable)");
}
int i = 0;
for (CompositeSequence cs : maskedVectorObjects.keySet()) {
DoubleVectorValueObject dvvo = maskedVectorObjects.get(cs);
if (seenDes.contains(cs)) {
// defensive programming, this happens.
throw new IllegalStateException("Duplicated design element: " + cs + "; make sure the experiment has only one 'preferred' quantitation type. " + "Perhaps you need to run vector merging following an array design switch?");
}
ProcessedExpressionDataVector vec = (ProcessedExpressionDataVector) dvvo.toDesignElementDataVector(ee, cs, preferredMaskedDataQuantitationType);
expressionExperiment.getProcessedExpressionDataVectors().add(vec);
seenDes.add(cs);
if (++i % 5000 == 0) {
AbstractDao.log.info(i + " vectors built");
}
}
AbstractDao.log.info("Persisting " + expressionExperiment.getProcessedExpressionDataVectors().size() + " processed data vectors");
expressionExperiment.getQuantitationTypes().add(preferredMaskedDataQuantitationType);
expressionExperiment.setNumberOfDataVectors(expressionExperiment.getProcessedExpressionDataVectors().size());
this.getSessionFactory().getCurrentSession().update(expressionExperiment);
assert expressionExperiment.getNumberOfDataVectors() != null;
this.processedDataVectorCache.clearCache(expressionExperiment.getId());
return expressionExperiment;
}
use of ubic.gemma.model.common.quantitationtype.QuantitationType in project Gemma by PavlidisLab.
the class ProcessedExpressionDataVectorDaoImpl method createProcessedDataVectors.
@Override
public ExpressionExperiment createProcessedDataVectors(ExpressionExperiment ee, Collection<ProcessedExpressionDataVector> data) {
if (ee == null) {
throw new IllegalStateException("ExpressionExperiment cannot be null");
}
ExpressionExperiment expressionExperiment = (ExpressionExperiment) this.getSessionFactory().getCurrentSession().get(ExpressionExperiment.class, ee.getId());
assert expressionExperiment != null;
this.removeProcessedDataVectors(expressionExperiment);
Hibernate.initialize(expressionExperiment);
Hibernate.initialize(expressionExperiment.getQuantitationTypes());
expressionExperiment.setProcessedExpressionDataVectors(data);
QuantitationType qt = data.iterator().next().getQuantitationType();
// assumes all are same.
this.getSessionFactory().getCurrentSession().saveOrUpdate(qt);
expressionExperiment.getQuantitationTypes().add(data.iterator().next().getQuantitationType());
expressionExperiment.setNumberOfDataVectors(expressionExperiment.getProcessedExpressionDataVectors().size());
this.getSessionFactory().getCurrentSession().update(expressionExperiment);
assert expressionExperiment.getNumberOfDataVectors() != null;
this.processedDataVectorCache.clearCache(expressionExperiment.getId());
return expressionExperiment;
}
use of ubic.gemma.model.common.quantitationtype.QuantitationType 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);
}
}
Aggregations