Search in sources :

Example 96 with BioAssay

use of ubic.gemma.model.expression.bioAssay.BioAssay 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 97 with BioAssay

use of ubic.gemma.model.expression.bioAssay.BioAssay in project Gemma by PavlidisLab.

the class ExpressionExperimentDaoImpl method thawBioAssays.

@Override
public ExpressionExperiment thawBioAssays(ExpressionExperiment expressionExperiment) {
    String thawQuery = "select distinct e from ExpressionExperiment e " + " left join fetch e.accession acc left join fetch acc.externalDatabase where e.id=:eeId";
    List res = this.getSessionFactory().getCurrentSession().createQuery(thawQuery).setParameter("eeId", expressionExperiment.getId()).list();
    ExpressionExperiment result = (ExpressionExperiment) res.iterator().next();
    Hibernate.initialize(result.getBioAssays());
    for (BioAssay ba : result.getBioAssays()) {
        Hibernate.initialize(ba.getArrayDesignUsed());
        Hibernate.initialize(ba.getSampleUsed());
    }
    return result;
}
Also used : BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay)

Example 98 with BioAssay

use of ubic.gemma.model.expression.bioAssay.BioAssay in project Gemma by PavlidisLab.

the class ExperimentalFactorDaoImpl method remove.

@Override
public void remove(ExperimentalFactor experimentalFactor) {
    Long experimentalDesignId = experimentalFactor.getExperimentalDesign().getId();
    ExperimentalDesign ed = (ExperimentalDesign) this.getSessionFactory().getCurrentSession().load(ExperimentalDesign.class, experimentalDesignId);
    // language=HQL
    final String queryString = "select distinct ee from ExpressionExperiment as ee where ee.experimentalDesign = :ed";
    List<?> results = this.getHibernateTemplate().findByNamedParam(queryString, "ed", ed);
    if (results.size() == 0) {
        throw new IllegalArgumentException("No expression experiment for experimental design " + ed);
    }
    ExpressionExperiment ee = (ExpressionExperiment) results.iterator().next();
    for (BioAssay ba : ee.getBioAssays()) {
        BioMaterial bm = ba.getSampleUsed();
        Collection<FactorValue> factorValuesToRemoveFromBioMaterial = new HashSet<>();
        for (FactorValue factorValue : bm.getFactorValues()) {
            if (experimentalFactor.equals(factorValue.getExperimentalFactor())) {
                factorValuesToRemoveFromBioMaterial.add(factorValue);
                this.getSessionFactory().getCurrentSession().evict(factorValue.getExperimentalFactor());
            }
        }
        // if there are factor values to remove
        if (factorValuesToRemoveFromBioMaterial.size() > 0) {
            bm.getFactorValues().removeAll(factorValuesToRemoveFromBioMaterial);
        // this.getSessionFactory().getCurrentSession().update( bm ); // needed? see bug 4341
        }
    }
    // ed.getExperimentalFactors().remove( experimentalFactor );
    // remove the experimental factor this cascades to values.
    // this.getExperimentalDesignDao().update( ed );
    this.getHibernateTemplate().delete(experimentalFactor);
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 99 with BioAssay

use of ubic.gemma.model.expression.bioAssay.BioAssay in project Gemma by PavlidisLab.

the class BioAssayDaoImpl method find.

@Override
public BioAssay find(BioAssay bioAssay) {
    try {
        Criteria queryObject = BusinessKey.createQueryObject(this.getSessionFactory().getCurrentSession(), bioAssay);
        List<?> results = queryObject.list();
        Object result = null;
        if (results != null) {
            if (results.size() > 1) {
                throw new org.springframework.dao.InvalidDataAccessResourceUsageException("More than one instance of '" + BioAssay.class.getName() + "' was found when executing query");
            } else if (results.size() == 1) {
                result = results.iterator().next();
            }
        }
        return (BioAssay) result;
    } catch (org.hibernate.HibernateException ex) {
        throw super.convertHibernateAccessException(ex);
    }
}
Also used : BioAssayValueObject(ubic.gemma.model.expression.bioAssay.BioAssayValueObject) Criteria(org.hibernate.Criteria) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay)

Example 100 with BioAssay

use of ubic.gemma.model.expression.bioAssay.BioAssay in project Gemma by PavlidisLab.

the class ExpressionExperimentPlatformSwitchService method vectorReWrite.

/**
 * Rearrange/expand a vector as necessary to use the given BioAssayDimension. Only used for multiplatform case of
 * samples run on multiple platforms.
 *
 * @param vector vector
 * @param bad    to be used as the replacement.
 */
private void vectorReWrite(DesignElementDataVector vector, BioAssayDimension bad) {
    List<BioAssay> desiredOrder = bad.getBioAssays();
    List<BioAssay> currentOrder = vector.getBioAssayDimension().getBioAssays();
    if (this.equivalent(currentOrder, desiredOrder)) {
        // Easy, we can just switch it.
        vector.setBioAssayDimension(bad);
        return;
    }
    /*
         * We remake the data vector following the new ordering.
         */
    PrimitiveType representation = vector.getQuantitationType().getRepresentation();
    Object missingVal;
    if (representation.equals(PrimitiveType.DOUBLE)) {
        missingVal = Double.NaN;
    } else if (representation.equals(PrimitiveType.STRING)) {
        missingVal = "";
    } else if (representation.equals(PrimitiveType.INT)) {
        missingVal = 0;
    } else if (representation.equals(PrimitiveType.BOOLEAN)) {
        missingVal = false;
    } else {
        throw new UnsupportedOperationException("Missing values in data vectors of type " + representation + " not supported (when processing " + vector);
    }
    List<Object> oldData = new ArrayList<>();
    super.convertFromBytes(oldData, vector.getQuantitationType().getRepresentation(), vector);
    /*
         * Now data has the old data, so we need to rearrange it to match, inserting missings as necessary.
         */
    Map<BioMaterial, Integer> bm2loc = new HashMap<>();
    int i = 0;
    List<Object> newData = new ArrayList<>();
    // initialize
    for (BioAssay ba : desiredOrder) {
        bm2loc.put(ba.getSampleUsed(), i++);
        newData.add(missingVal);
    }
    // Put data into new locations
    int j = 0;
    for (BioAssay ba : currentOrder) {
        Integer loc = bm2loc.get(ba.getSampleUsed());
        assert loc != null;
        newData.set(loc, oldData.get(j++));
    }
    byte[] newDataAr = converter.toBytes(newData.toArray());
    vector.setData(newDataAr);
    vector.setBioAssayDimension(bad);
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) PrimitiveType(ubic.gemma.model.common.quantitationtype.PrimitiveType) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay)

Aggregations

BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)144 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)67 Test (org.junit.Test)29 BioAssayDimension (ubic.gemma.model.expression.bioAssayData.BioAssayDimension)29 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)24 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)20 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)18 RawExpressionDataVector (ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector)16 AbstractGeoServiceTest (ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest)15 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)14 ExperimentalFactor (ubic.gemma.model.expression.experiment.ExperimentalFactor)14 InputStream (java.io.InputStream)11 ByteArrayConverter (ubic.basecode.io.ByteArrayConverter)10 HashSet (java.util.HashSet)9 AlreadyExistsInSystemException (ubic.gemma.core.loader.util.AlreadyExistsInSystemException)8 DesignElementDataVector (ubic.gemma.model.expression.bioAssayData.DesignElementDataVector)8 FactorValue (ubic.gemma.model.expression.experiment.FactorValue)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 ModelAndView (org.springframework.web.servlet.ModelAndView)7 ExpressionDataDoubleMatrix (ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix)7