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);
}
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations