Skip to content

Commit 9abf847

Browse files
committed
Refs #201: Post analysis edges now have a more contrasting colour when there is only one dataset (it's the same colour used when creating compound edges, and not the dataset colour).
1 parent 508de9c commit 9abf847

File tree

3 files changed

+51
-25
lines changed

3 files changed

+51
-25
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@ public void setDataSets(Map<String, EMDataSet> dataSets) {
328328
this.dataSets = dataSets;
329329
}
330330

331+
/**
332+
* Returns the total number of data sets, excluding Signature Data Sets.
333+
*/
331334
public int getDataSetCount() {
332335
return dataSets.size();
333336
}

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

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ public static class Columns {
113113

114114
// Multi-edge case
115115
public static final ColumnDescriptor<String> EDGE_DATASET = new ColumnDescriptor<>("Data Set", String.class);
116-
public static final String EDGE_DATASET_VALUE_COMPOUND = "compound";
116+
public static final String EDGE_DATASET_VALUE_COMPOUND = "compound";
117117
public static final String EDGE_DATASET_VALUE_SIG = "signature"; // post-analysis edges
118+
public static final String EDGE_INTERACTION_VALUE_OVERLAP = "Geneset_Overlap";
118119
public static final String EDGE_INTERACTION_VALUE_SIG = "sig"; // post-analysis edges
119120
public static final ColumnDescriptor<String> EDGE_SIG_DATASET = new ColumnDescriptor<>("Signature Set", String.class);
120121

@@ -265,8 +266,11 @@ private void setEdgePaint(VisualStyle vs, EMStyleOptions options) {
265266
}
266267

267268
private DiscreteMapping<String, Paint> createEdgeColorMapping(EMStyleOptions options, VisualProperty<Paint> vp) {
268-
String prefix = options.getAttributePrefix();
269-
String col = Columns.EDGE_DATASET.with(prefix, null);
269+
int dataSetCount = options.getEnrichmentMap().getDataSetCount();
270+
boolean distinctEdges = options.getEnrichmentMap().getParams().getCreateDistinctEdges();
271+
272+
String col = (dataSetCount > 1 && distinctEdges) ?
273+
Columns.EDGE_DATASET.with(options.getAttributePrefix(), null) : CyEdge.INTERACTION;
270274

271275
DiscreteMapping<String, Paint> dm = (DiscreteMapping<String, Paint>) dmFactory
272276
.createVisualMappingFunction(col, String.class, vp);
@@ -278,28 +282,33 @@ private DiscreteMapping<String, Paint> createEdgeColorMapping(EMStyleOptions opt
278282
eventHelper.silenceEventSource(dm);
279283

280284
try {
281-
dm.putMapValue(Columns.EDGE_DATASET_VALUE_COMPOUND, Colors.COMPOUND_EDGE_COLOR);
282-
// dm.putMapValue(Columns.EDGE_DATASET_VALUE_SIG, Colors.SIG_EDGE_COLOR);
283-
284-
List<EMDataSet> dataSets = options.getEnrichmentMap().getDataSetList();
285-
final ColorBrewer colorBrewer;
286-
287-
// Try colorblind and/or print friendly colours first
288-
if (dataSets.size() <= 4) // Try a colorblind safe color scheme first
289-
colorBrewer = ColorBrewer.Paired; // http://colorbrewer2.org/#type=qualitative&scheme=Paired&n=4
290-
else if (dataSets.size() <= 5) // Same--more than 5, it adds a RED that can be confused with the edge selection color
291-
colorBrewer = ColorBrewer.Paired; // http://colorbrewer2.org/#type=qualitative&scheme=Paired&n=5
292-
else
293-
colorBrewer = ColorBrewer.Set3; // http://colorbrewer2.org/#type=qualitative&scheme=Set3&n=12
285+
if (dataSetCount > 1 && distinctEdges) {
286+
List<EMDataSet> dataSets = options.getEnrichmentMap().getDataSetList();
287+
final ColorBrewer colorBrewer;
294288

295-
Color[] colors = colorBrewer.getColorPalette(dataSets.size());
296-
297-
// Do not use the filtered data sets here, because we don't want edge colours changing when filtering
298-
for (int i = 0; i < dataSets.size(); i++) {
299-
EMDataSet ds = dataSets.get(i);
300-
Color color = colors[i];
301-
dm.putMapValue(ds.getName(), color);
302-
ds.setColor(color);
289+
// Try colorblind and/or print friendly colours first
290+
if (dataSets.size() <= 4) // Try a colorblind safe color scheme first
291+
colorBrewer = ColorBrewer.Paired; // http://colorbrewer2.org/#type=qualitative&scheme=Paired&n=4
292+
else if (dataSets.size() <= 5) // Same--more than 5, it adds a RED that can be confused with the edge selection color
293+
colorBrewer = ColorBrewer.Paired; // http://colorbrewer2.org/#type=qualitative&scheme=Paired&n=5
294+
else
295+
colorBrewer = ColorBrewer.Set3; // http://colorbrewer2.org/#type=qualitative&scheme=Set3&n=12
296+
297+
Color[] colors = colorBrewer.getColorPalette(dataSets.size());
298+
299+
// Do not use the filtered data sets here, because we don't want edge colours changing when filtering
300+
for (int i = 0; i < dataSets.size(); i++) {
301+
EMDataSet ds = dataSets.get(i);
302+
Color color = colors[i];
303+
dm.putMapValue(ds.getName(), color);
304+
ds.setColor(color);
305+
}
306+
} else {
307+
Color overlapColor = distinctEdges ?
308+
ColorBrewer.Paired.getColorPalette(1)[0] : Colors.COMPOUND_EDGE_COLOR;
309+
310+
dm.putMapValue(Columns.EDGE_INTERACTION_VALUE_OVERLAP, overlapColor);
311+
dm.putMapValue(Columns.EDGE_INTERACTION_VALUE_SIG, Colors.SIG_EDGE_COLOR);
303312
}
304313
} finally {
305314
eventHelper.unsilenceEventSource(dm);

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/legend/LegendPanel.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,9 @@ private void updateEdgeColorPanel(EnrichmentMap map) {
350350

351351
if (map != null) {
352352
Dimension iconSize = new Dimension(LEGEND_ICON_SIZE, LEGEND_ICON_SIZE / 2);
353+
boolean distinctEdges = map.getParams().getCreateDistinctEdges();
353354

354-
if (map.getParams().getCreateDistinctEdges()) {
355+
if (distinctEdges) {
355356
VisualMappingFunction<?, Paint> mf =
356357
style.getVisualMappingFunction(BasicVisualLexicon.EDGE_STROKE_UNSELECTED_PAINT);
357358

@@ -360,11 +361,24 @@ private void updateEdgeColorPanel(EnrichmentMap map) {
360361
final Collator collator = Collator.getInstance();
361362

362363
Map<Object, Paint> dmMap = new TreeMap<>((Object o1, Object o2) -> {
364+
if (Columns.EDGE_DATASET_VALUE_SIG.equals(o1)) return 1;
365+
if (Columns.EDGE_DATASET_VALUE_SIG.equals(o2)) return -1;
363366
return collator.compare("" + o1, "" + o2);
364367
});
365368
dmMap.putAll(dm.getAll());
366369
dmMap.remove(Columns.EDGE_DATASET_VALUE_COMPOUND);
367370

371+
// Special case of 1 dataset with distinct edges and maybe signature genesets as well
372+
if (map.getDataSetCount() == 1) {
373+
Paint p1 = dmMap.remove(Columns.EDGE_INTERACTION_VALUE_OVERLAP);
374+
Paint p2 = dmMap.remove(Columns.EDGE_INTERACTION_VALUE_SIG);
375+
376+
if (p1 != null)
377+
dmMap.put(map.getDataSetList().iterator().next().getName(), p1);
378+
if (p2 != null)
379+
dmMap.put(Columns.EDGE_DATASET_VALUE_SIG, p2);
380+
}
381+
368382
if (!map.hasSignatureDataSets())
369383
dmMap.remove(Columns.EDGE_DATASET_VALUE_SIG);
370384

0 commit comments

Comments
 (0)