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);
}
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);
}
}
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);
}
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);
}
}
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;
}
Aggregations