Search in sources :

Example 21 with DesignElementDataVector

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

the class DesignElementDataVectorDaoImpl method thawRawAndProcessed.

@Override
public void thawRawAndProcessed(Collection<DesignElementDataVector> designElementDataVectors) {
    if (designElementDataVectors == null)
        return;
    Session session = this.getSessionFactory().getCurrentSession();
    Hibernate.initialize(designElementDataVectors);
    StopWatch timer = new StopWatch();
    timer.start();
    Collection<ExpressionExperiment> ees = new HashSet<>();
    Map<BioAssayDimension, Collection<DesignElementDataVector>> dims = new HashMap<>();
    Collection<CompositeSequence> cs = new HashSet<>();
    for (DesignElementDataVector vector : designElementDataVectors) {
        session.buildLockRequest(LockOptions.NONE).lock(vector);
        Hibernate.initialize(vector);
        Hibernate.initialize(vector.getQuantitationType());
        BioAssayDimension bad = vector.getBioAssayDimension();
        if (!dims.containsKey(bad)) {
            dims.put(bad, new HashSet<DesignElementDataVector>());
        }
        dims.get(bad).add(vector);
        cs.add(vector.getDesignElement());
        ees.add(vector.getExpressionExperiment());
        session.evict(vector.getQuantitationType());
        session.evict(vector);
    }
    if (timer.getTime() > designElementDataVectors.size()) {
        AbstractDao.log.info("Thaw phase 1, " + designElementDataVectors.size() + " vectors initialized in " + timer.getTime() + "ms ");
    }
    timer.reset();
    timer.start();
    // lightly thawRawAndProcessed the EEs we saw
    for (ExpressionExperiment ee : ees) {
        Hibernate.initialize(ee);
        session.evict(ee);
    }
    if (timer.getTime() > 200) {
        AbstractDao.log.info("Thaw phase 2, " + ees.size() + " vector-associated expression experiments in " + timer.getTime() + "ms ");
    }
    timer.reset();
    timer.start();
    // thawRawAndProcessed the bioassayDimensions we saw -- usually one, more rarely two.
    for (BioAssayDimension bad : dims.keySet()) {
        BioAssayDimension tbad = (BioAssayDimension) this.getSessionFactory().getCurrentSession().createQuery("select distinct bad from BioAssayDimension bad join fetch bad.bioAssays ba join fetch ba.sampleUsed " + "bm join fetch ba.arrayDesignUsed left join fetch bm.factorValues fetch all properties where bad.id= :bad ").setParameter("bad", bad.getId()).uniqueResult();
        assert tbad != null;
        assert !dims.get(tbad).isEmpty();
        for (DesignElementDataVector v : designElementDataVectors) {
            if (v.getBioAssayDimension().getId().equals(tbad.getId())) {
                v.setBioAssayDimension(tbad);
            }
        }
    }
    if (timer.getTime() > 1000) {
        AbstractDao.log.info("Thaw phase 3, " + dims.size() + " vector-associated bioassaydimensions in " + timer.getTime() + "ms ");
    }
    timer.reset();
    timer.start();
    // thawRawAndProcessed the designelements we saw. SLOW
    long lastTime = 0;
    int count = 0;
    for (CompositeSequence de : cs) {
        BioSequence seq = de.getBiologicalCharacteristic();
        if (seq == null)
            continue;
        session.buildLockRequest(LockOptions.NONE).lock(seq);
        Hibernate.initialize(seq);
        // is this really necessary?
        ArrayDesign arrayDesign = de.getArrayDesign();
        Hibernate.initialize(arrayDesign);
        if (++count % 10000 == 0) {
            if (timer.getTime() - lastTime > 1000) {
                AbstractDao.log.info("Thawed " + count + " vector-associated probes " + timer.getTime() + " ms");
            }
            lastTime = timer.getTime();
        }
    }
    timer.stop();
    if (designElementDataVectors.size() >= 2000 || timer.getTime() > 200) {
        AbstractDao.log.info("Thaw phase 4 " + cs.size() + " vector-associated probes thawed in " + timer.getTime() + "ms");
    }
}
Also used : HashMap(java.util.HashMap) BioSequence(ubic.gemma.model.genome.biosequence.BioSequence) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) StopWatch(org.apache.commons.lang3.time.StopWatch) BioAssayDimension(ubic.gemma.model.expression.bioAssayData.BioAssayDimension) Collection(java.util.Collection) DesignElementDataVector(ubic.gemma.model.expression.bioAssayData.DesignElementDataVector) HashSet(java.util.HashSet)

Example 22 with DesignElementDataVector

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

the class GeoConverterTest method checkQts.

private boolean checkQts(ExpressionExperiment ee) {
    boolean ok = false;
    for (DesignElementDataVector dedv : ee.getRawExpressionDataVectors()) {
        QuantitationType qt = dedv.getQuantitationType();
        if (qt.getIsPreferred()) {
            ok = true;
            assertEquals("VALUE", qt.getName());
        }
    }
    return ok;
}
Also used : DesignElementDataVector(ubic.gemma.model.expression.bioAssayData.DesignElementDataVector) QuantitationType(ubic.gemma.model.common.quantitationtype.QuantitationType) StandardQuantitationType(ubic.gemma.model.common.quantitationtype.StandardQuantitationType)

Example 23 with DesignElementDataVector

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

the class MatrixConversionTest method getDesignElementDataVectors.

/**
 * Creates an ugly (but not unusual) situation where there are two bioassay dimensions with different sizes,
 * referring to the same set of biomaterials.
 *
 * @return design element data vectors
 */
private Collection<DesignElementDataVector> getDesignElementDataVectors(Collection<QuantitationType> quantTypes) {
    Collection<DesignElementDataVector> vectors = new HashSet<>();
    ArrayDesign ad = ArrayDesign.Factory.newInstance();
    ad.setName("junk");
    List<CompositeSequence> sequences = this.getCompositeSequences(ad);
    ArrayDesign adb = ArrayDesign.Factory.newInstance();
    adb.setName("bjunk");
    List<CompositeSequence> sequencesb = this.getCompositeSequences(ad);
    // resused
    List<BioMaterial> bioMaterials = this.getBioMaterials();
    for (QuantitationType quantType : quantTypes) {
        /*
             * Create two bioassay dimension which overlap; "A" does not use all the biomaterials.
             */
        BioAssayDimension baDimA = BioAssayDimension.Factory.newInstance();
        Iterator<BioMaterial> bmita = bioMaterials.iterator();
        for (long i = 0; i < MatrixConversionTest.NUM_BIOMATERIALS - 20; i++) {
            BioAssay ba = ubic.gemma.model.expression.bioAssay.BioAssay.Factory.newInstance();
            ba.setName(RandomStringUtils.randomNumeric(5) + "_testbioassay");
            ba.setSampleUsed(bmita.next());
            ba.setArrayDesignUsed(ad);
            ba.setId(i);
            baDimA.getBioAssays().add(ba);
        }
        baDimA.setName(RandomStringUtils.randomAlphanumeric(10));
        BioAssayDimension baDimB = BioAssayDimension.Factory.newInstance();
        Iterator<BioMaterial> bmitb = bioMaterials.iterator();
        for (long i = 0; i < MatrixConversionTest.NUM_BIOMATERIALS; i++) {
            BioAssay ba = ubic.gemma.model.expression.bioAssay.BioAssay.Factory.newInstance();
            ba.setName(RandomStringUtils.randomNumeric(15) + "_testbioassay");
            ba.setSampleUsed(bmitb.next());
            ba.setArrayDesignUsed(adb);
            ba.setId(i + 20);
            baDimB.getBioAssays().add(ba);
        }
        baDimB.setName(RandomStringUtils.randomAlphanumeric(10));
        // bio.a gets cs 0-99, bio.b gets 100-199.
        long j = 0;
        j = this.loopVectors(vectors, sequencesb, quantType, baDimA, j, MatrixConversionTest.NUM_CS - 100);
        // noinspection UnusedAssignment // Better readability
        j = this.loopVectors(vectors, sequences, quantType, baDimB, j, MatrixConversionTest.NUM_CS);
    }
    return vectors;
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) BioAssayDimension(ubic.gemma.model.expression.bioAssayData.BioAssayDimension) DesignElementDataVector(ubic.gemma.model.expression.bioAssayData.DesignElementDataVector) QuantitationType(ubic.gemma.model.common.quantitationtype.QuantitationType) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay)

Example 24 with DesignElementDataVector

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

the class MatrixConversionTest method loopVectors.

private long loopVectors(Collection<DesignElementDataVector> vectors, List<CompositeSequence> sequencesb, QuantitationType quantType, BioAssayDimension baDimA, long j, int i2) {
    for (; j < i2; j++) {
        DesignElementDataVector vector = RawExpressionDataVector.Factory.newInstance();
        double[] data = new double[baDimA.getBioAssays().size()];
        for (int k = 0; k < data.length; k++) {
            data[k] = k;
        }
        ByteArrayConverter bconverter = new ByteArrayConverter();
        byte[] bdata = bconverter.doubleArrayToBytes(data);
        vector.setData(bdata);
        CompositeSequence cs = sequencesb.get((int) j);
        vector.setDesignElement(cs);
        vector.setQuantitationType(quantType);
        vector.setBioAssayDimension(baDimA);
        vectors.add(vector);
    }
    return j;
}
Also used : ByteArrayConverter(ubic.basecode.io.ByteArrayConverter) DesignElementDataVector(ubic.gemma.model.expression.bioAssayData.DesignElementDataVector) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence)

Example 25 with DesignElementDataVector

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

the class ExpressionExperimentPrePersistServiceImpl method prepare.

@Override
public ArrayDesignsForExperimentCache prepare(ExpressionExperiment ee, ArrayDesignsForExperimentCache cache) {
    Map<ArrayDesign, Collection<CompositeSequence>> newprobes = new HashMap<>();
    Collection<DesignElementDataVector> dataVectorsThatNeedNewProbes = new HashSet<>();
    /*
         * First time through.
         */
    Collection<RawExpressionDataVector> vectors = ee.getRawExpressionDataVectors();
    if (vectors.isEmpty()) {
        /*
             * That's okay; some data sets don't come with data.
             */
        this.prepareWithoutData(ee, cache);
    }
    for (DesignElementDataVector dataVector : vectors) {
        CompositeSequence probe = dataVector.getDesignElement();
        assert probe != null;
        ArrayDesign arrayDesign = probe.getArrayDesign();
        assert arrayDesign != null : probe + " does not have an array design";
        arrayDesign = this.loadOrPersistArrayDesignAndAddToCache(arrayDesign, cache);
        CompositeSequence cachedProbe = cache.getFromCache(probe);
        if (cachedProbe == null) {
            if (!newprobes.containsKey(arrayDesign)) {
                newprobes.put(arrayDesign, new HashSet<CompositeSequence>());
            }
            newprobes.get(arrayDesign).add(probe);
            dataVectorsThatNeedNewProbes.add(dataVector);
        } else {
            dataVector.setDesignElement(cachedProbe);
        }
    }
    /*
         * Second pass - to fill in vectors that needed probes after the first pass.
         */
    if (!dataVectorsThatNeedNewProbes.isEmpty()) {
        ExpressionExperimentPrePersistServiceImpl.log.info(dataVectorsThatNeedNewProbes.size() + " vectors don't have probes, may add to the platform.");
        newprobes = this.addNewDesignElementToPersistentArrayDesigns(newprobes);
        if (newprobes.isEmpty()) {
            ExpressionExperimentPrePersistServiceImpl.log.info("No probes were added");
        // this is okay if there were none to add, but a problem otherwise.
        } else {
            // don't forget to cache them.
            for (ArrayDesign ad : newprobes.keySet()) {
                for (CompositeSequence cs : newprobes.get(ad)) {
                    cache.addToCache(cs);
                }
            }
            // associate with vectors. This repeats code from above, needs refactoring...
            for (DesignElementDataVector v : dataVectorsThatNeedNewProbes) {
                CompositeSequence probe = v.getDesignElement();
                probe = cache.getFromCache(probe);
                if (probe == null || persisterHelper.isTransient(probe)) {
                    throw new IllegalStateException("All probes should be persistent by now");
                }
                v.setDesignElement(probe);
            }
        }
    }
    return cache;
}
Also used : RawExpressionDataVector(ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector) HashMap(java.util.HashMap) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) Collection(java.util.Collection) DesignElementDataVector(ubic.gemma.model.expression.bioAssayData.DesignElementDataVector) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) HashSet(java.util.HashSet)

Aggregations

DesignElementDataVector (ubic.gemma.model.expression.bioAssayData.DesignElementDataVector)33 QuantitationType (ubic.gemma.model.common.quantitationtype.QuantitationType)18 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)18 BioAssayDimension (ubic.gemma.model.expression.bioAssayData.BioAssayDimension)15 ByteArrayConverter (ubic.basecode.io.ByteArrayConverter)9 StandardQuantitationType (ubic.gemma.model.common.quantitationtype.StandardQuantitationType)9 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)8 RawExpressionDataVector (ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector)6 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)5 ProcessedExpressionDataVector (ubic.gemma.model.expression.bioAssayData.ProcessedExpressionDataVector)5 Collection (java.util.Collection)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Test (org.junit.Test)2 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)2 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)2 InputStream (java.io.InputStream)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 StopWatch (org.apache.commons.lang3.time.StopWatch)1 DetachedCriteria (org.hibernate.criterion.DetachedCriteria)1