use of org.cytoscape.view.vizmap.VisualStyle in project EnrichmentMapApp by BaderLab.
the class LegendPanel method updateNodeChartPanel.
private void updateNodeChartPanel(Collection<EMDataSet> dataSets, EnrichmentMap map) {
JPanel p = getNodeChartPanel();
chartLegendPanel.removeAll();
CyNetworkView netView = options.getNetworkView();
VisualStyle style = netView != null ? visualMappingManager.getVisualStyle(netView) : null;
NetworkViewRenderer renderer = applicationManager.getCurrentNetworkViewRenderer();
if (renderer == null)
renderer = applicationManager.getDefaultNetworkViewRenderer();
VisualLexicon lexicon = renderer.getRenderingEngineFactory(NetworkViewRenderer.DEFAULT_CONTEXT).getVisualLexicon();
VisualProperty<?> vp = lexicon.lookup(CyNode.class, "NODE_CUSTOMGRAPHICS_1");
Object cg = vp != null ? style.getDefaultValue(vp) : null;
ChartType chartType = options.getChartOptions() != null ? options.getChartOptions().getType() : null;
if (chartType != null && cg instanceof CyCustomGraphics2 && dataSets != null && dataSets.size() > 1) {
ChartPanel chart = createChartPanel(dataSets);
if (chart != null) {
JLabel titleLabel = new JLabel("" + options.getChartOptions().getData());
titleLabel.setHorizontalAlignment(JLabel.CENTER);
makeSmall(titleLabel);
chartLegendPanel.add(chart, BorderLayout.CENTER);
chartLegendPanel.add(titleLabel, BorderLayout.SOUTH);
}
p.setVisible(true);
} else {
p.setVisible(false);
}
p.revalidate();
}
use of org.cytoscape.view.vizmap.VisualStyle 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.VisualStyle in project EnrichmentMapApp by BaderLab.
the class LegendPanel method updateNodeShapePanel.
private void updateNodeShapePanel(EnrichmentMap map) {
JPanel p = getNodeShapePanel();
p.removeAll();
CyNetworkView netView = options.getNetworkView();
VisualStyle style = netView != null ? visualMappingManager.getVisualStyle(netView) : null;
nodeShapeIcon1.setVisible(style != null);
nodeShapeDesc1.setVisible(style != null);
nodeShapeIcon2.setVisible(style != null && map.hasSignatureDataSets());
nodeShapeDesc2.setVisible(style != null && map.hasSignatureDataSets());
if (style != null) {
NodeShape shape = EMStyleBuilder.getGeneSetNodeShape(style);
nodeShapeIcon1.setIcon(getIcon(BasicVisualLexicon.NODE_SHAPE, shape, netView));
if (map.hasSignatureDataSets()) {
shape = EMStyleBuilder.getSignatureNodeShape(style);
nodeShapeIcon2.setIcon(getIcon(BasicVisualLexicon.NODE_SHAPE, shape, netView));
}
}
p.revalidate();
}
use of org.cytoscape.view.vizmap.VisualStyle 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.VisualStyle in project EnrichmentMapApp by BaderLab.
the class ApplyEMStyleTask method applyVisualStyle.
private void applyVisualStyle() {
CyNetworkView view = options.getNetworkView();
VisualStyle vs = getVisualStyle(options.getEnrichmentMap());
if (updateChartOnly)
styleBuilderProvider.get().updateNodeChart(vs, options, chart);
else
styleBuilderProvider.get().updateProperties(vs, options, chart);
if (!vs.equals(visualMappingManager.getVisualStyle(view)))
visualMappingManager.setVisualStyle(vs, view);
}
Aggregations