Search in sources :

Example 31 with FactorValue

use of ubic.gemma.model.expression.experiment.FactorValue 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 32 with FactorValue

use of ubic.gemma.model.expression.experiment.FactorValue 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 33 with FactorValue

use of ubic.gemma.model.expression.experiment.FactorValue in project Gemma by PavlidisLab.

the class ExpressionExperimentSubSetDaoImpl method getFactorValuesUsed.

@Override
public Collection<FactorValueValueObject> getFactorValuesUsed(Long subSetId, Long experimentalFactor) {
    // noinspection unchecked
    List<FactorValue> list = this.getSessionFactory().getCurrentSession().createQuery("select distinct fv from ExpressionExperimentSubSet es join es.bioAssays ba join ba.sampleUsed bm " + "join bm.factorValues fv where es.id=:es and fv.experimentalFactor.id = :ef ").setParameter("es", subSetId).setParameter("ef", experimentalFactor).list();
    Collection<FactorValueValueObject> result = new HashSet<>();
    for (FactorValue fv : list) {
        result.add(new FactorValueValueObject(fv));
    }
    return result;
}
Also used : FactorValueValueObject(ubic.gemma.model.expression.experiment.FactorValueValueObject) FactorValue(ubic.gemma.model.expression.experiment.FactorValue) HashSet(java.util.HashSet)

Example 34 with FactorValue

use of ubic.gemma.model.expression.experiment.FactorValue in project Gemma by PavlidisLab.

the class BioMaterialServiceImpl method update.

private BioMaterial update(BioMaterialValueObject bmvo) {
    BioMaterial bm = this.load(bmvo.getId());
    Collection<FactorValue> updatedFactorValues = new HashSet<>();
    // all of them.
    Map<String, String> factorIdToFactorValueId = bmvo.getFactorIdToFactorValueId();
    for (String factorIdString : factorIdToFactorValueId.keySet()) {
        String factorValueString = factorIdToFactorValueId.get(factorIdString);
        assert factorIdString.matches("factor\\d+");
        Long factorId = Long.parseLong(factorIdString.substring(6));
        // noinspection StatementWithEmptyBody // no value provided, that's okay, the curator can fill it in later.
        if (StringUtils.isBlank(factorValueString)) {
        } else if (factorValueString.matches("fv\\d+")) {
            // categorical
            long fvId = Long.parseLong(factorValueString.substring(2));
            FactorValue fv = factorValueDao.load(fvId);
            if (fv == null) {
                throw new RuntimeException("No such factorValue with id=" + fvId);
            }
            updatedFactorValues.add(fv);
        } else {
            // continuous, the value send is the actual value, not an id. This will only make sense if the value is
            // a measurement.
            boolean found = false;
            // find the right factor value to update.
            for (FactorValue fv : bm.getFactorValues()) {
                if (fv.getExperimentalFactor().getId().equals(factorId)) {
                    if (fv.getMeasurement() == null) {
                        throw new IllegalStateException("Should have been a measurement associated with fv=" + fv + ", cannot update.");
                    } else if (!fv.getMeasurement().getValue().equals(factorValueString)) {
                        AbstractService.log.debug("Updating continuous value on biomaterial:" + bmvo + ", factor=" + fv.getExperimentalFactor() + " value= '" + factorValueString + "'");
                        fv.getMeasurement().setValue(factorValueString);
                    } else {
                        AbstractService.log.debug("Value unchanged from " + fv.getMeasurement().getValue());
                    }
                    // always add...
                    updatedFactorValues.add(fv);
                    found = true;
                    break;
                }
            }
            if (!found) {
                /*
                     * Have to load the factor, create a factor value.
                     */
                ExperimentalFactor ef = experimentalFactorDao.load(factorId);
                // note that this type of factorvalues are not reused for continuous ones.
                AbstractService.log.info("Adding factor value for " + ef + ": " + factorValueString + " to " + bm);
                FactorValue fv = FactorValue.Factory.newInstance();
                fv.setExperimentalFactor(ef);
                fv.setValue(factorValueString);
                Measurement m = Measurement.Factory.newInstance();
                m.setType(MeasurementType.ABSOLUTE);
                m.setValue(fv.getValue());
                try {
                    // noinspection ResultOfMethodCallIgnored // check if it is a number, don't need the value.
                    Double.parseDouble(fv.getValue());
                    m.setRepresentation(PrimitiveType.DOUBLE);
                } catch (NumberFormatException e) {
                    m.setRepresentation(PrimitiveType.STRING);
                }
                fv.setMeasurement(m);
                fv = factorValueDao.create(fv);
                updatedFactorValues.add(fv);
                ef.getFactorValues().add(fv);
                experimentalFactorDao.update(ef);
            }
        }
    }
    // this is not valid, because it's possible that we are removing a factor value.
    // assert bm.getFactorValues().size() <= updatedFactorValues.size();
    bm.getFactorValues().clear();
    bm.getFactorValues().addAll(updatedFactorValues);
    assert !bm.getFactorValues().isEmpty();
    this.update(bm);
    assert !bm.getFactorValues().isEmpty();
    return bm;
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) Measurement(ubic.gemma.model.common.measurement.Measurement) FactorValue(ubic.gemma.model.expression.experiment.FactorValue) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) HashSet(java.util.HashSet)

Example 35 with FactorValue

use of ubic.gemma.model.expression.experiment.FactorValue in project Gemma by PavlidisLab.

the class ExperimentalDesignUtils method extractFactorValueForSample.

private static Object extractFactorValueForSample(Map<ExperimentalFactor, FactorValue> baselines, BioMaterial samp, ExperimentalFactor factor) {
    FactorValue baseLineFV = baselines.get(factor);
    /*
         * Find this biomaterial's value for the current factor.
         */
    Object value = null;
    boolean found = false;
    for (FactorValue fv : samp.getFactorValues()) {
        if (fv.getExperimentalFactor().equals(factor)) {
            if (found) {
                // not unique
                throw new IllegalStateException("Biomaterial had more than one value for factor: " + factor);
            }
            boolean isBaseline = baseLineFV != null && fv.equals(baseLineFV);
            if (ExperimentalDesignUtils.isContinuous(factor)) {
                Measurement measurement = fv.getMeasurement();
                assert measurement != null;
                try {
                    value = Double.parseDouble(measurement.getValue());
                } catch (NumberFormatException e) {
                    value = Double.NaN;
                }
            } else {
                /*
                     * We always use a dummy value. It's not as human-readable but at least we're sure it is unique and
                     * R-compliant. (assuming the fv is persistent!)
                     */
                value = ExperimentalDesignUtils.nameForR(fv, isBaseline);
            }
            found = true;
        // could break here but nice to check for uniqueness.
        }
    }
    if (!found) {
        return null;
    }
    return value;
}
Also used : Measurement(ubic.gemma.model.common.measurement.Measurement) FactorValue(ubic.gemma.model.expression.experiment.FactorValue) ExperimentalFactorValueObject(ubic.gemma.model.expression.experiment.ExperimentalFactorValueObject)

Aggregations

FactorValue (ubic.gemma.model.expression.experiment.FactorValue)55 ExperimentalFactor (ubic.gemma.model.expression.experiment.ExperimentalFactor)30 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)27 Test (org.junit.Test)12 VocabCharacteristic (ubic.gemma.model.common.description.VocabCharacteristic)8 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)8 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)8 HashSet (java.util.HashSet)7 Characteristic (ubic.gemma.model.common.description.Characteristic)6 DifferentialExpressionAnalysis (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis)5 ArrayList (java.util.ArrayList)4 AbstractGeoServiceTest (ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest)4 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)4 FactorValueValueObject (ubic.gemma.model.expression.experiment.FactorValueValueObject)4 StopWatch (org.apache.commons.lang3.time.StopWatch)3 DifferentialExpressionAnalysisResult (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysisResult)3 ExpressionAnalysisResultSet (ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet)3 AnnotationValueObject (ubic.gemma.model.common.description.AnnotationValueObject)3 Measurement (ubic.gemma.model.common.measurement.Measurement)3 BioAssaySet (ubic.gemma.model.expression.experiment.BioAssaySet)3