Search in sources :

Example 16 with QuantitationType

use of ubic.gemma.model.common.quantitationtype.QuantitationType in project Gemma by PavlidisLab.

the class BaseExpressionDataMatrix method selectVectors.

/**
 * Selects all the vectors passed in (uses them to initialize the data)
 */
void selectVectors(Collection<? extends DesignElementDataVector> vectors) {
    QuantitationType quantitationType = null;
    int i = 0;
    List<DesignElementDataVector> sorted = this.sortVectorsByDesignElement(vectors);
    for (DesignElementDataVector vector : sorted) {
        if (this.expressionExperiment == null)
            this.expressionExperiment = vector.getExpressionExperiment();
        QuantitationType vectorQuantitationType = vector.getQuantitationType();
        CompositeSequence designElement = vector.getDesignElement();
        this.bioAssayDimensions.put(designElement, vector.getBioAssayDimension());
        if (quantitationType == null) {
            quantitationType = vectorQuantitationType;
            this.getQuantitationTypes().add(vectorQuantitationType);
        } else {
            if (quantitationType != vectorQuantitationType) {
                throw new IllegalArgumentException("Cannot pass vectors from more than one quantitation type");
            }
        }
        this.addToRowMaps(i, designElement);
        i++;
    }
}
Also used : DesignElementDataVector(ubic.gemma.model.expression.bioAssayData.DesignElementDataVector) QuantitationType(ubic.gemma.model.common.quantitationtype.QuantitationType) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence)

Example 17 with QuantitationType

use of ubic.gemma.model.common.quantitationtype.QuantitationType in project Gemma by PavlidisLab.

the class ExpressionExperimentServiceTest method testGetRawExpressionDataVectors.

@Test
public final void testGetRawExpressionDataVectors() {
    ExpressionExperiment eel = this.getTestPersistentCompleteExpressionExperiment(false);
    Collection<CompositeSequence> designElements = new HashSet<>();
    QuantitationType quantitationType = eel.getRawExpressionDataVectors().iterator().next().getQuantitationType();
    Collection<RawExpressionDataVector> allv = eel.getRawExpressionDataVectors();
    assertNotNull(quantitationType);
    assertTrue(allv.size() > 1);
    for (RawExpressionDataVector anAllv : allv) {
        CompositeSequence designElement = anAllv.getDesignElement();
        assertNotNull(designElement);
        designElements.add(designElement);
        if (designElements.size() == 2)
            break;
    }
    assertEquals(2, designElements.size());
    Collection<? extends DesignElementDataVector> vectors = rawExpressionDataVectorService.find(designElements, quantitationType);
    assertEquals(2, vectors.size());
}
Also used : RawExpressionDataVector(ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector) QuantitationType(ubic.gemma.model.common.quantitationtype.QuantitationType) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) HashSet(java.util.HashSet) Test(org.junit.Test) BaseSpringContextTest(ubic.gemma.core.testing.BaseSpringContextTest)

Example 18 with QuantitationType

use of ubic.gemma.model.common.quantitationtype.QuantitationType in project Gemma by PavlidisLab.

the class ExpressionExperimentServiceTest method testGetQuantitationTypesForArrayDesign.

@Test
public final void testGetQuantitationTypesForArrayDesign() {
    ArrayDesign ad = ee.getRawExpressionDataVectors().iterator().next().getDesignElement().getArrayDesign();
    Collection<QuantitationType> types = expressionExperimentService.getQuantitationTypes(ee, ad);
    assertEquals(2, types.size());
}
Also used : ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) QuantitationType(ubic.gemma.model.common.quantitationtype.QuantitationType) Test(org.junit.Test) BaseSpringContextTest(ubic.gemma.core.testing.BaseSpringContextTest)

Example 19 with QuantitationType

use of ubic.gemma.model.common.quantitationtype.QuantitationType in project Gemma by PavlidisLab.

the class ExpressionExperimentPlatformSwitchService method runOldAd.

private void runOldAd(ExpressionExperiment ee, ArrayDesign arrayDesign, Map<BioSequence, Collection<CompositeSequence>> designElementMap, BioAssayDimension maxBAD, Map<CompositeSequence, Collection<BioAssayDimension>> usedDesignElements, ArrayDesign oldAd) {
    if (oldAd.equals(arrayDesign))
        return;
    oldAd = arrayDesignService.thaw(oldAd);
    if (oldAd.getCompositeSequences().size() == 0 && !oldAd.getTechnologyType().equals(TechnologyType.NONE)) {
        /*
             * Bug 3451 - this is okay if it is a RNA-seq experiment etc. prior to data upload.
             */
        throw new IllegalStateException(oldAd + " has no elements");
    }
    Collection<QuantitationType> qts = expressionExperimentService.getQuantitationTypes(ee, oldAd);
    ExpressionExperimentPlatformSwitchService.log.info("Processing " + qts.size() + " quantitation types for vectors on " + oldAd);
    for (QuantitationType type : qts) {
        // use each design element only once per quantitation type + bioassaydimension per array design
        usedDesignElements.clear();
        Collection<RawExpressionDataVector> rawForQt = this.getRawVectorsForOneQuantitationType(oldAd, type);
        Collection<ProcessedExpressionDataVector> processedForQt = this.getProcessedVectorsForOneQuantitationType(oldAd, type);
        if (// 
        (rawForQt == null || rawForQt.size() == 0) && (processedForQt == null || processedForQt.size() == 0)) {
            /*
                 * This can happen when the quantitation types vary for the array designs.
                 */
            ExpressionExperimentPlatformSwitchService.log.debug("No vectors for " + type + " on " + oldAd);
            continue;
        }
        // This check assures we do not mix raw and processed vectors further down the line
        if ((rawForQt != null && rawForQt.size() > 0) && (processedForQt != null && processedForQt.size() > 0)) {
            throw new IllegalStateException("Two types of vector for quantitationType " + type);
        }
        Collection<DesignElementDataVector> vectors = new HashSet<>();
        if (rawForQt != null) {
            vectors.addAll(rawForQt);
        }
        if (processedForQt != null) {
            vectors.addAll(processedForQt);
        }
        ExpressionExperimentPlatformSwitchService.log.info("Switching " + vectors.size() + " vectors for " + type + " from " + oldAd.getShortName() + " to " + arrayDesign.getShortName());
        int count = 0;
        // noinspection MismatchedQueryAndUpdateOfCollection // Only used for logging
        Collection<DesignElementDataVector> unMatched = new HashSet<>();
        for (DesignElementDataVector vector : vectors) {
            assert RawExpressionDataVector.class.isAssignableFrom(vector.getClass()) : "Unexpected class: " + vector.getClass().getName();
            CompositeSequence oldDe = vector.getDesignElement();
            if (oldDe.getArrayDesign().equals(arrayDesign)) {
                continue;
            }
            this.processVector(designElementMap, usedDesignElements, vector, maxBAD);
            if (++count % 20000 == 0) {
                ExpressionExperimentPlatformSwitchService.log.info("Found matches for " + count + " vectors for " + type);
            }
        }
        /*
             * This is bad.
             */
        if (unMatched.size() > 0) {
            throw new IllegalStateException("There were " + unMatched.size() + " vectors that couldn't be matched to the new design for: " + type + ", example: " + unMatched.iterator().next());
        }
        // Force collection update
        if (rawForQt != null && rawForQt.size() > 0) {
            int s = ee.getRawExpressionDataVectors().size();
            ee.getRawExpressionDataVectors().removeAll(rawForQt);
            assert s > ee.getRawExpressionDataVectors().size();
            ee.getRawExpressionDataVectors().addAll(rawForQt);
            assert s == ee.getRawExpressionDataVectors().size();
        } else if (processedForQt != null && processedForQt.size() > 0) {
            int s = ee.getProcessedExpressionDataVectors().size();
            ee.getProcessedExpressionDataVectors().removeAll(processedForQt);
            assert s > ee.getProcessedExpressionDataVectors().size();
            ee.getProcessedExpressionDataVectors().addAll(processedForQt);
            assert s == ee.getProcessedExpressionDataVectors().size();
        }
    }
}
Also used : RawExpressionDataVector(ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector) ProcessedExpressionDataVector(ubic.gemma.model.expression.bioAssayData.ProcessedExpressionDataVector) DesignElementDataVector(ubic.gemma.model.expression.bioAssayData.DesignElementDataVector) QuantitationType(ubic.gemma.model.common.quantitationtype.QuantitationType) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence)

Example 20 with QuantitationType

use of ubic.gemma.model.common.quantitationtype.QuantitationType 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)

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