Skip to content

Commit 234337e

Browse files
committed
Add option to set compound edge color.
Refs #502
1 parent 3ed0cc5 commit 234337e

File tree

7 files changed

+112
-31
lines changed

7 files changed

+112
-31
lines changed

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/commands/DatasetColorCommandTask.java

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class DatasetColorCommandTask extends AbstractTask {
3131
@ContainsTunables @Inject
3232
public DatasetColorTunable datasetColorTunable;
3333

34+
3435
@Override
3536
public void run(TaskMonitor tm) throws Exception {
3637
tm.setTitle("Change Data Set Colors");
@@ -42,9 +43,28 @@ public void run(TaskMonitor tm) throws Exception {
4243
throw new IllegalArgumentException("network is not an EnrichmentMap network");
4344

4445
Map<String,Color> colors = datasetColorTunable.getColors();
45-
if(colors.isEmpty())
46+
Color ceColor = datasetColorTunable.getCompoundEdgeColor();
47+
if(colors.isEmpty() && ceColor == null)
4648
throw new IllegalArgumentException("no colors specified");
4749

50+
// Set colors
51+
setDatasetColors(tm, map, colors);
52+
setCompoundEdgeColor(map, ceColor);
53+
54+
// update panels
55+
controlPanelMediator.updateDataSetList(networkTunable.getNetworkView());
56+
heatMapMediatorProvider.get().reset();
57+
58+
// update visual style
59+
EMStyleOptions styleOptions = controlPanelMediator.createStyleOptions(netView);
60+
controlPanelMediator.applyVisualStyle(styleOptions, StyleUpdateScope.ONLY_DATASETS);
61+
heatMapMediatorProvider.get().reset();
62+
63+
tm.setProgress(1.0);
64+
}
65+
66+
67+
private static void setDatasetColors(TaskMonitor tm, EnrichmentMap map, Map<String,Color> colors) {
4868
List<EMDataSet> datasetList = map.getDataSetList();
4969

5070
for(var entry : colors.entrySet()) {
@@ -66,16 +86,12 @@ public void run(TaskMonitor tm) throws Exception {
6686
}
6787
}
6888
};
69-
70-
// update panels
71-
controlPanelMediator.updateDataSetList(networkTunable.getNetworkView());
72-
heatMapMediatorProvider.get().reset();
73-
74-
// update visual style
75-
EMStyleOptions styleOptions = controlPanelMediator.createStyleOptions(netView);
76-
controlPanelMediator.applyVisualStyle(styleOptions, StyleUpdateScope.ONLY_DATASETS);
77-
heatMapMediatorProvider.get().reset();
78-
79-
tm.setProgress(1.0);
89+
}
90+
91+
92+
private static void setCompoundEdgeColor(EnrichmentMap map, Color color) {
93+
if(color != null && map.useCompoundEdgeColor()) {
94+
map.setCompoundEdgeColor(color);
95+
}
8096
}
8197
}

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/commands/tunables/DatasetColorTunable.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ public class DatasetColorTunable {
1717
+ "name or index of a data set, and the value is an HTML hex color code. "
1818
+ "Example: \"DataSet1=#224433,DataSet2=#887766\"")
1919
public String colors = null;
20+
21+
@Tunable(description="Color to use for compound edges, the value is an HTML hex color code. "
22+
+ "Note: This parameter has no effect if the EnrichmentMap network uses distinct edges (i.e. separate edges for each data set). "
23+
+ "Example: \"#224433\"")
24+
public String compoundEdgeColor = null;
2025

2126

2227
public Map<String,Color> getColors() {
@@ -41,5 +46,9 @@ public Map<String,Color> getColors() {
4146
)
4247
);
4348
}
49+
50+
public Color getCompoundEdgeColor() {
51+
return compoundEdgeColor == null ? null : Color.decode(compoundEdgeColor);
52+
}
4453

4554
}

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/model/EnrichmentMap.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static com.google.common.base.Strings.isNullOrEmpty;
44

5+
import java.awt.Color;
56
import java.util.ArrayList;
67
import java.util.Collection;
78
import java.util.Collections;
@@ -62,6 +63,8 @@ public class EnrichmentMap {
6263
private boolean isLegacy = false;
6364
private boolean isDistinctExpressionSets = false;
6465
private boolean isCommonExpressionValues = false;
66+
67+
private Color compoundEdgeColor;
6568

6669
private final Object lock = new Object();
6770

@@ -644,6 +647,18 @@ public void removeSignatureDataSet(EMSignatureDataSet sigDataSet) {
644647
}
645648
}
646649

650+
public void setCompoundEdgeColor(Color compoundEdgeColor) {
651+
this.compoundEdgeColor = compoundEdgeColor;
652+
}
653+
654+
public Color getCompoundEdgeColor() {
655+
return compoundEdgeColor;
656+
}
657+
658+
public boolean useCompoundEdgeColor() {
659+
return !(getDataSetCount() > 1 && getParams().getCreateDistinctEdges());
660+
}
661+
647662
public void setDistinctExpressionSets(boolean d) {
648663
this.isDistinctExpressionSets = d;
649664
}

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/style/EMStyleBuilder.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import static org.baderlab.csplugins.enrichmentmap.style.EMStyleBuilder.StyleUpdateScope.*;
44
import static org.cytoscape.view.presentation.property.BasicVisualLexicon.*;
5-
import static org.cytoscape.view.presentation.property.NodeShapeVisualProperty.*;
5+
import static org.cytoscape.view.presentation.property.NodeShapeVisualProperty.DIAMOND;
6+
import static org.cytoscape.view.presentation.property.NodeShapeVisualProperty.ELLIPSE;
7+
import static org.cytoscape.view.presentation.property.NodeShapeVisualProperty.RECTANGLE;
68

79
import java.awt.Color;
810
import java.awt.Paint;
@@ -272,9 +274,9 @@ private void setEdgeDefaults(VisualStyle vs, EMStyleOptions options) {
272274
}
273275

274276
private void setEdgePaint(VisualStyle vs, EMStyleOptions options) {
275-
DiscreteMapping<String, Paint> edgePaint = createEdgeColorMapping(options, EDGE_UNSELECTED_PAINT);
277+
DiscreteMapping<String,Paint> edgePaint = createEdgeColorMapping(options, EDGE_UNSELECTED_PAINT);
276278
vs.addVisualMappingFunction(edgePaint);
277-
DiscreteMapping<String, Paint> edgeStrokePaint = createEdgeColorMapping(options, EDGE_STROKE_UNSELECTED_PAINT);
279+
DiscreteMapping<String,Paint> edgeStrokePaint = createEdgeColorMapping(options, EDGE_STROKE_UNSELECTED_PAINT);
278280
vs.addVisualMappingFunction(edgeStrokePaint);
279281
}
280282

@@ -293,11 +295,10 @@ else if (datasetCount <= 5) // Same--more than 5, it adds a RED that can be conf
293295
}
294296

295297
private DiscreteMapping<String, Paint> createEdgeColorMapping(EMStyleOptions options, VisualProperty<Paint> vp) {
296-
int dataSetCount = options.getEnrichmentMap().getDataSetCount();
297-
boolean distinctEdges = options.getEnrichmentMap().getParams().getCreateDistinctEdges();
298+
var em = options.getEnrichmentMap();
298299

299-
String col = (dataSetCount > 1 && distinctEdges) ?
300-
Columns.EDGE_DATASET.with(options.getAttributePrefix(), null) : CyEdge.INTERACTION;
300+
String col = em.useCompoundEdgeColor()
301+
? CyEdge.INTERACTION : Columns.EDGE_DATASET.with(options.getAttributePrefix(), null);
301302

302303
DiscreteMapping<String, Paint> mapping = (DiscreteMapping<String, Paint>) dmFactory
303304
.createVisualMappingFunction(col, String.class, vp);
@@ -309,8 +310,7 @@ private DiscreteMapping<String, Paint> createEdgeColorMapping(EMStyleOptions opt
309310
eventHelper.silenceEventSource(mapping);
310311

311312
try {
312-
List<EMDataSet> dataSets = options.getEnrichmentMap().getDataSetList();
313-
313+
var dataSets = em.getDataSetList();
314314
boolean hasColor = dataSets.stream().allMatch(ds -> ds.getColor() != null);
315315

316316
Color overlapColor;
@@ -325,11 +325,16 @@ private DiscreteMapping<String, Paint> createEdgeColorMapping(EMStyleOptions opt
325325
ds.setColor(color);
326326
}
327327
overlapColor = colors[0];
328+
em.setCompoundEdgeColor(overlapColor);
328329
} else {
329330
for (EMDataSet ds : dataSets) {
330331
mapping.putMapValue(ds.getName(), ds.getColor());
331332
}
332-
overlapColor = dataSets.get(0).getColor();
333+
overlapColor = em.getCompoundEdgeColor();
334+
if(overlapColor == null) {
335+
overlapColor = dataSets.get(0).getColor();
336+
em.setCompoundEdgeColor(overlapColor);
337+
}
333338
}
334339

335340
mapping.putMapValue(Columns.EDGE_INTERACTION_VALUE_OVERLAP, overlapColor);

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/control/ControlPanelMediator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ private void showEdgeWidthDialog() {
917917
}
918918

919919
private boolean showColorDialog(EnrichmentMap map) {
920-
DataSetColorSelectorDialog dialog = colorSelectorDialogFactory.create(map.getDataSetList());
920+
var dialog = colorSelectorDialogFactory.create(map.getDataSetList());
921921
dialog.pack();
922922
dialog.setLocationRelativeTo(swingApplication.getJFrame());
923923
dialog.setModal(true);

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/control/DataSetColorSelectorDialog.java

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.apache.commons.math3.util.Pair;
2020
import org.baderlab.csplugins.enrichmentmap.AfterInjection;
2121
import org.baderlab.csplugins.enrichmentmap.model.EMDataSet;
22+
import org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap;
2223
import org.baderlab.csplugins.enrichmentmap.view.util.GBCFactory;
2324
import org.baderlab.csplugins.enrichmentmap.view.util.SwingUtil;
2425
import org.cytoscape.util.color.BrewerType;
@@ -37,8 +38,11 @@ public class DataSetColorSelectorDialog extends JDialog {
3738
@Inject private CyColorPaletteChooserFactory paletteChooserFactory;
3839

3940
private final List<EMDataSet> dataSets;
41+
private final EnrichmentMap map;
4042

4143
private final Map<EMDataSet,Color> newColors = new IdentityHashMap<>();
44+
private Color newCompoundColor = null;
45+
4246
private final List<Pair<EMDataSet,ColorButton>> buttons = new ArrayList<>();
4347

4448
private boolean colorsChanged = false;
@@ -50,11 +54,15 @@ public interface Factory {
5054
@Inject
5155
public DataSetColorSelectorDialog(@Assisted List<EMDataSet> dataSets) {
5256
setTitle("EnrichmentMap: Data Set Colors");
57+
if(dataSets == null || dataSets.isEmpty())
58+
throw new IllegalArgumentException("There must be at least one dataset to show dialog");
5359
this.dataSets = dataSets;
60+
this.map = dataSets.get(0).getMap();
5461
}
5562

5663
@AfterInjection
5764
private void createContents() {
65+
JPanel compoundEdgePanel = createCompoundEdgeColorPanel();
5866
JPanel dataSetPanel = createDataSetColorsPanel();
5967
JPanel buttonPanel = createButtonPanel();
6068

@@ -64,13 +72,40 @@ private void createContents() {
6472
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
6573

6674
JPanel panel = new JPanel(new BorderLayout());
75+
if(compoundEdgePanel != null)
76+
panel.add(compoundEdgePanel, BorderLayout.NORTH);
6777
panel.add(scrollPane, BorderLayout.CENTER);
6878
panel.add(buttonPanel, BorderLayout.SOUTH);
6979
setContentPane(panel);
7080
}
7181

82+
private JPanel createCompoundEdgeColorPanel() {
83+
if(!map.useCompoundEdgeColor())
84+
return null;
85+
86+
JPanel panel = new JPanel(new GridBagLayout());
87+
JLabel label = new JLabel("Edges ");
88+
89+
var color = map.getCompoundEdgeColor();
90+
if(color == null)
91+
color = dataSets.get(0).getColor();
92+
93+
ColorButton colorButton = new ColorButton(color);
94+
95+
colorButton.addPropertyChangeListener("color", pce -> {
96+
Color newColor = (Color) pce.getNewValue();
97+
newCompoundColor = newColor;
98+
});
99+
100+
panel.add(label, GBCFactory.grid(0,0).get());
101+
panel.add(colorButton, GBCFactory.grid(1,0).get());
102+
103+
panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
104+
return panel;
105+
}
106+
72107
private JPanel createDataSetColorsPanel() {
73-
JPanel dataSetPanel = new JPanel(new GridBagLayout());
108+
JPanel panel = new JPanel(new GridBagLayout());
74109

75110
int y = 0;
76111
for(EMDataSet dataSet : dataSets) {
@@ -83,19 +118,19 @@ private JPanel createDataSetColorsPanel() {
83118
});
84119
buttons.add(new Pair<>(dataSet,colorButton));
85120

86-
dataSetPanel.add(label, GBCFactory.grid(0,y).get());
87-
dataSetPanel.add(colorButton, GBCFactory.grid(1,y).get());
121+
panel.add(label, GBCFactory.grid(0,y).get());
122+
panel.add(colorButton, GBCFactory.grid(1,y).get());
88123
y += 1;
89124
}
90125

91126
JButton paletteButton = new JButton("Color Palettes");
92127
SwingUtil.makeSmall(paletteButton);
93128

94-
dataSetPanel.add(paletteButton, GBCFactory.grid(3, 0).gridheight(y).anchor(GridBagConstraints.NORTH).get());
129+
panel.add(paletteButton, GBCFactory.grid(3, 0).gridheight(y).anchor(GridBagConstraints.NORTH).get());
95130
paletteButton.addActionListener(e -> showPaletteDialog());
96131

97-
dataSetPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
98-
return dataSetPanel;
132+
panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
133+
return panel;
99134
}
100135

101136
private JPanel createButtonPanel() {
@@ -128,11 +163,12 @@ private void showPaletteDialog() {
128163
}
129164

130165
private void applyColors() {
131-
if(newColors.isEmpty())
166+
if(newColors.isEmpty() && newCompoundColor == null)
132167
return;
133168

134169
colorsChanged = true;
135170
newColors.forEach(EMDataSet::setColor);
171+
map.setCompoundEdgeColor(newCompoundColor);
136172
}
137173

138174
public boolean colorsChanged() {

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/control/DataSetSelector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ JMenuItem getAddMenuItem() {
363363

364364
JMenuItem getDataSetColorMenuItem() {
365365
if (colorMenuItem == null) {
366-
colorMenuItem = new JMenuItem("Change data set colors...");
366+
colorMenuItem = new JMenuItem("Change Colors...");
367367
}
368368
return colorMenuItem;
369369
}

0 commit comments

Comments
 (0)