Search in sources :

Example 6 with ExpressionExperimentSet

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());
}
Also used : ExpressionExperimentSet(ubic.gemma.model.analysis.expression.ExpressionExperimentSet) HashSet(java.util.HashSet) Test(org.junit.Test) BaseSpringContextTest(ubic.gemma.core.testing.BaseSpringContextTest)

Example 7 with ExpressionExperimentSet

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);
}
Also used : ExpressionExperimentSet(ubic.gemma.model.analysis.expression.ExpressionExperimentSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with ExpressionExperimentSet

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);
    }
}
Also used : ExpressionExperimentSet(ubic.gemma.model.analysis.expression.ExpressionExperimentSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with ExpressionExperimentSet

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;
}
Also used : BioAssaySet(ubic.gemma.model.expression.experiment.BioAssaySet) Taxon(ubic.gemma.model.genome.Taxon) ExpressionExperimentSet(ubic.gemma.model.analysis.expression.ExpressionExperimentSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with ExpressionExperimentSet

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);
}
Also used : BioAssaySet(ubic.gemma.model.expression.experiment.BioAssaySet) Taxon(ubic.gemma.model.genome.Taxon) ExpressionExperimentSet(ubic.gemma.model.analysis.expression.ExpressionExperimentSet) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ExpressionExperimentSet (ubic.gemma.model.analysis.expression.ExpressionExperimentSet)18 HashSet (java.util.HashSet)6 Transactional (org.springframework.transaction.annotation.Transactional)6 BioAssaySet (ubic.gemma.model.expression.experiment.BioAssaySet)6 Taxon (ubic.gemma.model.genome.Taxon)6 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)4 Test (org.junit.Test)3 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)3 Gene (ubic.gemma.model.genome.Gene)3 ArrayList (java.util.ArrayList)2 StopWatch (org.apache.commons.lang3.time.StopWatch)2 Element (org.w3c.dom.Element)2 ExpressionExperimentSetValueObject (ubic.gemma.model.expression.experiment.ExpressionExperimentSetValueObject)2 AclObjectIdentity (gemma.gsec.acl.domain.AclObjectIdentity)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 LinkedList (java.util.LinkedList)1 Acl (org.springframework.security.acls.model.Acl)1 CoexpressionMetaValueObject (ubic.gemma.core.analysis.expression.coexpression.CoexpressionMetaValueObject)1 CoexpressionValueObjectExt (ubic.gemma.core.analysis.expression.coexpression.CoexpressionValueObjectExt)1