Search in sources :

Example 21 with BioAssayDimension

use of ubic.gemma.model.expression.bioAssayData.BioAssayDimension in project Gemma by PavlidisLab.

the class ExpressionExperimentServiceImpl method addRawVectors.

@Override
@Transactional
public ExpressionExperiment addRawVectors(ExpressionExperiment ee, Collection<RawExpressionDataVector> newVectors) {
    Collection<BioAssayDimension> BADs = new HashSet<>();
    Collection<QuantitationType> qts = new HashSet<>();
    for (RawExpressionDataVector vec : newVectors) {
        BADs.add(vec.getBioAssayDimension());
        qts.add(vec.getQuantitationType());
    }
    if (BADs.size() > 1) {
        throw new IllegalArgumentException("Vectors must share a common bioassay dimension");
    }
    if (qts.size() > 1) {
        throw new UnsupportedOperationException("Can only replace with one type of vector (only one quantitation type)");
    }
    BioAssayDimension bad = BADs.iterator().next();
    bad = this.bioAssayDimensionService.findOrCreate(bad);
    assert bad.getBioAssays().size() > 0;
    QuantitationType newQt = qts.iterator().next();
    if (newQt.getId() == null) {
        newQt = this.quantitationTypeDao.create(newQt);
    } else {
        AbstractService.log.warn("Quantitation type already had an ID...:" + newQt);
    }
    /*
         * This is probably a more or less redundant setting, but doesn't hurt to make sure.
         */
    ArrayDesign vectorAd = newVectors.iterator().next().getDesignElement().getArrayDesign();
    for (BioAssay ba : bad.getBioAssays()) {
        ba.setArrayDesignUsed(vectorAd);
    }
    for (RawExpressionDataVector vec : newVectors) {
        vec.setBioAssayDimension(bad);
        vec.setQuantitationType(newQt);
    }
    ee = rawExpressionDataVectorDao.addVectors(ee.getId(), newVectors);
    // this is a denormalization; easy to forget to update this.
    ee.getQuantitationTypes().add(newQt);
    AbstractService.log.info(ee.getRawExpressionDataVectors().size() + " vectors for experiment");
    return ee;
}
Also used : BioAssayDimension(ubic.gemma.model.expression.bioAssayData.BioAssayDimension) RawExpressionDataVector(ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) QuantitationType(ubic.gemma.model.common.quantitationtype.QuantitationType) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay) Transactional(org.springframework.transaction.annotation.Transactional)

Example 22 with BioAssayDimension

use of ubic.gemma.model.expression.bioAssayData.BioAssayDimension 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 BioAssayDimension

use of ubic.gemma.model.expression.bioAssayData.BioAssayDimension in project Gemma by PavlidisLab.

the class BioAssayDimensionDaoImpl method find.

@Override
public BioAssayDimension find(BioAssayDimension bioAssayDimension) {
    Criteria queryObject = this.getSessionFactory().getCurrentSession().createCriteria(BioAssayDimension.class);
    queryObject.setReadOnly(true);
    queryObject.setFlushMode(FlushMode.MANUAL);
    if (StringUtils.isNotBlank(bioAssayDimension.getName())) {
        queryObject.add(Restrictions.eq("name", bioAssayDimension.getName()));
    }
    if (StringUtils.isNotBlank(bioAssayDimension.getDescription())) {
        queryObject.add(Restrictions.eq("description", bioAssayDimension.getDescription()));
    }
    queryObject.add(Restrictions.sizeEq("bioAssays", bioAssayDimension.getBioAssays().size()));
    Collection<String> names = new HashSet<>();
    assert bioAssayDimension.getBioAssays().size() > 0;
    for (BioAssay bioAssay : bioAssayDimension.getBioAssays()) {
        names.add(bioAssay.getName());
    }
    queryObject.createCriteria("bioAssays").add(Restrictions.in("name", names));
    BioAssayDimension candidate = (BioAssayDimension) queryObject.uniqueResult();
    if (candidate == null)
        return null;
    // Now check that the bioassays and order are exactly the same.
    Collection<BioAssay> desiredBioAssays = bioAssayDimension.getBioAssays();
    Collection<BioAssay> candidateBioAssays = candidate.getBioAssays();
    assert desiredBioAssays.size() == candidateBioAssays.size();
    Iterator<BioAssay> dit = desiredBioAssays.iterator();
    Iterator<BioAssay> cit = candidateBioAssays.iterator();
    while (dit.hasNext()) {
        BioAssay d = dit.next();
        BioAssay c = cit.next();
        if (!c.equals(d))
            return null;
    }
    return candidate;
}
Also used : BioAssayDimension(ubic.gemma.model.expression.bioAssayData.BioAssayDimension) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 24 with BioAssayDimension

use of ubic.gemma.model.expression.bioAssayData.BioAssayDimension 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)

Example 25 with BioAssayDimension

use of ubic.gemma.model.expression.bioAssayData.BioAssayDimension in project Gemma by PavlidisLab.

the class ExpressionExperimentDaoImpl method removeDataVectors.

private int removeDataVectors(Session session, Set<BioAssayDimension> dims, Set<QuantitationType> qts, Collection<RawExpressionDataVector> designElementDataVectors, int count) {
    AbstractDao.log.info("Removing Design Element Data Vectors ...");
    for (RawExpressionDataVector dv : designElementDataVectors) {
        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();
        }
        // put back...
        dv.setBioAssayDimension(bad);
        dv.setQuantitationType(qt);
        if (count % 20000 == 0) {
            AbstractDao.log.info(count + " design Element data vectors deleted");
        }
    }
    count = 0;
    return count;
}
Also used : BioAssayDimension(ubic.gemma.model.expression.bioAssayData.BioAssayDimension) RawExpressionDataVector(ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector) QuantitationType(ubic.gemma.model.common.quantitationtype.QuantitationType)

Aggregations

BioAssayDimension (ubic.gemma.model.expression.bioAssayData.BioAssayDimension)59 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)29 QuantitationType (ubic.gemma.model.common.quantitationtype.QuantitationType)20 RawExpressionDataVector (ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector)16 DesignElementDataVector (ubic.gemma.model.expression.bioAssayData.DesignElementDataVector)15 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)15 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)15 ByteArrayConverter (ubic.basecode.io.ByteArrayConverter)11 StandardQuantitationType (ubic.gemma.model.common.quantitationtype.StandardQuantitationType)10 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)9 ProcessedExpressionDataVector (ubic.gemma.model.expression.bioAssayData.ProcessedExpressionDataVector)9 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)6 HashSet (java.util.HashSet)4 Test (org.junit.Test)4 Transactional (org.springframework.transaction.annotation.Transactional)4 BioSequence (ubic.gemma.model.genome.biosequence.BioSequence)4 StopWatch (org.apache.commons.lang3.time.StopWatch)3 ExpressionDataDoubleMatrix (ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix)3 ExpressionExperimentValueObject (ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject)3 DoubleArrayList (cern.colt.list.DoubleArrayList)2