use of ubic.gemma.model.analysis.expression.ExpressionExperimentSet in project Gemma by PavlidisLab.
the class ExpressionExperimentSetValueObjectHelperTest method testConvertToEntity.
@Test
public void testConvertToEntity() {
// create VO from entity
Long id = eeSet.getId();
assertNotNull(id);
assertNotNull(expressionExperimentService.loadValueObject(ee));
ExpressionExperimentSetValueObject eesvo = expressionExperimentSetService.loadValueObject(eeSet);
assertEquals(1, eeSet.getExperiments().size());
Collection<ExpressionExperimentValueObject> experimentValueObjectsInSet = expressionExperimentSetService.getExperimentValueObjectsInSet(id);
assertEquals(1, experimentValueObjectsInSet.size());
eesvo.getExpressionExperimentIds().addAll(EntityUtils.getIds(experimentValueObjectsInSet));
// create entity from VO
ExpressionExperimentSet remadeEE = expressionExperimentSetValueObjectHelper.convertToEntity(eesvo);
// check that entity is valid
expressionExperimentSetService.update(remadeEE);
assertEquals(eeSet.getId(), remadeEE.getId());
assertEquals(eeSet.getExperiments().size(), remadeEE.getExperiments().size());
// check that experiment members are the same
Set<BioAssaySet> set1 = new HashSet<>(eeSet.getExperiments());
Set<BioAssaySet> set2 = new HashSet<>(remadeEE.getExperiments());
// noinspection ResultOfMethodCallIgnored
set1.equals(set2);
assertEquals(eeSet.getName(), remadeEE.getName());
assertEquals(eeSet.getDescription(), remadeEE.getDescription());
assertEquals(eeSet.getTaxon(), remadeEE.getTaxon());
}
use of ubic.gemma.model.analysis.expression.ExpressionExperimentSet in project Gemma by PavlidisLab.
the class ExpressionExperimentSetServiceImpl method updateDatabaseEntityNameDesc.
@Override
@Transactional
public ExpressionExperimentSetValueObject updateDatabaseEntityNameDesc(ExpressionExperimentSetValueObject eeSetVO, boolean loadEEIds) {
Long groupId = eeSetVO.getId();
ExpressionExperimentSet eeSet = this.load(groupId);
if (eeSet == null) {
throw new IllegalArgumentException("No experiment set with id=" + groupId + " could be loaded");
}
eeSet.setDescription(eeSetVO.getDescription());
if (eeSetVO.getName() != null && eeSetVO.getName().length() > 0)
eeSet.setName(eeSetVO.getName());
this.update(eeSet);
return this.loadValueObjectById(eeSet.getId(), loadEEIds);
}
use of ubic.gemma.model.analysis.expression.ExpressionExperimentSet in project Gemma by PavlidisLab.
the class ExpressionExperimentSetServiceImpl method updateDatabaseEntity.
@Override
@Transactional
public void updateDatabaseEntity(ExpressionExperimentSetValueObject eesvo) {
try {
ExpressionExperimentSet eeset = expressionExperimentValueObjectHelper.convertToEntity(eesvo);
if (eeset == null) {
throw new IllegalArgumentException("Cannot update null set");
}
this.update(eeset);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of ubic.gemma.model.analysis.expression.ExpressionExperimentSet in project Gemma by PavlidisLab.
the class ExpressionExperimentSetServiceImpl method createFromValueObject.
@Override
@Transactional
public ExpressionExperimentSet createFromValueObject(ExpressionExperimentSetValueObject eesvo) {
/*
* Sanity check.
*/
Collection<ExpressionExperimentSet> dups = this.findByName(eesvo.getName());
if (dups == null || !dups.isEmpty()) {
throw new IllegalArgumentException("Sorry, there is already a set with that name (" + eesvo.getName() + ")");
}
ExpressionExperimentSet newSet = ExpressionExperimentSet.Factory.newInstance();
newSet.setName(eesvo.getName());
newSet.setDescription(eesvo.getDescription());
Collection<? extends BioAssaySet> datasetsAnalyzed = expressionExperimentService.load(eesvo.getExpressionExperimentIds());
newSet.getExperiments().addAll(datasetsAnalyzed);
if (eesvo.getTaxonId() != null)
newSet.setTaxon(taxonService.load(eesvo.getTaxonId()));
else {
/*
* Figure out the taxon from the experiments. mustn't be heterogeneous.
*/
Taxon taxon = null;
for (BioAssaySet bioAssaySet : newSet.getExperiments()) {
Taxon eeTaxon = this.getTaxonForSet(bioAssaySet);
if (taxon == null) {
taxon = eeTaxon;
} else {
assert eeTaxon != null;
if (!eeTaxon.equals(taxon)) {
throw new UnsupportedOperationException("EESets with mixed taxa are not supported");
}
}
}
if (taxon == null) {
throw new IllegalStateException("Could not determine taxon for new EEset");
}
newSet.setTaxon(taxon);
}
if (newSet.getTaxon() == null) {
throw new IllegalArgumentException("Unable to determine the taxon for the EESet");
}
ExpressionExperimentSet newEESet = this.create(newSet);
// make groups private by default
if (eesvo.getIsPublic()) {
securityService.makePublic(newEESet);
} else {
securityService.makePrivate(newEESet);
}
return newEESet;
}
use of ubic.gemma.model.analysis.expression.ExpressionExperimentSet in project Gemma by PavlidisLab.
the class ExpressionExperimentSetServiceImpl method updateDatabaseEntityMembers.
/**
* update the members of the experiment set with the given ids
*
* @param groupId set to update
* @param eeIds new set member ids
*/
@Override
@Transactional
public void updateDatabaseEntityMembers(Long groupId, Collection<Long> eeIds) {
if (eeIds.isEmpty()) {
throw new IllegalArgumentException("No expression experiment ids provided. Cannot save an empty set.");
}
ExpressionExperimentSet eeSet = this.load(groupId);
if (eeSet == null) {
throw new IllegalArgumentException("No experiment set with id=" + groupId + " could be loaded. " + "Either it does not exist or you do not have permission to view it.");
}
// check that new member ids are valid
Collection<ExpressionExperiment> newExperiments = expressionExperimentService.load(eeIds);
if (newExperiments.isEmpty()) {
throw new IllegalArgumentException("None of the experiment ids were valid (out of " + eeIds.size() + " provided)");
}
if (newExperiments.size() < eeIds.size()) {
throw new IllegalArgumentException("Some of the experiment ids were invalid: only found " + newExperiments.size() + " out of " + eeIds.size() + " provided)");
}
assert newExperiments.size() == eeIds.size();
Collection<BioAssaySet> basColl = new HashSet<>();
for (ExpressionExperiment experiment : newExperiments) {
Taxon eeTaxon = this.getTaxonForSet(experiment);
// make sure experiments being added are from the right taxon
if (eeTaxon == null || !eeTaxon.equals(eeSet.getTaxon())) {
throw new IllegalArgumentException(experiment + " is of the wrong taxon to add to eeset. EESet taxon is " + eeSet.getTaxon());
}
basColl.add(experiment);
}
eeSet.getExperiments().clear();
eeSet.getExperiments().addAll(basColl);
this.update(eeSet);
}
Aggregations