Search in sources :

Example 1 with BioAssayValueObject

use of ubic.gemma.model.expression.bioAssay.BioAssayValueObject in project Gemma by PavlidisLab.

the class AssayViewTag method doStartTag.

@Override
public int doStartTag() throws JspException {
    StringBuilder buf = new StringBuilder();
    buf.append("<div>");
    // create table
    Map<BioMaterialValueObject, Map<ArrayDesignValueObject, Collection<BioAssayValueObject>>> bioAssayMap = new HashMap<>();
    Set<ArrayDesignValueObject> designs = new HashSet<>();
    Map<ArrayDesignValueObject, Long> arrayMaterialCount = new HashMap<>();
    // package all of this information into JSON for javascript dynamic retrieval
    Map<String, String> assayToMaterial = new HashMap<>();
    for (BioAssayValueObject assay : bioAssays) {
        // map for bioassays linked to a specific arraydesign
        // map for the bioassays linked to a specific biomaterial
        BioMaterialValueObject material = assay.getSample();
        ArrayDesignValueObject design = assay.getArrayDesign();
        designs.add(design);
        // check if the assay list is initialized yet
        Map<ArrayDesignValueObject, Collection<BioAssayValueObject>> assayMap;
        if (bioAssayMap.containsKey(material)) {
            assayMap = bioAssayMap.get(material);
        } else {
            assayMap = new HashMap<>();
            bioAssayMap.put(material, assayMap);
        }
        if (assayMap.containsKey(design)) {
            assayMap.get(design).add(assay);
        } else {
            Collection<BioAssayValueObject> assayList = new ArrayList<>();
            assayList.add(assay);
            assayMap.put(design, assayList);
        }
        if (arrayMaterialCount.containsKey(design)) {
            Long count = arrayMaterialCount.get(design);
            count++;
            arrayMaterialCount.put(design, count);
        } else {
            Long count = new Long(1);
            arrayMaterialCount.put(design, count);
        }
    }
    int materialCount = bioAssayMap.keySet().size();
    buf.append("<table class='detail row-separated odd-gray'><tr>");
    buf.append("<th>" + materialCount + " BioMaterials</th>");
    // display arraydesigns
    for (ArrayDesignValueObject design : designs) {
        Long count = arrayMaterialCount.get(design);
        buf.append("<th>" + count + " BioAssays on<br /><a target='_blank' href=\"" + Settings.getRootContext() + "/arrays/showArrayDesign.html?id=" + design.getId() + "\" title=\"" + design.getName() + "\" >" + (design.getShortName() == null ? design.getName() : design.getShortName()) + "</a></th>");
    }
    buf.append("</tr>");
    // display bioMaterials and the corresponding bioAssays
    int count = 1;
    Iterator<BioMaterialValueObject> iter = bioAssayMap.keySet().iterator();
    List<BioMaterialValueObject> materials = new ArrayList<>();
    while (iter.hasNext()) {
        materials.add(iter.next());
    }
    Comparator<BioMaterialValueObject> comparator = new BioMaterialComparator();
    Collections.sort(materials, comparator);
    int elementCount = 1;
    int emptyCount = 0;
    for (BioMaterialValueObject material : materials) {
        if (count % 2 == 0) {
            buf.append("<tr class='even' align=justify>");
        } else {
            buf.append("<tr class='odd' align=justify>");
        }
        String bmLink = "<a href='" + Settings.getRootContext() + "/bioMaterial/showBioMaterial.html?id=" + material.getId() + "'> " + material.getName() + "</a>";
        buf.append("<td>" + bmLink + "</td>");
        Map<ArrayDesignValueObject, Collection<BioAssayValueObject>> assayMap = bioAssayMap.get(material);
        String image = "&nbsp;&nbsp;&nbsp;<img height=16 width=16 src='" + Settings.getRootContext() + "/images/icons/arrow_switch.png' />&nbsp;&nbsp;&nbsp;";
        for (ArrayDesignValueObject design : designs) {
            if (assayMap.containsKey(design)) {
                Collection<BioAssayValueObject> assays = assayMap.get(design);
                Collection<Long> ids = new ArrayList<>();
                Collection<String> tooltips = new ArrayList<>();
                for (BioAssayValueObject assay : assays) {
                    ids.add(assay.getId());
                    tooltips.add(StringUtils.abbreviate(assay.getName() + assay.getDescription(), 120));
                    this.addMaterial(assayToMaterial, assay.getId(), material.getId());
                }
                if (assayMap.get(design).size() > 1) {
                    String link = "<a title='" + StringUtils.join(tooltips.toArray(), "\n") + "' href='" + Settings.getRootContext() + "/bioAssay/showAllBioAssays.html?id=" + StringUtils.join(ids.toArray(), ",") + "'> (list) </a>";
                    buf.append("<td>" + assayMap.get(design).size() + link + "&nbsp;" + elementCount + "</td>\n");
                } else {
                    /*
                         * Each bioassay has a unique id; the div it sits in is identified by the class 'dragitem'. See
                         * expressionExperiment.edit.jsp.
                         */
                    BioAssayValueObject assay = ((List<BioAssayValueObject>) assayMap.get(design)).get(0);
                    String shortDesc = StringUtils.abbreviate(assay.getDescription(), 60);
                    String link = "<a target=\"_blank\" title='" + shortDesc + "' href='" + Settings.getRootContext() + "/bioAssay/showBioAssay.html?id=" + assay.getId() + "'>" + assay.getName() + "</a>";
                    String editAttributes = " align='left' class='dragItem' id='bioassay." + assay.getId() + "' material='" + material.getId() + "' assay='" + assay.getId() + "' arrayDesign='" + design.getId() + "'";
                    if (edit && designs.size() > 1) {
                        buf.append("\n<td><span " + editAttributes + ">" + image + link);
                    } else {
                        buf.append("\n<td ><span>" + link + "&nbsp;");
                    }
                    buf.append("</span></td>\n");
                }
            } else {
                emptyCount = addEmpty(buf, assayToMaterial, emptyCount, material, image, design);
            }
        }
        buf.append("</tr>");
        count++;
        elementCount++;
    }
    // add a few blanks, but only if we are editing.
    if (edit) {
        addNovelBiomaterialSlots(buf, designs, assayToMaterial, count, emptyCount);
    }
    buf.append("</table>");
    if (edit) {
        // append JSON serialization
        try {
            String jsonSerialization = JSONMapper.toJSON(assayToMaterial).render(false);
            buf.append("<input type='hidden' id='assayToMaterialMap' name='assayToMaterialMap' value='" + jsonSerialization + "'/>");
        } catch (MapperException e) {
        // cannot serialize
        }
    }
    buf.append("</div>");
    try {
        pageContext.getOut().print(buf.toString());
    } catch (Exception ex) {
        throw new JspException("assayViewTag: " + ex.getMessage());
    }
    return SKIP_BODY;
}
Also used : JspException(javax.servlet.jsp.JspException) ArrayDesignValueObject(ubic.gemma.model.expression.arrayDesign.ArrayDesignValueObject) MapperException(com.sdicons.json.mapper.MapperException) MapperException(com.sdicons.json.mapper.MapperException) JspException(javax.servlet.jsp.JspException) BioAssayValueObject(ubic.gemma.model.expression.bioAssay.BioAssayValueObject) BioMaterialValueObject(ubic.gemma.model.expression.biomaterial.BioMaterialValueObject)

Example 2 with BioAssayValueObject

use of ubic.gemma.model.expression.bioAssay.BioAssayValueObject in project Gemma by PavlidisLab.

the class ExperimentalDesignVisualizationServiceImpl method prepare.

/**
 * Gets the bioassay dimensions for the experiments associated with the given vectors. These are cached for later
 * re-use.
 */
private void prepare(Collection<DoubleVectorValueObject> dvvOs) {
    if (dvvOs == null)
        return;
    for (DoubleVectorValueObject vec : dvvOs) {
        if (vec == null) {
            log.debug("DoubleVectorValueObject is null");
            continue;
        }
        if (vec.isReorganized()) {
            // wouldn't normally be the case...
            continue;
        }
        ExpressionExperimentValueObject ee = vec.getExpressionExperiment();
        /*
             * Problem: we can't have two layouts for one experiment, which is actually required if there is more than
             * one bioassay dimension. However, this rarely matters. See bug 3775
             */
        if (cachedLayouts.containsKey(ee.getId())) {
            continue;
        } else if (vec.getClass().isInstance(ExpressionExperimentSubsetValueObject.class)) {
            ExpressionExperimentSubsetValueObject eesvo = (ExpressionExperimentSubsetValueObject) vec.getExpressionExperiment();
            if (eesvo.getSourceExperiment() != null && cachedLayouts.containsKey(eesvo.getSourceExperiment())) {
                continue;
            }
        }
        BioAssayDimensionValueObject bioAssayDimension = this.getBioAssayDimensionForVector(vec);
        ExpressionExperiment actualEe = this.getExperimentForVector(vec, ee);
        assert bioAssayDimension != null;
        LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>> experimentalDesignLayout = this.getExperimentalDesignLayout(actualEe, expressionExperimentService.getBioAssayDimensions(actualEe));
        cachedLayouts.put(ee.getId(), experimentalDesignLayout);
    }
}
Also used : BioAssayDimensionValueObject(ubic.gemma.model.expression.bioAssayData.BioAssayDimensionValueObject) BioAssayValueObject(ubic.gemma.model.expression.bioAssay.BioAssayValueObject) DoubleVectorValueObject(ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject)

Example 3 with BioAssayValueObject

use of ubic.gemma.model.expression.bioAssay.BioAssayValueObject 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)

Example 4 with BioAssayValueObject

use of ubic.gemma.model.expression.bioAssay.BioAssayValueObject in project Gemma by PavlidisLab.

the class ExperimentalDesignVisualizationServiceImpl method extendLayout.

/**
 * See bug 3775. For experiments which have more than one bioassay dimension, we typically have to "extend" the
 * layout to include more bioassays. Because the ordering is defined by the factor values associated with the
 * underlying biomaterials, this is going to be okay.
 */
private LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>> extendLayout(DoubleVectorValueObject vec, Long eeId) {
    BioAssayDimensionValueObject bioAssayDimension = this.getBioAssayDimensionForVector(vec);
    ExpressionExperimentValueObject ee = vec.getExpressionExperiment();
    ExpressionExperiment actualEe = this.getExperimentForVector(vec, ee);
    LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>> extension = this.getExperimentalDesignLayout(actualEe, expressionExperimentService.getBioAssayDimensions(actualEe));
    for (BioAssayValueObject vbaVo : bioAssayDimension.getBioAssays()) {
        assert extension.containsKey(vbaVo);
    }
    for (BioAssayValueObject vbaVo : vec.getBioAssays()) {
        assert extension.containsKey(vbaVo);
    }
    cachedLayouts.get(eeId).putAll(extension);
    return cachedLayouts.get(eeId);
}
Also used : BioAssayDimensionValueObject(ubic.gemma.model.expression.bioAssayData.BioAssayDimensionValueObject) BioAssayValueObject(ubic.gemma.model.expression.bioAssay.BioAssayValueObject)

Example 5 with BioAssayValueObject

use of ubic.gemma.model.expression.bioAssay.BioAssayValueObject in project Gemma by PavlidisLab.

the class VectorElementValueObject method average.

private VectorElementValueObject average(List<DoubleVectorValueObject> vectors) {
    StringBuilder name = new StringBuilder(GeneElementExpressionsValueObject.AVG_PREFIX);
    Map<String, Double> bioAssayValues = new HashMap<>();
    for (DoubleVectorValueObject vo : vectors) {
        for (int i = 0; i < vo.getBioAssays().size(); i++) {
            BioAssayValueObject bvo = vo.getBioAssays().get(i);
            if (bioAssayValues.containsKey(bvo.getName())) {
                bioAssayValues.put(bvo.getName(), bioAssayValues.get(bvo.getName()) + vo.getData()[i]);
            } else {
                bioAssayValues.put(bvo.getName(), vo.getData()[i]);
            }
        }
        name.append(" ");
        name.append(vo.getDesignElement().getName());
    }
    for (Map.Entry<String, Double> entry : bioAssayValues.entrySet()) {
        entry.setValue(entry.getValue() / vectors.size());
    }
    return new VectorElementValueObject(name.toString(), bioAssayValues);
}
Also used : BioAssayValueObject(ubic.gemma.model.expression.bioAssay.BioAssayValueObject) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

BioAssayValueObject (ubic.gemma.model.expression.bioAssay.BioAssayValueObject)20 DoubleVectorValueObject (ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject)7 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)6 BioMaterialValueObject (ubic.gemma.model.expression.biomaterial.BioMaterialValueObject)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 StopWatch (org.apache.commons.lang3.time.StopWatch)3 ArrayDesignValueObject (ubic.gemma.model.expression.arrayDesign.ArrayDesignValueObject)3 BioAssayDimensionValueObject (ubic.gemma.model.expression.bioAssayData.BioAssayDimensionValueObject)3 HashSet (java.util.HashSet)2 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)2 GeneValueObject (ubic.gemma.model.genome.gene.GeneValueObject)2 VisualizationValueObject (ubic.gemma.web.controller.visualization.VisualizationValueObject)2 DoubleArrayList (cern.colt.list.DoubleArrayList)1 MapperException (com.sdicons.json.mapper.MapperException)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 JspException (javax.servlet.jsp.JspException)1 Test (org.junit.Test)1