Search in sources :

Example 41 with BioMaterial

use of ubic.gemma.model.expression.biomaterial.BioMaterial in project Gemma by PavlidisLab.

the class BioAssayServiceImpl method handleRemoveBioMaterialAssociation.

// TODO: Refactor so that it accepts ids and does security check later.
private void handleRemoveBioMaterialAssociation(BioAssay bioAssay, BioMaterial bioMaterial) {
    BioAssay bioAssayTemp = this.bioAssayDao.load(bioAssay.getId());
    BioMaterial biomaterialToBeRemoved = this.bioMaterialDao.load(bioMaterial.getId());
    BioMaterial currentBioMaterials = bioAssayTemp.getSampleUsed();
    bioAssayTemp.setSampleUsed(currentBioMaterials);
    // Remove bioAssay from bioMaterial
    Collection<BioAssay> currentBioAssays = biomaterialToBeRemoved.getBioAssaysUsedIn();
    currentBioAssays.remove(bioAssayTemp);
    biomaterialToBeRemoved.setBioAssaysUsedIn(currentBioAssays);
    this.bioMaterialDao.update(biomaterialToBeRemoved);
    this.update(bioAssayTemp);
    // If it is, remove it; if not, update it.
    if (currentBioAssays.size() == 0) {
        this.bioMaterialDao.remove(biomaterialToBeRemoved);
    }
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay)

Example 42 with BioMaterial

use of ubic.gemma.model.expression.biomaterial.BioMaterial in project Gemma by PavlidisLab.

the class ExpressionExperimentDaoImpl method removeBioAssays.

private void removeBioAssays(Session session, Map<BioAssay, BioMaterial> copyOfRelations, Collection<BioMaterial> bioMaterialsToDelete, Collection<BioAssay> bioAssays) {
    for (BioAssay ba : bioAssays) {
        // relations to files cascade, so we only have to worry about biomaterials, which aren't cascaded from
        // anywhere. BioAssay -> BioMaterial is many-to-one, but bioassaySet (experiment) owns the bioAssay.
        BioMaterial biomaterial = ba.getSampleUsed();
        if (biomaterial == null)
            // shouldn't...
            continue;
        bioMaterialsToDelete.add(biomaterial);
        copyOfRelations.put(ba, biomaterial);
        session.buildLockRequest(LockOptions.NONE).lock(biomaterial);
        Hibernate.initialize(biomaterial);
        // this can easily end up with an unattached object.
        Hibernate.initialize(biomaterial.getBioAssaysUsedIn());
        biomaterial.getFactorValues().clear();
        biomaterial.getBioAssaysUsedIn().clear();
        ba.setSampleUsed(null);
    }
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay)

Example 43 with BioMaterial

use of ubic.gemma.model.expression.biomaterial.BioMaterial in project Gemma by PavlidisLab.

the class BioMaterialDaoImpl method find.

@Override
public BioMaterial find(BioMaterial bioMaterial) {
    AbstractDao.log.debug("Start find");
    Criteria queryObject = this.getSessionFactory().getCurrentSession().createCriteria(BioMaterial.class);
    BusinessKey.addRestrictions(queryObject, bioMaterial);
    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 '" + BioMaterial.class.getName() + "' was found when executing query");
        } else if (results.size() == 1) {
            result = results.iterator().next();
        }
    }
    AbstractDao.log.debug("Done with find");
    return (BioMaterial) result;
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) List(java.util.List) BioMaterialValueObject(ubic.gemma.model.expression.biomaterial.BioMaterialValueObject)

Example 44 with BioMaterial

use of ubic.gemma.model.expression.biomaterial.BioMaterial in project Gemma by PavlidisLab.

the class BioMaterialServiceImpl method updateBioMaterials.

@Override
@Transactional
public Collection<BioMaterial> updateBioMaterials(Collection<BioMaterialValueObject> valueObjects) {
    Collection<BioMaterial> bms = new HashSet<>();
    for (BioMaterialValueObject bioMaterialValueObject : valueObjects) {
        BioMaterial updatedBm = this.update(bioMaterialValueObject);
        // the map FactorIdToFactorValueId contains values for all factors, including empty ones.
        assert bioMaterialValueObject.getFactorIdToFactorValueId().size() >= updatedBm.getFactorValues().size();
        bms.add(updatedBm);
    }
    return bms;
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) BioMaterialValueObject(ubic.gemma.model.expression.biomaterial.BioMaterialValueObject) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 45 with BioMaterial

use of ubic.gemma.model.expression.biomaterial.BioMaterial in project Gemma by PavlidisLab.

the class DifferentialExpressionAnalysisUtil method checkBiologicalReplicates.

/**
 * See if there are at least two samples for each factor value combination.
 *
 * @param expressionExperiment the experiment
 * @param factors              factors
 * @return true if there are replicates
 */
static boolean checkBiologicalReplicates(BioAssaySet expressionExperiment, Collection<ExperimentalFactor> factors) {
    Collection<BioMaterial> biomaterials = DifferentialExpressionAnalysisUtil.getBioMaterials(expressionExperiment);
    for (BioMaterial firstBm : biomaterials) {
        Collection<FactorValue> factorValuesToCheck = DifferentialExpressionAnalysisUtil.getRelevantFactorValues(factors, firstBm);
        boolean match = false;
        for (BioMaterial secondBm : biomaterials) {
            if (firstBm.equals(secondBm))
                continue;
            Collection<FactorValue> factorValuesToCompareTo = DifferentialExpressionAnalysisUtil.getRelevantFactorValues(factors, secondBm);
            if (factorValuesToCheck.size() == factorValuesToCompareTo.size() && factorValuesToCheck.containsAll(factorValuesToCompareTo)) {
                DifferentialExpressionAnalysisUtil.log.debug("Replicate found for biomaterial " + firstBm + ".");
                match = true;
                break;
            }
        }
        if (!match) {
            DifferentialExpressionAnalysisUtil.log.warn("No replicate found for biomaterial " + firstBm + ", with factor values" + StringUtils.join(factorValuesToCheck, ","));
            return false;
        }
    }
    return true;
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) FactorValue(ubic.gemma.model.expression.experiment.FactorValue)

Aggregations

BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)132 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)67 FactorValue (ubic.gemma.model.expression.experiment.FactorValue)27 ExperimentalFactor (ubic.gemma.model.expression.experiment.ExperimentalFactor)22 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)19 BioAssayDimension (ubic.gemma.model.expression.bioAssayData.BioAssayDimension)15 HashSet (java.util.HashSet)13 Test (org.junit.Test)13 ExpressionDataDoubleMatrix (ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix)12 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)12 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)10 InputStream (java.io.InputStream)7 DenseDoubleMatrix (ubic.basecode.dataStructure.matrix.DenseDoubleMatrix)7 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)7 QuantitationType (ubic.gemma.model.common.quantitationtype.QuantitationType)7 Characteristic (ubic.gemma.model.common.description.Characteristic)6 RawExpressionDataVector (ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector)6 DoubleArrayList (cern.colt.list.DoubleArrayList)5 DoubleMatrix1D (cern.colt.matrix.DoubleMatrix1D)5 ArrayList (java.util.ArrayList)5