Skip to content

Commit 1cd87e1

Browse files
committed
Support -log10(pval)*sign(NES) in legend
1 parent 00443a0 commit 1cd87e1

File tree

11 files changed

+228
-136
lines changed

11 files changed

+228
-136
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,10 @@ public boolean hasNonGSEADataSet() {
694694
return dataSets.values().stream().anyMatch(ds -> ds.getMethod() != Method.GSEA);
695695
}
696696

697+
public boolean isSingleGSEA() {
698+
return getDataSetCount() == 1 && getDataSetList().get(0).getMethod() == Method.GSEA;
699+
}
700+
697701
@Override
698702
public String toString() {
699703
return getName();

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ public String with(String prefix) {
2222
}
2323

2424
public String with(String prefix, AbstractDataSet ds) {
25+
if(prefix == null && ds == null)
26+
return getBaseName();
27+
2528
StringBuilder sb = new StringBuilder();
2629
if(prefix != null)
2730
sb.append(prefix);

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ public boolean isChartTypeSelectable() {
3636
return this != NONE && this != DATA_SET && this != EXPRESSION_DATA;
3737
}
3838

39+
/**
40+
* Returns true if the data range goes negative-zero-positive
41+
*/
42+
public boolean isDiverging() {
43+
return this == NES_VALUE || this == NES_SIG || this == LOG10_PVAL_NES;
44+
}
45+
3946
@Override
4047
public String toString() {
4148
return label;

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ public List<Color> getColors() {
6868
return Arrays.asList(colors);
6969
}
7070

71+
public Color getPosColor() {
72+
return colors[0];
73+
}
74+
75+
public Color getNegColor() {
76+
return colors[colors.length-1];
77+
}
78+
79+
public Color getZeroColor() {
80+
return colors[colors.length/2];
81+
}
82+
7183
/**
7284
* Can be used to create more complex gradients, with fixed range points,
7385
* such as the ones created by Continuous Mappings.

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

Lines changed: 51 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.baderlab.csplugins.enrichmentmap.CytoscapeServiceModule.Discrete;
1515
import org.baderlab.csplugins.enrichmentmap.CytoscapeServiceModule.Passthrough;
1616
import org.baderlab.csplugins.enrichmentmap.model.EMDataSet;
17-
import org.baderlab.csplugins.enrichmentmap.model.EMDataSet.Method;
1817
import org.baderlab.csplugins.enrichmentmap.model.EMSignatureDataSet;
1918
import org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap;
2019
import org.baderlab.csplugins.enrichmentmap.view.util.ChartUtil;
@@ -71,6 +70,8 @@ public class EMStyleBuilder {
7170

7271
private static final NodeShape SIGNATURE_NODE_SHAPE = DIAMOND;
7372

73+
public static final ColorScheme DEF_NODE_COLOR_SCHEME = ColorScheme.RD_BU_3;
74+
7475
public static class Columns {
7576
public static final String NAMESPACE = "EnrichmentMap";
7677
public static final String NAMESPACE_PREFIX = NAMESPACE + "::"; // added in Cytoscape 3.7
@@ -152,14 +153,15 @@ public static class Colors {
152153
public static final Color SIG_EDGE_COLOR = new Color(252, 141, 98);
153154
public static final Color COMPOUND_EDGE_COLOR = new Color(102, 194, 165);
154155

155-
/* See http://colorbrewer2.org/#type=diverging&scheme=RdBu&n=9 */
156-
public static final Color MAX_PHENOTYPE_1 = new Color(178, 24, 43);
157-
public static final Color LIGHTER_PHENOTYPE_1 = new Color(214, 96, 77);
158-
public static final Color LIGHTEST_PHENOTYPE_1 = new Color(244, 165, 130);
159-
public static final Color OVER_COLOR = new Color(247, 247, 247);
160-
public static final Color MAX_PHENOTYPE_2 = new Color(33, 102, 172);
161-
public static final Color LIGHTER_PHENOTYPE_2 = new Color(67, 147, 195);
162-
public static final Color LIGHTEST_PHENOTYPE_2 = new Color(146, 197, 222);
156+
// /* See http://colorbrewer2.org/#type=diverging&scheme=RdBu&n=9 */
157+
// These are deprecated, use ColorScheme.RD_BU_9 instead
158+
@Deprecated public static final Color MAX_PHENOTYPE_1 = new Color(178, 24, 43);
159+
@Deprecated public static final Color LIGHTER_PHENOTYPE_1 = new Color(214, 96, 77);
160+
@Deprecated public static final Color LIGHTEST_PHENOTYPE_1 = new Color(244, 165, 130);
161+
@Deprecated public static final Color OVER_COLOR = new Color(247, 247, 247);
162+
@Deprecated public static final Color MAX_PHENOTYPE_2 = new Color(33, 102, 172);
163+
@Deprecated public static final Color LIGHTER_PHENOTYPE_2 = new Color(67, 147, 195);
164+
@Deprecated public static final Color LIGHTEST_PHENOTYPE_2 = new Color(146, 197, 222);
163165

164166
public static final Color LIGHT_GREY = new Color(190, 190, 190);
165167
private static final Color BG_COLOR = Color.WHITE;
@@ -490,47 +492,57 @@ private void setNodeBorderColors(VisualStyle vs, EMStyleOptions options) {
490492
vs.addVisualMappingFunction(dm);
491493
}
492494

495+
public static ColumnDescriptor<Double> getDefaultMappingColumn(EMStyleOptions options) {
496+
var isSingleGSEA = options.getEnrichmentMap().isSingleGSEA();
497+
if(isSingleGSEA)
498+
return Columns.NODE_LOG_PVALUE_NES;
499+
else
500+
return Columns.NODE_LOG_PVALUE_MAX;
501+
}
493502

494-
private ContinuousMapping<Double,Paint> createLog10NodeColorMapping(EMStyleOptions options) {
503+
public static String getDefaultMappingColumnName(EMStyleOptions options) {
495504
var map = options.getEnrichmentMap();
496505
var prefix = options.getAttributePrefix();
506+
boolean isSingleGSEA = map.isSingleGSEA();
497507

498-
boolean isSingleGSEA = map.getDataSetCount() == 1 && map.getDataSetList().get(0).getMethod() == Method.GSEA;
499-
500-
String logPValCol;
501508
if(isSingleGSEA)
502-
logPValCol = Columns.NODE_LOG_PVALUE_NES.with(prefix, map.getDataSetList().get(0));
509+
return Columns.NODE_LOG_PVALUE_NES.with(prefix, map.getDataSetList().get(0));
503510
else
504-
logPValCol = Columns.NODE_LOG_PVALUE_MAX.with(prefix);
505-
511+
return Columns.NODE_LOG_PVALUE_MAX.with(prefix);
512+
}
513+
514+
515+
private ContinuousMapping<Double,Paint> createLog10NodeColorMapping(EMStyleOptions options) {
516+
var logPValCol = getDefaultMappingColumnName(options);
506517

507518
var mapping = (ContinuousMapping<Double,Paint>) cmFactory.createVisualMappingFunction(
508519
logPValCol, Double.class, BasicVisualLexicon.NODE_FILL_COLOR);
509520

510-
if(mapping != null) { // can happen in tests
511-
var network = options.getNetworkView().getModel();
512-
var colList = List.of(columnIdFactory.createColumnIdentifier(logPValCol));
513-
var range = ChartUtil.calculateGlobalRange(network, colList, true);
514-
515-
var colors = ColorScheme.RD_BU_3.getColors();
516-
var negColor = colors.get(2);
517-
var zeroColor = colors.get(1);
518-
var posColor = colors.get(0);
519-
520-
var negPoint = new BoundaryRangeValues<Paint>(negColor, negColor, negColor);
521-
var zeroPoint = new BoundaryRangeValues<Paint>(zeroColor, zeroColor, zeroColor);
522-
var posPoint = new BoundaryRangeValues<Paint>(posColor, posColor, posColor);
523-
524-
eventHelper.silenceEventSource(mapping);
525-
try {
526-
if(isSingleGSEA) {
527-
mapping.addPoint(-range.max, negPoint);
528-
}
529-
mapping.addPoint(0.0, zeroPoint);
530-
mapping.addPoint(range.max, posPoint);
531-
} finally {
532-
eventHelper.unsilenceEventSource(mapping);
521+
if(mapping == null) // can happen in tests
522+
return null;
523+
524+
var network = options.getNetworkView().getModel();
525+
var colList = List.of(columnIdFactory.createColumnIdentifier(logPValCol));
526+
var range = ChartUtil.calculateGlobalRange(network, colList, true);
527+
528+
var colors = DEF_NODE_COLOR_SCHEME.getColors();
529+
var negColor = colors.get(2);
530+
var zeroColor = colors.get(1);
531+
var posColor = colors.get(0);
532+
533+
var negPoint = new BoundaryRangeValues<Paint>(negColor, negColor, negColor);
534+
var zeroPoint = new BoundaryRangeValues<Paint>(zeroColor, zeroColor, zeroColor);
535+
var posPoint = new BoundaryRangeValues<Paint>(posColor, posColor, posColor);
536+
537+
eventHelper.silenceEventSource(mapping);
538+
try {
539+
if(options.getEnrichmentMap().isSingleGSEA()) {
540+
mapping.addPoint(-range.max, negPoint);
533541
}
542+
mapping.addPoint(0.0, zeroPoint);
543+
mapping.addPoint(range.max, posPoint);
544+
} finally {
545+
eventHelper.unsilenceEventSource(mapping);
534546
}
535547

536548
return mapping;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public class ColorLegendPanel extends JPanel {
7272
private final boolean legacy;
7373

7474
public ColorLegendPanel(Color minColor, Color maxColor, String phenotype1, String phenotype2) {
75-
this(minColor, maxColor, phenotype1, phenotype2, true);
75+
this(minColor, maxColor, phenotype1, phenotype2, false);
7676
}
7777

7878
public ColorLegendPanel(Color minColor, Color maxColor, String phenotype1, String phenotype2, boolean legacy) {

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,14 @@ public void run(TaskMonitor taskMonitor) throws IOException, DocumentException {
7070

7171

7272
private List<Element> createNodeColorSection(PdfWriter writer) throws DocumentException {
73-
ColorLegendPanel colorPanel = content.getNodeColorLegend();
74-
if(colorPanel == null)
75-
return null;
76-
Paragraph title = new Paragraph(new Chunk(LegendContent.NODE_COLOR_HEADER));
77-
Paragraph body = new Paragraph();
78-
body.add(createNodeColor(writer, colorPanel));
79-
return Arrays.asList(title, body);
73+
// ColorLegendPanel colorPanel = content.getNodeColorLegend();
74+
// if(colorPanel == null)
75+
// return null;
76+
// Paragraph title = new Paragraph(new Chunk(LegendContent.NODE_COLOR_HEADER));
77+
// Paragraph body = new Paragraph();
78+
// body.add(createNodeColor(writer, colorPanel));
79+
// return Arrays.asList(title, body);
80+
return null;
8081
}
8182

8283
private static Image createNodeColor(PdfWriter writer, ColorLegendPanel colorPanel) throws DocumentException {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ public interface LegendContent {
2828

2929
public Icon getSignatureNodeShape();
3030

31-
public ColorLegendPanel getNodeColorLegend();
31+
public ColorLegendPanel getNodePosLegend();
32+
33+
public ColorLegendPanel getNodeNegLegend();
3234

3335
public ColorLegendPanel getChartPosLegend();
3436

0 commit comments

Comments
 (0)