Search in sources :

Example 66 with BioAssay

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

Example 67 with BioAssay

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);
    }
}
Also used : DoubleArrayList(cern.colt.list.DoubleArrayList) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay)

Example 68 with BioAssay

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;
}
Also used : BioAssayDimension(ubic.gemma.model.expression.bioAssayData.BioAssayDimension) RawExpressionDataVector(ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay) StopWatch(org.apache.commons.lang3.time.StopWatch)

Example 69 with BioAssay

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

Example 70 with BioAssay

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;
}
Also used : SampleCoexpressionMatrix(ubic.gemma.model.analysis.expression.coexpression.SampleCoexpressionMatrix) DenseDoubleMatrix(ubic.basecode.dataStructure.matrix.DenseDoubleMatrix) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay)

Aggregations

BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)144 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)67 Test (org.junit.Test)29 BioAssayDimension (ubic.gemma.model.expression.bioAssayData.BioAssayDimension)29 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)24 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)20 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)18 RawExpressionDataVector (ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector)16 AbstractGeoServiceTest (ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest)15 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)14 ExperimentalFactor (ubic.gemma.model.expression.experiment.ExperimentalFactor)14 InputStream (java.io.InputStream)11 ByteArrayConverter (ubic.basecode.io.ByteArrayConverter)10 HashSet (java.util.HashSet)9 AlreadyExistsInSystemException (ubic.gemma.core.loader.util.AlreadyExistsInSystemException)8 DesignElementDataVector (ubic.gemma.model.expression.bioAssayData.DesignElementDataVector)8 FactorValue (ubic.gemma.model.expression.experiment.FactorValue)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 ModelAndView (org.springframework.web.servlet.ModelAndView)7 ExpressionDataDoubleMatrix (ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix)7