Search in sources :

Example 26 with RawExpressionDataVector

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;
}
Also used : ByteArrayConverter(ubic.basecode.io.ByteArrayConverter) RawExpressionDataVector(ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence)

Example 27 with RawExpressionDataVector

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);
}
Also used : RawExpressionDataVector(ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector) AuditEventType(ubic.gemma.model.common.auditAndSecurity.eventType.AuditEventType) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) Taxon(ubic.gemma.model.genome.Taxon) AffyPowerToolsProbesetSummarize(ubic.gemma.core.loader.expression.AffyPowerToolsProbesetSummarize)

Example 28 with RawExpressionDataVector

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;
}
Also used : RawExpressionDataVector(ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay)

Example 29 with RawExpressionDataVector

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);
    }
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) RawExpressionDataVector(ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) ExpressionDataDoubleMatrix(ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix) DoubleMatrix1D(cern.colt.matrix.DoubleMatrix1D) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) ConfigurationException(org.apache.commons.configuration.ConfigurationException) PreprocessingException(ubic.gemma.core.analysis.preprocess.PreprocessingException) IOException(java.io.IOException)

Example 30 with RawExpressionDataVector

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);
}
Also used : LocalFile(ubic.gemma.model.common.description.LocalFile) RawExpressionDataVector(ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector) AuditEventType(ubic.gemma.model.common.auditAndSecurity.eventType.AuditEventType) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) Taxon(ubic.gemma.model.genome.Taxon) AffyPowerToolsProbesetSummarize(ubic.gemma.core.loader.expression.AffyPowerToolsProbesetSummarize) RawDataFetcher(ubic.gemma.core.loader.expression.geo.fetcher.RawDataFetcher)

Aggregations

RawExpressionDataVector (ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector)53 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)18 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)16 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)16 BioAssayDimension (ubic.gemma.model.expression.bioAssayData.BioAssayDimension)16 Test (org.junit.Test)15 QuantitationType (ubic.gemma.model.common.quantitationtype.QuantitationType)13 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)12 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)9 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)7 InputStream (java.io.InputStream)6 Collection (java.util.Collection)6 HashSet (java.util.HashSet)6 GZIPInputStream (java.util.zip.GZIPInputStream)6 ByteArrayConverter (ubic.basecode.io.ByteArrayConverter)6 AbstractGeoServiceTest (ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest)6 GeoSeries (ubic.gemma.core.loader.expression.geo.model.GeoSeries)6 DesignElementDataVector (ubic.gemma.model.expression.bioAssayData.DesignElementDataVector)6 ProcessedExpressionDataVector (ubic.gemma.model.expression.bioAssayData.ProcessedExpressionDataVector)5 Transactional (org.springframework.transaction.annotation.Transactional)4