Search in sources :

Example 21 with QuantitationType

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;
}
Also used : QuantitationType(ubic.gemma.model.common.quantitationtype.QuantitationType) Transactional(org.springframework.transaction.annotation.Transactional)

Example 22 with QuantitationType

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;
}
Also used : BioAssayDimension(ubic.gemma.model.expression.bioAssayData.BioAssayDimension) RawExpressionDataVector(ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector) QuantitationType(ubic.gemma.model.common.quantitationtype.QuantitationType) Transactional(org.springframework.transaction.annotation.Transactional)

Example 23 with QuantitationType

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;
}
Also used : ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) StandardQuantitationType(ubic.gemma.model.common.quantitationtype.StandardQuantitationType) QuantitationType(ubic.gemma.model.common.quantitationtype.QuantitationType)

Example 24 with QuantitationType

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;
}
Also used : StandardQuantitationType(ubic.gemma.model.common.quantitationtype.StandardQuantitationType) QuantitationType(ubic.gemma.model.common.quantitationtype.QuantitationType) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment)

Example 25 with QuantitationType

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);
    }
}
Also used : BioAssayDimension(ubic.gemma.model.expression.bioAssayData.BioAssayDimension) ProcessedExpressionDataVector(ubic.gemma.model.expression.bioAssayData.ProcessedExpressionDataVector) QuantitationType(ubic.gemma.model.common.quantitationtype.QuantitationType)

Aggregations

QuantitationType (ubic.gemma.model.common.quantitationtype.QuantitationType)74 StandardQuantitationType (ubic.gemma.model.common.quantitationtype.StandardQuantitationType)30 BioAssayDimension (ubic.gemma.model.expression.bioAssayData.BioAssayDimension)20 DesignElementDataVector (ubic.gemma.model.expression.bioAssayData.DesignElementDataVector)18 Test (org.junit.Test)16 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)14 RawExpressionDataVector (ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector)13 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)11 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)10 ProcessedExpressionDataVector (ubic.gemma.model.expression.bioAssayData.ProcessedExpressionDataVector)10 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)8 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)7 AbstractGeoServiceTest (ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest)6 GeoDomainObjectGeneratorLocal (ubic.gemma.core.loader.expression.geo.GeoDomainObjectGeneratorLocal)6 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)6 InputStream (java.io.InputStream)5 GZIPInputStream (java.util.zip.GZIPInputStream)5 GeoSeries (ubic.gemma.core.loader.expression.geo.model.GeoSeries)5 AlreadyExistsInSystemException (ubic.gemma.core.loader.util.AlreadyExistsInSystemException)5 ByteArrayConverter (ubic.basecode.io.ByteArrayConverter)4