Search in sources :

Example 76 with ArrayDesign

use of ubic.gemma.model.expression.arrayDesign.ArrayDesign in project Gemma by PavlidisLab.

the class ArrayDesignDaoImpl method thaw.

@Override
public ArrayDesign thaw(final ArrayDesign arrayDesign) {
    if (arrayDesign.getId() == null) {
        throw new IllegalArgumentException("Cannot thawRawAndProcessed a non-persistent array design");
    }
    /*
         * Thaw basic stuff
         */
    StopWatch timer = new StopWatch();
    timer.start();
    ArrayDesign result = this.thawLite(arrayDesign);
    if (timer.getTime() > 1000) {
        AbstractDao.log.info("Thaw array design stage 1: " + timer.getTime() + "ms");
    }
    timer.stop();
    timer.reset();
    timer.start();
    /*
         * Thaw the composite sequences.
         */
    AbstractDao.log.info("Start initialize composite sequences");
    Hibernate.initialize(result.getCompositeSequences());
    if (timer.getTime() > 1000) {
        AbstractDao.log.info("Thaw array design stage 2: " + timer.getTime() + "ms");
    }
    timer.stop();
    timer.reset();
    timer.start();
    /*
         * Thaw the biosequences in batches
         */
    Collection<CompositeSequence> thawed = new HashSet<>();
    Collection<CompositeSequence> batch = new HashSet<>();
    long lastTime = timer.getTime();
    for (CompositeSequence cs : result.getCompositeSequences()) {
        batch.add(cs);
        if (batch.size() == 1000) {
            long t = timer.getTime();
            if (t > 10000 && t - lastTime > 1000) {
                AbstractDao.log.info("Thaw Batch : " + t);
            }
            List bb = this.thawBatchOfProbes(batch);
            // noinspection unchecked
            thawed.addAll((Collection<? extends CompositeSequence>) bb);
            lastTime = timer.getTime();
            batch.clear();
        }
        this.getSessionFactory().getCurrentSession().evict(cs);
    }
    if (!batch.isEmpty()) {
        // tail end
        List bb = this.thawBatchOfProbes(batch);
        // noinspection unchecked
        thawed.addAll((Collection<? extends CompositeSequence>) bb);
    }
    result.getCompositeSequences().clear();
    result.getCompositeSequences().addAll(thawed);
    /*
         * This is a bit ugly, but necessary to avoid 'dirty collection' errors later.
         */
    if (result.getCompositeSequences() instanceof PersistentCollection)
        ((PersistentCollection) result.getCompositeSequences()).clearDirty();
    if (timer.getTime() > 1000) {
        AbstractDao.log.info("Thaw array design stage 3: " + timer.getTime());
    }
    return result;
}
Also used : PersistentCollection(org.hibernate.collection.PersistentCollection) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) StopWatch(org.apache.commons.lang3.time.StopWatch)

Example 77 with ArrayDesign

use of ubic.gemma.model.expression.arrayDesign.ArrayDesign in project Gemma by PavlidisLab.

the class QuantitationTypeData method getBioAssayDimensions.

/**
 * @return a single BioAssayDimension except if there are multiple array designs used in the experiment.
 */
public List<BioAssayDimension> getBioAssayDimensions() {
    List<BioAssayDimension> result = new ArrayList<>();
    if (dimMap.keySet().size() > 0) {
        result.addAll(dimMap.values());
        return result;
    }
    if (this.vectors.isEmpty()) {
        throw new IllegalStateException("No vectors, no bioassay dimensions");
    }
    ExpressionDataMatrixBuilder.log.debug("Checking all vectors to get bioAssayDimensions");
    Collection<BioAssayDimension> dimensions = new HashSet<>();
    for (DesignElementDataVector vector : vectors) {
        ArrayDesign adUsed = this.arrayDesignForVector(vector);
        if (!dimMap.containsKey(adUsed)) {
            dimMap.put(adUsed, vector.getBioAssayDimension());
        }
        dimensions.add(vector.getBioAssayDimension());
    }
    ExpressionDataMatrixBuilder.log.debug("got " + dimensions.size() + " bioAssayDimensions");
    result.addAll(dimensions);
    return result;
}
Also used : BioAssayDimension(ubic.gemma.model.expression.bioAssayData.BioAssayDimension) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) DesignElementDataVector(ubic.gemma.model.expression.bioAssayData.DesignElementDataVector)

Example 78 with ArrayDesign

use of ubic.gemma.model.expression.arrayDesign.ArrayDesign in project Gemma by PavlidisLab.

the class PersistentDummyObjectHelper method getTestPersistentExpressionExperiment.

/**
 * Convenience method to provide an ExpressionExperiment that can be used to fill non-nullable associations in test
 * objects. This implementation does NOT fill in associations of the created object except for the creation of
 * persistent BioMaterials and BioAssays so that database taxon lookups for this experiment will work.
 *
 * @param taxon the experiment will have this taxon
 * @return EE
 */
public ExpressionExperiment getTestPersistentExpressionExperiment(Taxon taxon) {
    BioAssay ba;
    BioMaterial bm;
    ArrayDesign ad;
    bm = this.getTestPersistentBioMaterial(taxon);
    ad = this.getTestPersistentArrayDesign(4, true, true);
    ba = this.getTestPersistentBioAssay(ad, bm);
    Set<BioAssay> bas1 = new HashSet<>();
    bas1.add(ba);
    ExpressionExperiment ee = ExpressionExperiment.Factory.newInstance();
    ee.setName(RandomStringUtils.randomNumeric(PersistentDummyObjectHelper.RANDOM_STRING_LENGTH) + "_testee");
    ee.setShortName(RandomStringUtils.randomNumeric(PersistentDummyObjectHelper.RANDOM_STRING_LENGTH) + "_testee");
    ee.setBioAssays(bas1);
    Collection<FactorValue> allFactorValues = new HashSet<>();
    ExperimentalDesign ed = this.getExperimentalDesign(allFactorValues);
    ee.setExperimentalDesign(ed);
    ee.setOwner(this.getTestPersistentContact());
    log.debug("expression experiment => design element data vectors");
    Collection<RawExpressionDataVector> vectors = new HashSet<>();
    Collection<QuantitationType> quantitationTypes = this.addQuantitationTypes(new HashSet<QuantitationType>());
    assert quantitationTypes.size() > 0;
    ee.setQuantitationTypes(quantitationTypes);
    ee.setRawExpressionDataVectors(vectors);
    ArrayDesignsForExperimentCache c = persisterHelper.prepare(ee);
    return persisterHelper.persist(ee, c);
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) ArrayDesignsForExperimentCache(ubic.gemma.persistence.util.ArrayDesignsForExperimentCache) RawExpressionDataVector(ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay)

Example 79 with ArrayDesign

use of ubic.gemma.model.expression.arrayDesign.ArrayDesign in project Gemma by PavlidisLab.

the class ArrayDesignMergeServiceImpl method createMerged.

/**
 * @param mergeWithExisting i.e., "add", assuming arrayDesign is already a merged design.
 */
private ArrayDesign createMerged(ArrayDesign arrayDesign, Collection<ArrayDesign> otherArrayDesigns, Map<BioSequence, Collection<CompositeSequence>> globalBsMap, String newName, String newShortName, boolean mergeWithExisting) {
    ArrayDesign result = this.formMergedDesign(arrayDesign, otherArrayDesigns, newName, newShortName, mergeWithExisting);
    Collection<CompositeSequence> newProbes = this.makeNewProbes(result, globalBsMap, mergeWithExisting);
    result = mergeServiceHelper.persistMerging(result, arrayDesign, otherArrayDesigns, mergeWithExisting, newProbes);
    arrayDesignReportService.generateArrayDesignReport(result.getId());
    return result;
}
Also used : ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence)

Example 80 with ArrayDesign

use of ubic.gemma.model.expression.arrayDesign.ArrayDesign in project Gemma by PavlidisLab.

the class ArrayDesignMergeServiceImpl method formMergedDesign.

/**
 * Populate the initial skeleton of the merged design. If mergeWithExisting=true, then the description of
 * arrayDesign is updated
 *
 * @return either a new non-persistent arrayDesign ready to be populated, or arrayDesign with an updated
 * description.
 */
private ArrayDesign formMergedDesign(ArrayDesign arrayDesign, Collection<ArrayDesign> otherArrayDesigns, String newName, String newShortName, boolean mergeWithExisting) {
    String mergeeListString = StringUtils.join(otherArrayDesigns, ",");
    ArrayDesign result;
    if (mergeWithExisting) {
        if (arrayDesign.getMergees().isEmpty()) {
            throw new IllegalArgumentException("Cannot use 'add' unless the array design is already a merged design: " + arrayDesign);
        }
        assert arrayDesign.getId() != null;
        ArrayDesignMergeServiceImpl.log.info(arrayDesign + " is already a merged design, others will be added in");
        result = arrayDesign;
        result.setDescription(result.getDescription() + "; Additional designs merged in: " + mergeeListString);
    } else {
        result = ArrayDesign.Factory.newInstance();
        result.setName(newName);
        // assume this is ok.
        result.setPrimaryTaxon(arrayDesign.getPrimaryTaxon());
        result.setShortName(newShortName);
        result.setTechnologyType(arrayDesign.getTechnologyType());
        result.setDesignProvider(arrayDesign.getDesignProvider());
        mergeeListString = mergeeListString + "," + arrayDesign.getShortName();
        result.setDescription("Created by merging the following array designs: " + mergeeListString);
    }
    return result;
}
Also used : ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign)

Aggregations

ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)186 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)43 Test (org.junit.Test)32 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)26 InputStream (java.io.InputStream)25 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)24 BioSequence (ubic.gemma.model.genome.biosequence.BioSequence)24 Taxon (ubic.gemma.model.genome.Taxon)23 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)19 HashSet (java.util.HashSet)16 RawExpressionDataVector (ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector)16 Collection (java.util.Collection)14 AbstractGeoServiceTest (ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest)13 StopWatch (org.apache.commons.lang3.time.StopWatch)12 Before (org.junit.Before)12 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)12 BioAssayDimension (ubic.gemma.model.expression.bioAssayData.BioAssayDimension)9 GZIPInputStream (java.util.zip.GZIPInputStream)8 SimpleExpressionExperimentMetaData (ubic.gemma.core.loader.expression.simple.model.SimpleExpressionExperimentMetaData)8 File (java.io.File)7