Search in sources :

Example 1 with DiscreteMapping

use of org.cytoscape.view.vizmap.mappings.DiscreteMapping in project EnrichmentMapApp by BaderLab.

the class EMStyleBuilder method setEdgeLineType.

private void setEdgeLineType(VisualStyle vs, EMStyleOptions options) {
    String col = CyEdge.INTERACTION;
    DiscreteMapping<String, LineType> dm = (DiscreteMapping<String, LineType>) dmFactory.createVisualMappingFunction(col, String.class, EDGE_LINE_TYPE);
    // Silence events fired by this mapping to prevent unnecessary style and view updates
    eventHelper.silenceEventSource(dm);
    try {
        LineType sigLineType = LineTypeVisualProperty.DOT;
        if (EDGE_LINE_TYPE.getRange().isDiscrete()) {
            DiscreteRange<LineType> range = (DiscreteRange<LineType>) EDGE_LINE_TYPE.getRange();
            Optional<LineType> first = range.values().stream().filter(v -> "MARQUEE_EQUAL".equalsIgnoreCase(v.getSerializableString())).findFirst();
            if (first.isPresent())
                sigLineType = first.get();
        }
        dm.putMapValue(Columns.EDGE_DATASET_VALUE_COMPOUND, LineTypeVisualProperty.SOLID);
        dm.putMapValue(Columns.EDGE_INTERACTION_VALUE_SIG, sigLineType);
    } finally {
        eventHelper.unsilenceEventSource(dm);
    }
    vs.addVisualMappingFunction(dm);
}
Also used : Color(java.awt.Color) NODE_SHAPE(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_SHAPE) RECTANGLE(org.cytoscape.view.presentation.property.NodeShapeVisualProperty.RECTANGLE) NODE_BORDER_TRANSPARENCY(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_BORDER_TRANSPARENCY) NodeShape(org.cytoscape.view.presentation.property.values.NodeShape) Inject(com.google.inject.Inject) EDGE_UNSELECTED_PAINT(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_UNSELECTED_PAINT) LineType(org.cytoscape.view.presentation.property.values.LineType) ColorBrewer(org.jcolorbrewer.ColorBrewer) View(org.cytoscape.view.model.View) CyCustomGraphics2(org.cytoscape.view.presentation.customgraphics.CyCustomGraphics2) NODE_TOOLTIP(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_TOOLTIP) Discrete(org.baderlab.csplugins.enrichmentmap.CytoscapeServiceModule.Discrete) CyNetwork(org.cytoscape.model.CyNetwork) NODE_SIZE(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_SIZE) NODE_FILL_COLOR(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_FILL_COLOR) VisualStyleChangedEvent(org.cytoscape.view.vizmap.events.VisualStyleChangedEvent) BasicVisualLexicon(org.cytoscape.view.presentation.property.BasicVisualLexicon) RenderingEngineManager(org.cytoscape.view.presentation.RenderingEngineManager) VisualLexicon(org.cytoscape.view.model.VisualLexicon) Collectors(java.util.stream.Collectors) AbstractDataSet(org.baderlab.csplugins.enrichmentmap.model.AbstractDataSet) List(java.util.List) NETWORK_BACKGROUND_PAINT(org.cytoscape.view.presentation.property.BasicVisualLexicon.NETWORK_BACKGROUND_PAINT) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) Paint(java.awt.Paint) DIAMOND(org.cytoscape.view.presentation.property.NodeShapeVisualProperty.DIAMOND) Optional(java.util.Optional) NODE_LABEL(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_LABEL) LineTypeVisualProperty(org.cytoscape.view.presentation.property.LineTypeVisualProperty) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) ContinuousMapping(org.cytoscape.view.vizmap.mappings.ContinuousMapping) Passthrough(org.baderlab.csplugins.enrichmentmap.CytoscapeServiceModule.Passthrough) EDGE_LINE_TYPE(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_LINE_TYPE) EDGE_STROKE_UNSELECTED_PAINT(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_STROKE_UNSELECTED_PAINT) CyNode(org.cytoscape.model.CyNode) PassthroughMapping(org.cytoscape.view.vizmap.mappings.PassthroughMapping) EnrichmentMap(org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap) EDGE_LABEL_TRANSPARENCY(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_LABEL_TRANSPARENCY) EDGE_WIDTH(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_WIDTH) ELLIPSE(org.cytoscape.view.presentation.property.NodeShapeVisualProperty.ELLIPSE) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) NODE_BORDER_PAINT(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_BORDER_PAINT) NODE_BORDER_WIDTH(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_BORDER_WIDTH) Continuous(org.baderlab.csplugins.enrichmentmap.CytoscapeServiceModule.Continuous) NODE_TRANSPARENCY(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_TRANSPARENCY) VisualMappingFunctionFactory(org.cytoscape.view.vizmap.VisualMappingFunctionFactory) CyEventHelper(org.cytoscape.event.CyEventHelper) DiscreteRange(org.cytoscape.view.model.DiscreteRange) NODE_LABEL_TRANSPARENCY(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_LABEL_TRANSPARENCY) EDGE_TRANSPARENCY(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_TRANSPARENCY) VisualProperty(org.cytoscape.view.model.VisualProperty) ContinuousMappingPoint(org.cytoscape.view.vizmap.mappings.ContinuousMappingPoint) BoundaryRangeValues(org.cytoscape.view.vizmap.mappings.BoundaryRangeValues) CyNetworkView(org.cytoscape.view.model.CyNetworkView) VisualMappingFunction(org.cytoscape.view.vizmap.VisualMappingFunction) EMSignatureDataSet(org.baderlab.csplugins.enrichmentmap.model.EMSignatureDataSet) CyEdge(org.cytoscape.model.CyEdge) VisualStyleChangeRecord(org.cytoscape.view.vizmap.events.VisualStyleChangeRecord) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) LineType(org.cytoscape.view.presentation.property.values.LineType) DiscreteRange(org.cytoscape.view.model.DiscreteRange)

Example 2 with DiscreteMapping

use of org.cytoscape.view.vizmap.mappings.DiscreteMapping in project EnrichmentMapApp by BaderLab.

the class EMStyleBuilder method setNodeShapes.

@SuppressWarnings({ "unchecked", "rawtypes" })
private void setNodeShapes(VisualStyle vs, EMStyleOptions options, ChartType chartType) {
    String prefix = options.getAttributePrefix();
    String columnName = Columns.NODE_GS_TYPE.with(prefix, null);
    NodeShape enrShape = getDefaultNodeShape(chartType);
    VisualMappingFunction<?, NodeShape> oldMapping = vs.getVisualMappingFunction(NODE_SHAPE);
    // This is done for performance optimization only!
    boolean update = oldMapping instanceof DiscreteMapping == false;
    if (!update) {
        // Also test the mapped column name
        update = !columnName.equals(oldMapping.getMappingColumnName());
        if (!update) {
            // Finally test the mapping values
            Object enrVal = ((DiscreteMapping) oldMapping).getMapValue(Columns.NODE_GS_TYPE_ENRICHMENT);
            Object sigVal = ((DiscreteMapping) oldMapping).getMapValue(Columns.NODE_GS_TYPE_SIGNATURE);
            update = !enrShape.equals(enrVal) || !SIGNATURE_NODE_SHAPE.equals(sigVal);
        }
    }
    if (update) {
        // Add mapping function for node shape
        DiscreteMapping<String, NodeShape> dm = (DiscreteMapping<String, NodeShape>) dmFactory.createVisualMappingFunction(columnName, String.class, NODE_SHAPE);
        // Silence events fired by this mapping to prevent unnecessary style and view updates
        eventHelper.silenceEventSource(dm);
        try {
            dm.putMapValue(Columns.NODE_GS_TYPE_ENRICHMENT, enrShape);
            dm.putMapValue(Columns.NODE_GS_TYPE_SIGNATURE, SIGNATURE_NODE_SHAPE);
        } finally {
            eventHelper.unsilenceEventSource(dm);
        }
        vs.addVisualMappingFunction(dm);
    }
}
Also used : NodeShape(org.cytoscape.view.presentation.property.values.NodeShape) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping)

Example 3 with DiscreteMapping

use of org.cytoscape.view.vizmap.mappings.DiscreteMapping in project EnrichmentMapApp by BaderLab.

the class LegendPanel method updateEdgeColorPanel.

private void updateEdgeColorPanel(EnrichmentMap map) {
    JPanel p = getEdgeColorPanel();
    CyNetworkView netView = options.getNetworkView();
    VisualStyle style = netView != null ? visualMappingManager.getVisualStyle(netView) : null;
    JComponent[][] entries = null;
    if (map != null) {
        Dimension iconSize = new Dimension(LEGEND_ICON_SIZE, LEGEND_ICON_SIZE / 2);
        if (map.getParams().getCreateDistinctEdges()) {
            VisualMappingFunction<?, Paint> mf = style.getVisualMappingFunction(BasicVisualLexicon.EDGE_STROKE_UNSELECTED_PAINT);
            if (mf instanceof DiscreteMapping) {
                DiscreteMapping<?, Paint> dm = (DiscreteMapping<?, Paint>) mf;
                final Collator collator = Collator.getInstance();
                Map<Object, Paint> dmMap = new TreeMap<>((Object o1, Object o2) -> {
                    return collator.compare("" + o1, "" + o2);
                });
                dmMap.putAll(dm.getAll());
                dmMap.remove(Columns.EDGE_DATASET_VALUE_COMPOUND);
                if (!map.hasSignatureDataSets())
                    dmMap.remove(Columns.EDGE_DATASET_VALUE_SIG);
                if (dmMap.size() > 0) {
                    entries = new JComponent[dmMap.size()][2];
                    int i = 0;
                    for (Entry<?, Paint> e : dmMap.entrySet()) {
                        Color color = null;
                        if (e.getValue() instanceof Color)
                            color = (Color) e.getValue();
                        JLabel iconLabel = createColorLabel(color, iconSize);
                        JLabel descLabel = new JLabel("" + e.getKey());
                        if (Columns.EDGE_DATASET_VALUE_SIG.equals(e.getKey()))
                            descLabel.setFont(descLabel.getFont().deriveFont(Font.ITALIC));
                        entries[i++] = new JComponent[] { iconLabel, descLabel };
                    }
                }
            }
        }
        if (entries == null) {
            int rows = map.hasSignatureDataSets() ? 2 : 1;
            entries = new JComponent[rows][2];
            {
                JLabel iconLabel = createColorLabel(Colors.COMPOUND_EDGE_COLOR, iconSize);
                JLabel descLabel = new JLabel(Columns.EDGE_DATASET_VALUE_COMPOUND);
                descLabel.setFont(descLabel.getFont().deriveFont(Font.ITALIC));
                entries[0] = new JComponent[] { iconLabel, descLabel };
            }
            if (rows == 2) {
                JLabel iconLabel = createColorLabel(Colors.SIG_EDGE_COLOR, iconSize);
                JLabel descLabel = new JLabel(Columns.EDGE_DATASET_VALUE_SIG);
                descLabel.setFont(descLabel.getFont().deriveFont(Font.ITALIC));
                entries[1] = new JComponent[] { iconLabel, descLabel };
            }
        }
    }
    updateStyleLegendPanel(entries, p);
}
Also used : JPanel(javax.swing.JPanel) Color(java.awt.Color) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) JComponent(javax.swing.JComponent) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) Paint(java.awt.Paint) TreeMap(java.util.TreeMap) Paint(java.awt.Paint) Collator(java.text.Collator) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 4 with DiscreteMapping

use of org.cytoscape.view.vizmap.mappings.DiscreteMapping in project EnrichmentMapApp by BaderLab.

the class EMStyleBuilder method setNodeColors.

private void setNodeColors(VisualStyle vs, EMStyleOptions options) {
    String prefix = options.getAttributePrefix();
    List<AbstractDataSet> dataSets = options.getDataSets().stream().filter(// Ignore Signature Data Sets in charts
    ds -> ds instanceof EMDataSet).collect(Collectors.toList());
    if (dataSets.size() == 1) {
        // Only 1 Data Set? Use node colour instead of charts...
        EMDataSet ds = (EMDataSet) dataSets.iterator().next();
        // Create boundary conditions
        BoundaryRangeValues<Paint> bv3a = new BoundaryRangeValues<>(Colors.MAX_PHENOTYPE_2, Colors.MAX_PHENOTYPE_2, Colors.MAX_PHENOTYPE_2);
        BoundaryRangeValues<Paint> bv3b = new BoundaryRangeValues<>(Colors.LIGHTER_PHENOTYPE_2, Colors.LIGHTER_PHENOTYPE_2, Colors.MAX_PHENOTYPE_2);
        BoundaryRangeValues<Paint> bv3c = new BoundaryRangeValues<>(Colors.LIGHTEST_PHENOTYPE_2, Colors.LIGHTEST_PHENOTYPE_2, Colors.LIGHTER_PHENOTYPE_2);
        BoundaryRangeValues<Paint> bv3d = new BoundaryRangeValues<>(Colors.LIGHTEST_PHENOTYPE_2, Colors.OVER_COLOR, Colors.OVER_COLOR);
        BoundaryRangeValues<Paint> bv3e = new BoundaryRangeValues<>(Colors.OVER_COLOR, Colors.OVER_COLOR, Colors.OVER_COLOR);
        BoundaryRangeValues<Paint> bv3f = new BoundaryRangeValues<>(Colors.OVER_COLOR, Colors.OVER_COLOR, Colors.LIGHTEST_PHENOTYPE_1);
        BoundaryRangeValues<Paint> bv3g = new BoundaryRangeValues<>(Colors.LIGHTEST_PHENOTYPE_1, Colors.LIGHTEST_PHENOTYPE_1, Colors.LIGHTER_PHENOTYPE_1);
        BoundaryRangeValues<Paint> bv3h = new BoundaryRangeValues<>(Colors.LIGHTER_PHENOTYPE_1, Colors.LIGHTER_PHENOTYPE_1, Colors.MAX_PHENOTYPE_1);
        BoundaryRangeValues<Paint> bv3i = new BoundaryRangeValues<>(Colors.MAX_PHENOTYPE_1, Colors.MAX_PHENOTYPE_1, Colors.MAX_PHENOTYPE_1);
        // Continuous Mapping - set node colour based on the sign of the ES score of the dataset
        ContinuousMapping<Double, Paint> cm = (ContinuousMapping<Double, Paint>) cmFactory.createVisualMappingFunction(Columns.NODE_COLOURING.with(prefix, ds.getName()), Double.class, BasicVisualLexicon.NODE_FILL_COLOR);
        // Silence events fired by this mapping to prevent unnecessary style and view updates
        eventHelper.silenceEventSource(cm);
        try {
            // Set the attribute point values associated with the boundary values
            cm.addPoint(-1.0, bv3a);
            cm.addPoint(-0.995, bv3b);
            cm.addPoint(-0.95, bv3c);
            cm.addPoint(-0.9, bv3d);
            cm.addPoint(0.0, bv3e);
            cm.addPoint(0.9, bv3f);
            cm.addPoint(0.95, bv3g);
            cm.addPoint(0.995, bv3h);
            cm.addPoint(1.0, bv3i);
        } finally {
            eventHelper.unsilenceEventSource(cm);
        }
        vs.addVisualMappingFunction(cm);
        // Then we need to use bypass to colour the hub nodes (signature genesets)
        List<EMSignatureDataSet> signatureDataSets = options.getEnrichmentMap().getSignatureSetList();
        CyNetworkView netView = options.getNetworkView();
        CyNetwork net = netView.getModel();
        for (EMSignatureDataSet sds : signatureDataSets) {
            for (Long suid : sds.getNodeSuids()) {
                CyNode node = net.getNode(suid);
                if (node != null) {
                    View<CyNode> nv = netView.getNodeView(node);
                    if (nv != null)
                        nv.setLockedValue(NODE_FILL_COLOR, Colors.SIG_NODE_COLOR);
                }
            }
        }
    } else {
        // 2 or more Data Sets? Use simple node colours and charts...
        // Add mapping function for node fill color
        DiscreteMapping<String, Paint> dm = (DiscreteMapping<String, Paint>) dmFactory.createVisualMappingFunction(Columns.NODE_GS_TYPE.with(prefix, null), String.class, NODE_FILL_COLOR);
        // Silence events fired by this mapping to prevent unnecessary style and view updates
        eventHelper.silenceEventSource(dm);
        try {
            dm.putMapValue(Columns.NODE_GS_TYPE_ENRICHMENT, Colors.DEF_NODE_COLOR);
            dm.putMapValue(Columns.NODE_GS_TYPE_SIGNATURE, Colors.SIG_NODE_COLOR);
        } finally {
            eventHelper.unsilenceEventSource(dm);
        }
        vs.addVisualMappingFunction(dm);
    }
}
Also used : Color(java.awt.Color) NODE_SHAPE(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_SHAPE) RECTANGLE(org.cytoscape.view.presentation.property.NodeShapeVisualProperty.RECTANGLE) NODE_BORDER_TRANSPARENCY(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_BORDER_TRANSPARENCY) NodeShape(org.cytoscape.view.presentation.property.values.NodeShape) Inject(com.google.inject.Inject) EDGE_UNSELECTED_PAINT(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_UNSELECTED_PAINT) LineType(org.cytoscape.view.presentation.property.values.LineType) ColorBrewer(org.jcolorbrewer.ColorBrewer) View(org.cytoscape.view.model.View) CyCustomGraphics2(org.cytoscape.view.presentation.customgraphics.CyCustomGraphics2) NODE_TOOLTIP(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_TOOLTIP) Discrete(org.baderlab.csplugins.enrichmentmap.CytoscapeServiceModule.Discrete) CyNetwork(org.cytoscape.model.CyNetwork) NODE_SIZE(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_SIZE) NODE_FILL_COLOR(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_FILL_COLOR) VisualStyleChangedEvent(org.cytoscape.view.vizmap.events.VisualStyleChangedEvent) BasicVisualLexicon(org.cytoscape.view.presentation.property.BasicVisualLexicon) RenderingEngineManager(org.cytoscape.view.presentation.RenderingEngineManager) VisualLexicon(org.cytoscape.view.model.VisualLexicon) Collectors(java.util.stream.Collectors) AbstractDataSet(org.baderlab.csplugins.enrichmentmap.model.AbstractDataSet) List(java.util.List) NETWORK_BACKGROUND_PAINT(org.cytoscape.view.presentation.property.BasicVisualLexicon.NETWORK_BACKGROUND_PAINT) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) Paint(java.awt.Paint) DIAMOND(org.cytoscape.view.presentation.property.NodeShapeVisualProperty.DIAMOND) Optional(java.util.Optional) NODE_LABEL(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_LABEL) LineTypeVisualProperty(org.cytoscape.view.presentation.property.LineTypeVisualProperty) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) ContinuousMapping(org.cytoscape.view.vizmap.mappings.ContinuousMapping) Passthrough(org.baderlab.csplugins.enrichmentmap.CytoscapeServiceModule.Passthrough) EDGE_LINE_TYPE(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_LINE_TYPE) EDGE_STROKE_UNSELECTED_PAINT(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_STROKE_UNSELECTED_PAINT) CyNode(org.cytoscape.model.CyNode) PassthroughMapping(org.cytoscape.view.vizmap.mappings.PassthroughMapping) EnrichmentMap(org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap) EDGE_LABEL_TRANSPARENCY(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_LABEL_TRANSPARENCY) EDGE_WIDTH(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_WIDTH) ELLIPSE(org.cytoscape.view.presentation.property.NodeShapeVisualProperty.ELLIPSE) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) NODE_BORDER_PAINT(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_BORDER_PAINT) NODE_BORDER_WIDTH(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_BORDER_WIDTH) Continuous(org.baderlab.csplugins.enrichmentmap.CytoscapeServiceModule.Continuous) NODE_TRANSPARENCY(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_TRANSPARENCY) VisualMappingFunctionFactory(org.cytoscape.view.vizmap.VisualMappingFunctionFactory) CyEventHelper(org.cytoscape.event.CyEventHelper) DiscreteRange(org.cytoscape.view.model.DiscreteRange) NODE_LABEL_TRANSPARENCY(org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_LABEL_TRANSPARENCY) EDGE_TRANSPARENCY(org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_TRANSPARENCY) VisualProperty(org.cytoscape.view.model.VisualProperty) ContinuousMappingPoint(org.cytoscape.view.vizmap.mappings.ContinuousMappingPoint) BoundaryRangeValues(org.cytoscape.view.vizmap.mappings.BoundaryRangeValues) CyNetworkView(org.cytoscape.view.model.CyNetworkView) VisualMappingFunction(org.cytoscape.view.vizmap.VisualMappingFunction) EMSignatureDataSet(org.baderlab.csplugins.enrichmentmap.model.EMSignatureDataSet) CyEdge(org.cytoscape.model.CyEdge) VisualStyleChangeRecord(org.cytoscape.view.vizmap.events.VisualStyleChangeRecord) ContinuousMapping(org.cytoscape.view.vizmap.mappings.ContinuousMapping) EMSignatureDataSet(org.baderlab.csplugins.enrichmentmap.model.EMSignatureDataSet) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) CyNetwork(org.cytoscape.model.CyNetwork) Paint(java.awt.Paint) AbstractDataSet(org.baderlab.csplugins.enrichmentmap.model.AbstractDataSet) BoundaryRangeValues(org.cytoscape.view.vizmap.mappings.BoundaryRangeValues) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) CyNode(org.cytoscape.model.CyNode) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 5 with DiscreteMapping

use of org.cytoscape.view.vizmap.mappings.DiscreteMapping in project EnrichmentMapApp by BaderLab.

the class EMStyleBuilder method createEdgeColorMapping.

private DiscreteMapping<String, Paint> createEdgeColorMapping(EMStyleOptions options, VisualProperty<Paint> vp) {
    String prefix = options.getAttributePrefix();
    String col = Columns.EDGE_DATASET.with(prefix, null);
    DiscreteMapping<String, Paint> dm = (DiscreteMapping<String, Paint>) dmFactory.createVisualMappingFunction(col, String.class, vp);
    // Silence events fired by this mapping, or it will fire too many VisualMappingFunctionChangedEvents,
    // which can be captured by VisualStyle later and cause unnecessary view updates,
    // even though this mapping has not been set to a style yet
    // (unfortunately that's just how Cytoscape's event payloads work).
    eventHelper.silenceEventSource(dm);
    try {
        dm.putMapValue(Columns.EDGE_DATASET_VALUE_COMPOUND, Colors.COMPOUND_EDGE_COLOR);
        //			dm.putMapValue(Columns.EDGE_DATASET_VALUE_SIG, Colors.SIG_EDGE_COLOR);
        List<EMDataSet> dataSets = options.getEnrichmentMap().getDataSetList();
        final ColorBrewer colorBrewer;
        // Try colorblind and/or print friendly colours first
        if (// Try a colorblind safe color scheme first
        dataSets.size() <= 4)
            // http://colorbrewer2.org/#type=qualitative&scheme=Paired&n=4
            colorBrewer = ColorBrewer.Paired;
        else if (// Same--more than 5, it adds a RED that can be confused with the edge selection color
        dataSets.size() <= 5)
            // http://colorbrewer2.org/#type=qualitative&scheme=Paired&n=5
            colorBrewer = ColorBrewer.Paired;
        else
            // http://colorbrewer2.org/#type=qualitative&scheme=Set3&n=12
            colorBrewer = ColorBrewer.Set3;
        Color[] colors = colorBrewer.getColorPalette(dataSets.size());
        // Do not use the filtered data sets here, because we don't want edge colours changing when filtering
        for (int i = 0; i < dataSets.size(); i++) {
            EMDataSet ds = dataSets.get(i);
            Color color = colors[i];
            dm.putMapValue(ds.getName(), color);
            ds.setColor(color);
        }
    } finally {
        eventHelper.unsilenceEventSource(dm);
    }
    return dm;
}
Also used : ColorBrewer(org.jcolorbrewer.ColorBrewer) Color(java.awt.Color) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) Paint(java.awt.Paint) Paint(java.awt.Paint) ContinuousMappingPoint(org.cytoscape.view.vizmap.mappings.ContinuousMappingPoint)

Aggregations

DiscreteMapping (org.cytoscape.view.vizmap.mappings.DiscreteMapping)5 Color (java.awt.Color)4 Paint (java.awt.Paint)4 EMDataSet (org.baderlab.csplugins.enrichmentmap.model.EMDataSet)3 CyNetworkView (org.cytoscape.view.model.CyNetworkView)3 Inject (com.google.inject.Inject)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Continuous (org.baderlab.csplugins.enrichmentmap.CytoscapeServiceModule.Continuous)2 Discrete (org.baderlab.csplugins.enrichmentmap.CytoscapeServiceModule.Discrete)2 Passthrough (org.baderlab.csplugins.enrichmentmap.CytoscapeServiceModule.Passthrough)2 AbstractDataSet (org.baderlab.csplugins.enrichmentmap.model.AbstractDataSet)2 EMSignatureDataSet (org.baderlab.csplugins.enrichmentmap.model.EMSignatureDataSet)2 EnrichmentMap (org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap)2 CyEventHelper (org.cytoscape.event.CyEventHelper)2 CyEdge (org.cytoscape.model.CyEdge)2 CyNetwork (org.cytoscape.model.CyNetwork)2 CyNode (org.cytoscape.model.CyNode)2 DiscreteRange (org.cytoscape.view.model.DiscreteRange)2