Search in sources :

Example 1 with EmptyExpressionMatrix

use of ubic.gemma.core.datastructure.matrix.EmptyExpressionMatrix in project Gemma by PavlidisLab.

the class ExperimentalDesignVisualizationServiceImpl method getExperimentalDesignLayout.

/**
 * @param bds a BioAssayDimension that represents the BioAssayDimensionValueObject. This is only needed to avoid
 *            making ExpressionMatrix use value objects, otherwise we could use the BioAssayDimensionValueObject
 * @return A "Layout": a map of bioassays to map of factors to doubles that represent the position in the layout.
 */
private LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>> getExperimentalDesignLayout(ExpressionExperiment experiment, Collection<BioAssayDimension> bds) {
    LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>> result = new LinkedHashMap<>();
    ExpressionDataMatrix<Object> mat = new EmptyExpressionMatrix(bds);
    // This is the place the actual sort order is determined.
    List<BioMaterial> bms = ExpressionDataMatrixColumnSort.orderByExperimentalDesign(mat);
    Map<Long, Double> fvV = new HashMap<>();
    assert experiment != null;
    assert experiment.getExperimentalDesign() != null;
    if (experiment.getExperimentalDesign().getExperimentalFactors().isEmpty()) {
        // Case of no experimental design; just put in a dummy factor.
        ExperimentalFactor dummyFactor = ExperimentalFactor.Factory.newInstance();
        dummyFactor.setName("No factors");
        for (BioMaterial bm : bms) {
            int j = mat.getColumnIndex(bm);
            Collection<BioAssay> bas = mat.getBioAssaysForColumn(j);
            for (BioAssay ba : bas) {
                BioAssayValueObject baVo = new BioAssayValueObject(ba, false);
                result.put(baVo, new LinkedHashMap<ExperimentalFactor, Double>());
                result.get(baVo).put(dummyFactor, 0.0);
            }
        }
        return result;
    }
    assert !experiment.getExperimentalDesign().getExperimentalFactors().isEmpty();
    // Map<ExperimentalFactor, Map<FactorValue, Double>> continuousRanges = new HashMap<>();
    for (ExperimentalFactor ef : experiment.getExperimentalDesign().getExperimentalFactors()) {
        if (ef.getFactorValues().isEmpty()) {
            // this can happen if the design isn't complete.
            continue;
        }
        for (FactorValue fv : ef.getFactorValues()) {
            assert fv.getId() != null;
            // the id is just used as a convenience.
            fvV.put(fv.getId(), new Double(fv.getId()));
        }
    }
    assert !fvV.isEmpty();
    assert !bms.isEmpty();
    // either bioassay dimension.
    for (BioMaterial bm : bms) {
        int j = mat.getColumnIndex(bm);
        Collection<BioAssay> bas = mat.getBioAssaysForColumn(j);
        Collection<FactorValue> fvs = bm.getFactorValues();
        for (BioAssay ba : bas) {
            BioAssayValueObject baVo = new BioAssayValueObject(ba, false);
            result.put(baVo, new LinkedHashMap<ExperimentalFactor, Double>(fvs.size()));
            for (FactorValue fv : fvs) {
                assert fv.getId() != null;
                assert fvV.containsKey(fv.getId());
                ExperimentalFactor ef = fv.getExperimentalFactor();
                Double value;
                if (fv.getMeasurement() != null) {
                    try {
                        value = Double.parseDouble(fv.getMeasurement().getValue());
                    } catch (NumberFormatException e) {
                        // not good.
                        value = fvV.get(fv.getId());
                    }
                } else {
                    value = fvV.get(fv.getId());
                }
                assert result.containsKey(baVo);
                assert value != null;
                result.get(baVo).put(ef, value);
            }
        }
    }
    return result;
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) EmptyExpressionMatrix(ubic.gemma.core.datastructure.matrix.EmptyExpressionMatrix) BioAssayValueObject(ubic.gemma.model.expression.bioAssay.BioAssayValueObject) DoubleVectorValueObject(ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject) BioAssayValueObject(ubic.gemma.model.expression.bioAssay.BioAssayValueObject) BioAssayDimensionValueObject(ubic.gemma.model.expression.bioAssayData.BioAssayDimensionValueObject) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay)

Aggregations

ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 EmptyExpressionMatrix (ubic.gemma.core.datastructure.matrix.EmptyExpressionMatrix)1 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)1 BioAssayValueObject (ubic.gemma.model.expression.bioAssay.BioAssayValueObject)1 BioAssayDimensionValueObject (ubic.gemma.model.expression.bioAssayData.BioAssayDimensionValueObject)1 DoubleVectorValueObject (ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject)1 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)1