use of ubic.gemma.model.expression.bioAssay.BioAssay in project Gemma by PavlidisLab.
the class DataUpdater method replaceData.
/**
* Replace the data associated with the experiment (or add it if there is none). These data become the 'preferred'
* quantitation type. Note that this replaces the "raw" data.
* Similar to AffyPowerToolsProbesetSummarize.convertDesignElementDataVectors and code in
* SimpleExpressionDataLoaderService.
*
* @param ee the experiment to be modified
* @param targetPlatform the platform for the new data (this can only be used for single-platform data sets)
* @param data the data to be used
* @return ee
*/
public ExpressionExperiment replaceData(ExpressionExperiment ee, ArrayDesign targetPlatform, ExpressionDataDoubleMatrix data) {
Collection<ArrayDesign> ads = experimentService.getArrayDesignsUsed(ee);
if (ads.size() > 1) {
throw new IllegalArgumentException("Can only replace data for an experiment that uses one platform; " + "you must switch/merge first and then provide appropriate replacement data.");
}
if (data.rows() == 0) {
throw new IllegalArgumentException("Data had no rows");
}
ArrayDesign originalArrayDesign = ads.iterator().next();
Collection<QuantitationType> qts = data.getQuantitationTypes();
if (qts.size() > 1) {
throw new IllegalArgumentException("Only supports a single quantitation type");
}
if (qts.isEmpty()) {
throw new IllegalArgumentException("Please supply a quantitation type with the data");
}
QuantitationType qt = qts.iterator().next();
qt.setIsPreferred(true);
Collection<RawExpressionDataVector> vectors = this.makeNewVectors(ee, targetPlatform, data, qt);
if (vectors.isEmpty()) {
throw new IllegalStateException("no vectors!");
}
/*
* remove all analyses, etc.
*/
analysisUtilService.deleteOldAnalyses(ee);
ee = experimentService.replaceRawVectors(ee, vectors);
// audit if we switched platforms.
if (!targetPlatform.equals(originalArrayDesign)) {
AuditEventType eventType = ExpressionExperimentPlatformSwitchEvent.Factory.newInstance();
auditTrailService.addUpdateEvent(ee, eventType, "Switched in course of updating vectors using data input (from " + originalArrayDesign.getShortName() + " to " + targetPlatform.getShortName() + ")");
}
this.audit(ee, "Data vector replacement for " + targetPlatform, true);
experimentService.update(ee);
ee = this.postprocess(ee);
assert ee.getNumberOfDataVectors() != null;
// debug code.
for (BioAssay ba : ee.getBioAssays()) {
assert ba.getArrayDesignUsed().equals(targetPlatform);
}
return ee;
}
use of ubic.gemma.model.expression.bioAssay.BioAssay in project Gemma by PavlidisLab.
the class DataUpdater method addTotalCountInformation.
private void addTotalCountInformation(ExpressionExperiment ee, ExpressionDataDoubleMatrix countEEMatrix, Integer readLength, Boolean isPairedReads) {
for (BioAssay ba : ee.getBioAssays()) {
Double[] col = countEEMatrix.getColumn(ba);
double librarySize = DescriptiveWithMissing.sum(new DoubleArrayList(ArrayUtils.toPrimitive(col)));
DataUpdater.log.info(ba + " total library size=" + librarySize);
ba.setSequenceReadLength(readLength);
ba.setSequencePairedReads(isPairedReads);
ba.setSequenceReadCount((int) Math.floor(librarySize));
bioAssayService.update(ba);
}
}
use of ubic.gemma.model.expression.bioAssay.BioAssay in project Gemma by PavlidisLab.
the class ExpressionPersister method fillInExpressionExperimentDataVectorAssociations.
private Collection<BioAssay> fillInExpressionExperimentDataVectorAssociations(ExpressionExperiment ee, ArrayDesignsForExperimentCache c) {
AbstractPersister.log.info("Filling in DesignElementDataVectors...");
Collection<BioAssay> bioAssays = new HashSet<>();
StopWatch timer = new StopWatch();
timer.start();
int count = 0;
for (RawExpressionDataVector dataVector : ee.getRawExpressionDataVectors()) {
BioAssayDimension bioAssayDimension = this.fillInDesignElementDataVectorAssociations(dataVector, c);
if (timer.getTime() > 5000) {
if (count == 0) {
AbstractPersister.log.info("Setup: " + timer.getTime());
} else {
AbstractPersister.log.info("Filled in " + (count) + " DesignElementDataVectors (" + timer.getTime() + "ms since last check)");
}
timer.reset();
timer.start();
}
bioAssays.addAll(bioAssayDimension.getBioAssays());
++count;
if (Thread.interrupted()) {
AbstractPersister.log.info("Cancelled");
return null;
}
}
AbstractPersister.log.info("Filled in total of " + count + " DesignElementDataVectors, " + bioAssays.size() + " bioassays");
return bioAssays;
}
use of ubic.gemma.model.expression.bioAssay.BioAssay in project Gemma by PavlidisLab.
the class ExpressionPersister method processBioAssays.
/**
* Handle persisting of the bioassays on the way to persisting the expression experiment.
*/
private void processBioAssays(ExpressionExperiment expressionExperiment, ArrayDesignsForExperimentCache c) {
Collection<BioAssay> alreadyFilled = new HashSet<>();
if (expressionExperiment.getRawExpressionDataVectors().isEmpty()) {
AbstractPersister.log.info("Filling in bioassays");
for (BioAssay bioAssay : expressionExperiment.getBioAssays()) {
this.fillInBioAssayAssociations(bioAssay, c);
alreadyFilled.add(bioAssay);
}
} else {
// usual case.
AbstractPersister.log.info("Filling in bioassays via data vectors");
alreadyFilled = this.fillInExpressionExperimentDataVectorAssociations(expressionExperiment, c);
expressionExperiment.setBioAssays(alreadyFilled);
}
}
use of ubic.gemma.model.expression.bioAssay.BioAssay in project Gemma by PavlidisLab.
the class SampleCoexpressionAnalysisDaoImpl method load.
@Override
public DoubleMatrix<BioAssay, BioAssay> load(ExpressionExperiment ee) {
Collection<SampleCoexpressionMatrix> r = this.findByExperiment(ee);
if (r.isEmpty())
return null;
if (r.size() > 1) {
AbstractDao.log.warn("More than one matrix was available, only the first is being returned.");
}
SampleCoexpressionMatrix matObj = r.iterator().next();
byte[] matrixBytes = matObj.getCoexpressionMatrix();
final List<BioAssay> bioAssays = matObj.getBioAssayDimension().getBioAssays();
int numBa = bioAssays.size();
if (numBa == 0) {
throw new IllegalArgumentException("No bioassays in the bioassaydimension with id=" + matObj.getBioAssayDimension().getId());
}
double[][] rawMatrix;
try {
rawMatrix = SampleCoexpressionAnalysisDaoImpl.bac.byteArrayToDoubleMatrix(matrixBytes, numBa);
} catch (IllegalArgumentException e) {
AbstractDao.log.error("EE id = " + ee.getId() + ": " + e.getMessage());
return null;
}
DoubleMatrix<BioAssay, BioAssay> result = new DenseDoubleMatrix<>(rawMatrix);
try {
result.setRowNames(bioAssays);
} catch (IllegalArgumentException e) {
AbstractDao.log.error("EE id = " + ee.getId() + ": " + e.getLocalizedMessage());
}
try {
result.setColumnNames(bioAssays);
} catch (IllegalArgumentException e) {
AbstractDao.log.error("EE id = " + ee.getId() + ": " + e.getLocalizedMessage());
}
return result;
}
Aggregations