Search in sources :

Example 21 with ProcessedExpressionDataVector

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

the class ExpressionExperimentDaoImpl method remove.

@Override
public void remove(final ExpressionExperiment ee) {
    if (ee == null)
        throw new IllegalArgumentException();
    Session session = this.getSessionFactory().getCurrentSession();
    try {
        // Note that links and analyses are deleted separately - see the ExpressionExperimentService.
        // At this point, the ee is probably still in the session, as the service already has gotten it
        // in this transaction.
        session.flush();
        session.clear();
        session.buildLockRequest(LockOptions.NONE).lock(ee);
        Hibernate.initialize(ee.getAuditTrail());
        Set<BioAssayDimension> dims = new HashSet<>();
        Set<QuantitationType> qts = new HashSet<>();
        Collection<RawExpressionDataVector> designElementDataVectors = ee.getRawExpressionDataVectors();
        Hibernate.initialize(designElementDataVectors);
        ee.setRawExpressionDataVectors(null);
        /*
             * We don't remove the investigators, just breaking the association.
             */
        ee.getInvestigators().clear();
        int count = 0;
        if (designElementDataVectors != null) {
            count = this.removeDataVectors(session, dims, qts, designElementDataVectors, count);
        }
        Collection<ProcessedExpressionDataVector> processedVectors = ee.getProcessedExpressionDataVectors();
        Hibernate.initialize(processedVectors);
        if (processedVectors != null && processedVectors.size() > 0) {
            ee.setProcessedExpressionDataVectors(null);
            this.removeProcessedVectors(session, dims, qts, count, processedVectors);
        }
        session.flush();
        session.clear();
        session.update(ee);
        AbstractDao.log.info("Removing BioAssay Dimensions ...");
        for (BioAssayDimension dim : dims) {
            dim.getBioAssays().clear();
            session.update(dim);
            session.delete(dim);
        }
        dims.clear();
        session.flush();
        AbstractDao.log.info("Removing Bioassays and biomaterials ...");
        // keep to put back in the object.
        Map<BioAssay, BioMaterial> copyOfRelations = new HashMap<>();
        Collection<BioMaterial> bioMaterialsToDelete = new HashSet<>();
        Collection<BioAssay> bioAssays = ee.getBioAssays();
        this.removeBioAssays(session, copyOfRelations, bioMaterialsToDelete, bioAssays);
        AbstractDao.log.info("Last bits ...");
        // We remove them here in case they are associated to more than one bioassay-- no cascade is possible.
        for (BioMaterial bm : bioMaterialsToDelete) {
            session.delete(bm);
        }
        for (QuantitationType qt : qts) {
            session.delete(qt);
        }
        session.flush();
        session.delete(ee);
        /*
             * Put transient instances back. This is possibly useful for clearing ACLS.
             */
        ee.setProcessedExpressionDataVectors(processedVectors);
        ee.setRawExpressionDataVectors(designElementDataVectors);
        for (BioAssay ba : ee.getBioAssays()) {
            ba.setSampleUsed(copyOfRelations.get(ba));
        }
        AbstractDao.log.info("Deleted " + ee);
    } catch (Exception e) {
        AbstractDao.log.error(e);
    } finally {
        AbstractDao.log.info("Finalising remove method.");
    }
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) ProcessedExpressionDataVector(ubic.gemma.model.expression.bioAssayData.ProcessedExpressionDataVector) NotImplementedException(org.apache.commons.lang.NotImplementedException) BioAssayDimension(ubic.gemma.model.expression.bioAssayData.BioAssayDimension) RawExpressionDataVector(ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector) QuantitationType(ubic.gemma.model.common.quantitationtype.QuantitationType) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay)

Example 22 with ProcessedExpressionDataVector

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

the class GeoSuperSeriesLoadTest method testFetchAndLoadSuperSeriesB.

/*
     * See bug 2064. GSE14618 is a superseries of GSE14613 and GSE14615. This is actually even worse, because some
     * samples were run on both platforms. This is a situation we don't really want to handle completely.
     *
     */
@Test
public void testFetchAndLoadSuperSeriesB() throws Exception {
    geoService.setGeoDomainObjectGenerator(new GeoDomainObjectGeneratorLocal(this.getTestFileBasePath("gse14618superser")));
    ee = ees.findByShortName("GSE14618");
    this.tearDown();
    // noinspection unchecked
    Collection<ExpressionExperiment> results = (Collection<ExpressionExperiment>) geoService.fetchAndLoad("GSE14618", false, true, false, true, false);
    assertEquals(1, results.size());
    ee = results.iterator().next();
    ee = ees.findByShortName("GSE14618");
    ee = ees.thawLite(ee);
    Collection<QuantitationType> qts = ee.getQuantitationTypes();
    assertEquals(1, qts.size());
    Collection<ArrayDesign> arrayDesignsUsed = ees.getArrayDesignsUsed(ee);
    Collection<ArrayDesign> others = new HashSet<>();
    others.add((ArrayDesign) arrayDesignsUsed.toArray()[1]);
    ArrayDesign arrayDesign = (ArrayDesign) arrayDesignsUsed.toArray()[0];
    ArrayDesign merged = adms.merge(arrayDesign, others, RandomStringUtils.randomAlphabetic(5), RandomStringUtils.randomAlphabetic(5), false);
    ee = eepss.switchExperimentToArrayDesign(ee, merged);
    vms.mergeVectors(ee);
    ee = ees.load(ee.getId());
    ee = ees.findByShortName("GSE14618");
    ee = ees.thaw(ee);
    assertEquals(40, ee.getProcessedExpressionDataVectors().size());
    // System.err.println( ee.getProcessedExpressionDataVectors().size() );
    boolean found1 = false;
    boolean found2 = false;
    ByteArrayConverter bac = new ByteArrayConverter();
    for (ProcessedExpressionDataVector v : ee.getProcessedExpressionDataVectors()) {
        double[] dat = bac.byteArrayToDoubles(v.getData());
        int count = 0;
        assertEquals(92, dat.length);
        if (v.getDesignElement().getName().equals("117_at")) {
            found1 = true;
            for (double d : dat) {
                if (Double.isNaN(d)) {
                    count++;
                }
            }
            assertEquals("Should have been no missing values", 0, count);
        } else if (v.getDesignElement().getName().equals("1552279_a_at")) {
            found2 = true;
            for (double d : dat) {
                if (Double.isNaN(d)) {
                    count++;
                }
            }
            assertEquals("Wrong number of missing values", 42, count);
        }
    }
    assertTrue("Didn't find first test probe expected.", found1);
    assertTrue("Didn't find second test probe expected.", found2);
}
Also used : ByteArrayConverter(ubic.basecode.io.ByteArrayConverter) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) ProcessedExpressionDataVector(ubic.gemma.model.expression.bioAssayData.ProcessedExpressionDataVector) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) Collection(java.util.Collection) QuantitationType(ubic.gemma.model.common.quantitationtype.QuantitationType) GeoDomainObjectGeneratorLocal(ubic.gemma.core.loader.expression.geo.GeoDomainObjectGeneratorLocal) HashSet(java.util.HashSet) AbstractGeoServiceTest(ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest) Test(org.junit.Test)

Example 23 with ProcessedExpressionDataVector

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

the class QuantitationTypeData method getRanksByMean.

public Map<CompositeSequence, Double> getRanksByMean() {
    Collection<QuantitationType> qtypes = this.getPreferredQTypes();
    Map<CompositeSequence, Double> ranks = new HashMap<>();
    for (DesignElementDataVector v : this.vectors) {
        if (qtypes.contains(v.getQuantitationType()) && v instanceof ProcessedExpressionDataVector) {
            ranks.put(v.getDesignElement(), ((ProcessedExpressionDataVector) v).getRankByMean());
        }
    }
    return ranks;
}
Also used : ProcessedExpressionDataVector(ubic.gemma.model.expression.bioAssayData.ProcessedExpressionDataVector) DesignElementDataVector(ubic.gemma.model.expression.bioAssayData.DesignElementDataVector) QuantitationType(ubic.gemma.model.common.quantitationtype.QuantitationType) StandardQuantitationType(ubic.gemma.model.common.quantitationtype.StandardQuantitationType) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence)

Example 24 with ProcessedExpressionDataVector

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

the class ExpressionDataDoubleMatrix method toProcessedDataVectors.

/**
 * @return Convert this to a collection of vectors.
 */
public Collection<ProcessedExpressionDataVector> toProcessedDataVectors() {
    Collection<ProcessedExpressionDataVector> result = new HashSet<>();
    QuantitationType qt = this.getQuantitationTypes().iterator().next();
    ByteArrayConverter bac = new ByteArrayConverter();
    if (this.getQuantitationTypes().size() > 1) {
        throw new UnsupportedOperationException("Cannot convert matrix that has more than one quantitation type");
    }
    for (int i = 0; i < this.rows(); i++) {
        Double[] data = this.getRow(i);
        ProcessedExpressionDataVector v = ProcessedExpressionDataVector.Factory.newInstance();
        v.setBioAssayDimension(this.getBestBioAssayDimension());
        v.setDesignElement(this.getRowNames().get(i));
        v.setQuantitationType(qt);
        v.setData(bac.doubleArrayToBytes(data));
        v.setExpressionExperiment(this.expressionExperiment);
        // we don't fill in the ranks because we only have the mean value here.
        result.add(v);
    }
    return result;
}
Also used : ByteArrayConverter(ubic.basecode.io.ByteArrayConverter) ProcessedExpressionDataVector(ubic.gemma.model.expression.bioAssayData.ProcessedExpressionDataVector) QuantitationType(ubic.gemma.model.common.quantitationtype.QuantitationType)

Example 25 with ProcessedExpressionDataVector

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

the class ExpressionDataDoubleMatrix method vectorsToMatrix.

/**
 * Convert {@link DesignElementDataVector}s into Double matrix.
 */
@Override
protected void vectorsToMatrix(Collection<? extends DesignElementDataVector> vectors) {
    if (vectors == null || vectors.size() == 0) {
        throw new IllegalArgumentException("No vectors!");
    }
    for (DesignElementDataVector vector : vectors) {
        if (vector instanceof ProcessedExpressionDataVector) {
            this.ranks.put(vector.getDesignElement(), ((ProcessedExpressionDataVector) vector).getRankByMean());
        }
    }
    int maxSize = this.setUpColumnElements();
    this.matrix = this.createMatrix(vectors, maxSize);
}
Also used : ProcessedExpressionDataVector(ubic.gemma.model.expression.bioAssayData.ProcessedExpressionDataVector) DesignElementDataVector(ubic.gemma.model.expression.bioAssayData.DesignElementDataVector)

Aggregations

ProcessedExpressionDataVector (ubic.gemma.model.expression.bioAssayData.ProcessedExpressionDataVector)26 QuantitationType (ubic.gemma.model.common.quantitationtype.QuantitationType)10 BioAssayDimension (ubic.gemma.model.expression.bioAssayData.BioAssayDimension)9 Test (org.junit.Test)8 AbstractGeoServiceTest (ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest)8 GeoDomainObjectGeneratorLocal (ubic.gemma.core.loader.expression.geo.GeoDomainObjectGeneratorLocal)8 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)7 AlreadyExistsInSystemException (ubic.gemma.core.loader.util.AlreadyExistsInSystemException)6 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)6 ByteArrayConverter (ubic.basecode.io.ByteArrayConverter)5 ExpressionDataDoubleMatrix (ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix)5 DesignElementDataVector (ubic.gemma.model.expression.bioAssayData.DesignElementDataVector)5 RawExpressionDataVector (ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector)5 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)5 HashSet (java.util.HashSet)4 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)4 File (java.io.File)3 StandardQuantitationType (ubic.gemma.model.common.quantitationtype.StandardQuantitationType)3 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)3 DoubleArrayList (cern.colt.list.DoubleArrayList)2