use of ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector in project Gemma by PavlidisLab.
the class AffyPowerToolsProbesetSummarize method convertDesignElementDataVectors.
/**
* Stolen from SimpleExpressionDataLoaderService
*
* @param expressionExperiment ee
* @param bioAssayDimension BA dim
* @param arrayDesign target design
* @param matrix matrix
* @return raw data vectors
*/
private Collection<RawExpressionDataVector> convertDesignElementDataVectors(ExpressionExperiment expressionExperiment, BioAssayDimension bioAssayDimension, ArrayDesign arrayDesign, DoubleMatrix<String, String> matrix) {
ByteArrayConverter bArrayConverter = new ByteArrayConverter();
Collection<RawExpressionDataVector> vectors = new HashSet<>();
Map<String, CompositeSequence> csMap = new HashMap<>();
for (CompositeSequence cs : arrayDesign.getCompositeSequences()) {
csMap.put(cs.getName(), cs);
}
for (int i = 0; i < matrix.rows(); i++) {
byte[] bdata = bArrayConverter.doubleArrayToBytes(matrix.getRow(i));
RawExpressionDataVector vector = RawExpressionDataVector.Factory.newInstance();
vector.setData(bdata);
CompositeSequence cs = csMap.get(matrix.getRowName(i));
if (cs == null) {
continue;
}
vector.setDesignElement(cs);
vector.setQuantitationType(this.quantitationType);
vector.setExpressionExperiment(expressionExperiment);
vector.setBioAssayDimension(bioAssayDimension);
vectors.add(vector);
}
AffyPowerToolsProbesetSummarize.log.info("Setup " + vectors.size() + " data vectors for " + matrix.rows() + " results from APT");
return vectors;
}
use of ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector in project Gemma by PavlidisLab.
the class DataUpdater method addAffyExonArrayData.
/**
* Use when we want to avoid downloading the CEL files etc. For example if GEO doesn't have them and we ran
* apt-probeset-summarize ourselves. Must be single-platform
*
* @param ee ee
* @param pathToAptOutputFile file
*/
public void addAffyExonArrayData(ExpressionExperiment ee, String pathToAptOutputFile) throws IOException {
Collection<ArrayDesign> ads = experimentService.getArrayDesignsUsed(ee);
if (ads.size() > 1) {
throw new IllegalArgumentException("Can't handle experiments with more than one platform when passing APT output file");
}
ArrayDesign ad = ads.iterator().next();
ad = arrayDesignService.thaw(ad);
ee = experimentService.thawLite(ee);
Taxon primaryTaxon = ad.getPrimaryTaxon();
ArrayDesign targetPlatform = this.prepareTargetPlatformForExonArrays(primaryTaxon);
AffyPowerToolsProbesetSummarize apt = new AffyPowerToolsProbesetSummarize();
Collection<RawExpressionDataVector> vectors = apt.processData(ee, pathToAptOutputFile, targetPlatform);
if (vectors.isEmpty()) {
throw new IllegalStateException("No vectors were returned for " + ee);
}
experimentService.replaceRawVectors(ee, vectors);
if (!targetPlatform.equals(ad)) {
AuditEventType eventType = ExpressionExperimentPlatformSwitchEvent.Factory.newInstance();
auditTrailService.addUpdateEvent(ee, eventType, "Switched in course of updating vectors using AffyPowerTools (from " + ad.getShortName() + " to " + targetPlatform.getShortName() + ")");
}
this.audit(ee, "Data vector input from APT output file " + pathToAptOutputFile + " on " + targetPlatform, true);
this.postprocess(ee);
}
use of ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector in project Gemma by PavlidisLab.
the class DataUpdater method addData.
/**
* Add an additional data (with associated quantitation type) to the selected experiment. Will do postprocessing if
* the data quantitationType is 'preferred', but if there is already a preferred quantitation type, an error will be
* thrown.
*
* @param ee ee
* @param targetPlatform optional; if null, uses the platform already used (if there is just one; you can't use this
* for a multi-platform dataset)
* @param data to slot in
* @return ee
*/
public ExpressionExperiment addData(ExpressionExperiment ee, ArrayDesign targetPlatform, ExpressionDataDoubleMatrix data) {
if (data.rows() == 0) {
throw new IllegalArgumentException("Data had no rows");
}
Collection<QuantitationType> qts = data.getQuantitationTypes();
if (qts.size() > 1) {
throw new IllegalArgumentException("Only support a single quantitation type");
}
if (qts.isEmpty()) {
throw new IllegalArgumentException("Please supply a quantitation type with the data");
}
QuantitationType qt = qts.iterator().next();
if (qt.getIsPreferred()) {
for (QuantitationType existingQt : ee.getQuantitationTypes()) {
if (existingQt.getIsPreferred()) {
throw new IllegalArgumentException("You cannot add 'preferred' data to an experiment that already has it. You should first make the existing data non-preferred.");
}
}
}
Collection<RawExpressionDataVector> vectors = this.makeNewVectors(ee, targetPlatform, data, qt);
if (vectors.isEmpty()) {
throw new IllegalStateException("no vectors!");
}
ee = experimentService.addRawVectors(ee, vectors);
this.audit(ee, "Data vectors added for " + targetPlatform + ", " + qt, false);
// debug code.
for (BioAssay ba : ee.getBioAssays()) {
assert ba.getArrayDesignUsed().equals(targetPlatform);
}
experimentService.update(ee);
if (qt.getIsPreferred()) {
DataUpdater.log.info("Postprocessing preferred data");
ee = this.postprocess(ee);
assert ee.getNumberOfDataVectors() != null;
}
return ee;
}
use of ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector in project Gemma by PavlidisLab.
the class DataUpdater method log2cpmFromCounts.
/**
* For back filling log2cpm when only counts are available. This wouldn't be used routinely, because new experiments
* get log2cpm computed when loaded.
*
* @param ee ee
* @param qt qt
*/
public void log2cpmFromCounts(ExpressionExperiment ee, QuantitationType qt) {
ee = experimentService.thawLite(ee);
/*
* Get the count data; Make sure it is currently preferred (so we don't do this twice by accident)
* We need to do this from the Raw data, not the data that has been normalized etc.
*/
Collection<RawExpressionDataVector> counts = rawExpressionDataVectorService.find(qt);
ExpressionDataDoubleMatrix countMatrix = new ExpressionDataDoubleMatrix(counts);
try {
/*
* Get the count data quantitation type and make it non-preferred
*/
qt.setIsPreferred(false);
qtService.update(qt);
// so updated QT is attached.
ee = experimentService.thawLite(ee);
QuantitationType log2cpmQt = this.makelog2cpmQt();
DoubleMatrix1D librarySize = MatrixStats.colSums(countMatrix.getMatrix());
DoubleMatrix<CompositeSequence, BioMaterial> log2cpmMatrix = MatrixStats.convertToLog2Cpm(countMatrix.getMatrix(), librarySize);
ExpressionDataDoubleMatrix log2cpmEEMatrix = new ExpressionDataDoubleMatrix(ee, log2cpmQt, log2cpmMatrix);
assert log2cpmEEMatrix.getQuantitationTypes().iterator().next().getIsPreferred();
Collection<ArrayDesign> platforms = experimentService.getArrayDesignsUsed(ee);
if (platforms.size() > 1)
throw new IllegalArgumentException("Cannot apply to multiplatform data sets");
this.addData(ee, platforms.iterator().next(), log2cpmEEMatrix);
} catch (Exception e) {
DataUpdater.log.error(e, e);
// try to recover.
qt.setIsPreferred(true);
qtService.update(qt);
}
}
use of ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector in project Gemma by PavlidisLab.
the class DataUpdater method addAffyExonArrayData.
/**
* Replaces any existing "preferred" data. Must be a single-platform study
*
* @param ee ee
* @param ad ad
*/
// Possible external use
@SuppressWarnings({ "unused", "WeakerAccess" })
public void addAffyExonArrayData(ExpressionExperiment ee, ArrayDesign ad) {
RawDataFetcher f = new RawDataFetcher();
Collection<LocalFile> files = f.fetch(ee.getAccession().getAccession());
if (files.isEmpty()) {
throw new RuntimeException("Data was apparently not available");
}
ad = arrayDesignService.thaw(ad);
ee = experimentService.thawLite(ee);
Taxon primaryTaxon = ad.getPrimaryTaxon();
ArrayDesign targetPlatform = this.prepareTargetPlatformForExonArrays(primaryTaxon);
assert !targetPlatform.getCompositeSequences().isEmpty();
AffyPowerToolsProbesetSummarize apt = new AffyPowerToolsProbesetSummarize();
Collection<RawExpressionDataVector> vectors = apt.processExonArrayData(ee, targetPlatform, files);
if (vectors.isEmpty()) {
throw new IllegalStateException("No vectors were returned for " + ee);
}
ee = experimentService.replaceRawVectors(ee, vectors);
if (!targetPlatform.equals(ad)) {
AuditEventType eventType = ExpressionExperimentPlatformSwitchEvent.Factory.newInstance();
auditTrailService.addUpdateEvent(ee, eventType, "Switched in course of updating vectors using AffyPowerTools (from " + ad.getShortName() + " to " + targetPlatform.getShortName() + ")");
}
this.audit(ee, "Data vector computation from CEL files using AffyPowerTools for " + targetPlatform, true);
this.postprocess(ee);
}
Aggregations