Search in sources :

Example 81 with BioMaterial

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

the class ExperimentalDesignImporterTestB method testParseLoadDelete.

@Test
public final void testParseLoadDelete() throws Exception {
    try (InputStream is = this.getClass().getResourceAsStream("/data/loader/expression/gill2007temperatureGemmaAnnotationData.txt")) {
        experimentalDesignImporter.importDesign(ee, is);
    }
    this.checkResults();
    this.aclTestUtils.checkEEAcls(ee);
    ee = this.expressionExperimentService.load(ee.getId());
    ee = expressionExperimentService.thawLite(ee);
    int s = ee.getExperimentalDesign().getExperimentalFactors().size();
    ExperimentalFactor toDelete = ee.getExperimentalDesign().getExperimentalFactors().iterator().next();
    experimentalFactorService.delete(toDelete);
    ee = this.expressionExperimentService.load(ee.getId());
    ee = expressionExperimentService.thawLite(ee);
    assertEquals(s - 1, ee.getExperimentalDesign().getExperimentalFactors().size());
    for (BioAssay ba : ee.getBioAssays()) {
        BioMaterial bm = ba.getSampleUsed();
        for (FactorValue fv : bm.getFactorValues()) {
            assertTrue(!fv.getExperimentalFactor().equals(toDelete));
        }
    }
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) FactorValue(ubic.gemma.model.expression.experiment.FactorValue) InputStream(java.io.InputStream) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay) Test(org.junit.Test) BaseSpringContextTest(ubic.gemma.core.testing.BaseSpringContextTest)

Example 82 with BioMaterial

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

the class CharacteristicUpdateTaskImpl method removeFromParent.

private void removeFromParent(Characteristic c, Object parent) {
    if (parent instanceof ExpressionExperiment) {
        ExpressionExperiment ee = (ExpressionExperiment) parent;
        ee = expressionExperimentService.thawLite(ee);
        ee.getCharacteristics().remove(c);
        expressionExperimentService.update(ee);
    } else if (parent instanceof BioMaterial) {
        BioMaterial bm = (BioMaterial) parent;
        bm.getCharacteristics().remove(c);
        bioMaterialService.update(bm);
    } else if (parent instanceof FactorValue) {
        FactorValue fv = (FactorValue) parent;
        fv.getCharacteristics().remove(c);
        factorValueService.update(fv);
    }
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) FactorValue(ubic.gemma.model.expression.experiment.FactorValue) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment)

Example 83 with BioMaterial

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

the class BioAssayDimensionValueObject method makeDummyBioAssayDimension.

private BioAssayDimension makeDummyBioAssayDimension() {
    assert this.id == null;
    BioAssayDimension fakeBd = BioAssayDimension.Factory.newInstance("Placeholder representing: " + name, description, new ArrayList<BioAssay>());
    Map<Long, ExperimentalFactor> fakeEfs = new HashMap<>();
    for (BioAssayValueObject bav : this.bioAssays) {
        BioAssay ba = BioAssay.Factory.newInstance();
        ba.setId(bav.getId());
        ba.setName(bav.getName());
        ba.setDescription("Fake placeholder");
        BioMaterial sampleUsed = BioMaterial.Factory.newInstance();
        BioMaterialValueObject bmVo = bav.getSample();
        assert bmVo != null;
        sampleUsed.setId(bmVo.getId());
        sampleUsed.setName(bmVo.getName());
        sampleUsed.setDescription("Fake placeholder");
        for (IdentifiableValueObject iVo : bmVo.getFactorValueObjects()) {
            FactorValueValueObject fvVo = (FactorValueValueObject) iVo;
            FactorValue fv = FactorValue.Factory.newInstance();
            assert fvVo.getId() != null;
            fv.setId(fvVo.getId());
            assert fvVo.getValue() != null;
            fv.setValue(fvVo.getValue());
            Long efId = fvVo.getFactorId();
            ExperimentalFactor ef;
            if (fakeEfs.containsKey(efId)) {
                ef = fakeEfs.get(efId);
            } else {
                ef = ExperimentalFactor.Factory.newInstance();
                ef.setId(efId);
                ef.setName(fvVo.getCategory());
                ef.setType(fvVo.isMeasurement() ? FactorType.CONTINUOUS : FactorType.CATEGORICAL);
                fakeEfs.put(efId, ef);
            }
            ef.getFactorValues().add(fv);
            fv.setExperimentalFactor(ef);
            sampleUsed.getFactorValues().add(fv);
        }
        ba.setSampleUsed(sampleUsed);
        ArrayDesign ad = ArrayDesign.Factory.newInstance();
        ArrayDesignValueObject adVo = bav.getArrayDesign();
        assert adVo != null;
        ad.setId(adVo.getId());
        ad.setShortName(adVo.getShortName());
        ad.setDescription("Fake placeholder");
        ba.setArrayDesignUsed(ad);
        fakeBd.getBioAssays().add(ba);
    }
    return fakeBd;
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) FactorValueValueObject(ubic.gemma.model.expression.experiment.FactorValueValueObject) FactorValue(ubic.gemma.model.expression.experiment.FactorValue) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) ArrayDesignValueObject(ubic.gemma.model.expression.arrayDesign.ArrayDesignValueObject) BioAssayValueObject(ubic.gemma.model.expression.bioAssay.BioAssayValueObject) IdentifiableValueObject(ubic.gemma.model.IdentifiableValueObject) BioMaterialValueObject(ubic.gemma.model.expression.biomaterial.BioMaterialValueObject) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay)

Example 84 with BioMaterial

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

the class FactorValueDaoImpl method remove.

@Override
public void remove(final FactorValue factorValue) {
    if (factorValue == null)
        return;
    // noinspection unchecked
    Collection<BioMaterial> bms = this.getSessionFactory().getCurrentSession().createQuery("select distinct bm from BioMaterial as bm join bm.factorValues fv where fv = :fv").setParameter("fv", factorValue).list();
    AbstractDao.log.info("Disassociating " + factorValue + " from " + bms.size() + " biomaterials");
    for (BioMaterial bioMaterial : bms) {
        // temporary, debugging.
        AbstractDao.log.info("Processing " + bioMaterial);
        if (bioMaterial.getFactorValues().remove(factorValue)) {
            this.getSessionFactory().getCurrentSession().update(bioMaterial);
        } else {
            AbstractDao.log.warn("Unexpectedly the factor value was not actually associated with " + bioMaterial);
        }
    }
    List<?> efs = this.getHibernateTemplate().findByNamedParam("select ef from ExperimentalFactor ef join ef.factorValues fv where fv = :fv", "fv", factorValue);
    ExperimentalFactor ef = (ExperimentalFactor) efs.iterator().next();
    ef.getFactorValues().remove(factorValue);
    this.getSessionFactory().getCurrentSession().update(ef);
    // will get the dreaded 'already in session' error if we don't do this.
    this.getSessionFactory().getCurrentSession().flush();
    this.getSessionFactory().getCurrentSession().clear();
    this.getSessionFactory().getCurrentSession().delete(factorValue);
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor)

Example 85 with BioMaterial

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

the class BioMaterialDaoImpl method copy.

@Override
public BioMaterial copy(final BioMaterial bioMaterial) {
    BioMaterial newMaterial = BioMaterial.Factory.newInstance();
    newMaterial.setDescription(bioMaterial.getDescription() + " [Created by Gemma]");
    newMaterial.setCharacteristics(bioMaterial.getCharacteristics());
    newMaterial.setSourceTaxon(bioMaterial.getSourceTaxon());
    newMaterial.setTreatments(bioMaterial.getTreatments());
    newMaterial.setFactorValues(bioMaterial.getFactorValues());
    newMaterial.setName("Modeled after " + bioMaterial.getName());
    newMaterial = this.findOrCreate(newMaterial);
    return newMaterial;
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial)

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