Skip to content

Commit 512dc4c

Browse files
committed
Add -log10(pval)*sign(NES) chart
1 parent 7e87f18 commit 512dc4c

File tree

11 files changed

+56
-31
lines changed

11 files changed

+56
-31
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ private static Comparator<CyNode> compareSignificance(Map<CyNode,Double> nodeSig
127127
case NONE: // -log10
128128
case LOG10_PVAL:
129129
return (n1, n2) -> -Double.compare(nodeSig.get(n1), nodeSig.get(n2));
130+
case LOG10_PVAL_NES:
130131
case NES_VALUE:
131132
case NES_SIG:
132133
return (n1, n2) -> {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ public enum ChartData {
1313
PHENOTYPES("Phenotypes", Columns.NODE_COLOURING),
1414
DATA_SET("Color by Data Set", Columns.DATASET_CHART),
1515
EXPRESSION_DATA("Color by Expression Data", Columns.EXPRESSION_DATA_CHART),
16-
LOG10_PVAL("-log10(pvalue)", Columns.NODE_LOG_PVALUE);
16+
LOG10_PVAL("-log10(pvalue)", Columns.NODE_LOG_PVALUE),
17+
LOG10_PVAL_NES("-log10(pvalue)*sign(NES)", Columns.NODE_LOG_PVALUE_NES);
1718

1819
private final String label;
1920
private final AbstractColumnDescriptor columnDescriptor;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ public static class Columns {
8787
public static final String NODE_GS_TYPE_SIGNATURE = "SIG";
8888
public static final ColumnListDescriptor<String> NODE_GENES = new ColumnListDescriptor<>("Genes", String.class);
8989
public static final ColumnDescriptor<Integer> NODE_GS_SIZE = new ColumnDescriptor<>("gs_size", Integer.class);
90-
public static final ColumnDescriptor<Double> NODE_LOG_PVALUE = new ColumnDescriptor<>("-log10(pvalue)", Double.class);
91-
public static final ColumnDescriptor<Double> NODE_LOG_PVALUE_MAX = new ColumnDescriptor<>("-log10(pvalue)_max", Double.class);
90+
public static final ColumnDescriptor<Double> NODE_LOG_PVALUE = new ColumnDescriptor<>("-log10(pvalue)", Double.class); // per dataset
91+
public static final ColumnDescriptor<Double> NODE_LOG_PVALUE_NES = new ColumnDescriptor<>("-log10(pvalue)*sign(NES)", Double.class); // per dataset
92+
public static final ColumnDescriptor<Double> NODE_LOG_PVALUE_MAX = new ColumnDescriptor<>("-log10(pvalue)_max", Double.class); // max of all datasets
9293

9394
// Per-DataSet attributes
9495
// GSEA attributes

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/style/charts/radialheatmap/RadialHeatMapLayer.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public RadialHeatMapLayer(
5151
this.startAngle = startAngle;
5252
this.rotation = rotation;
5353
this.labels = new HashMap<>();
54-
useColorsDirectly = false;
54+
this.useColorsDirectly = false;
5555

5656
// Range cannot be null
5757
if (this.range == null)
@@ -78,7 +78,7 @@ public RadialHeatMapLayer(
7878
this.startAngle = startAngle;
7979
this.rotation = rotation;
8080
this.labels = new HashMap<>();
81-
useColorsDirectly = true;
81+
this.useColorsDirectly = true;
8282
}
8383

8484
// ==[ PRIVATE METHODS ]============================================================================================
@@ -153,10 +153,11 @@ public JFreeChart createChart(final PieDataset dataset) {
153153
Color lowerColor = Color.RED;
154154
Color nanColor = Color.LIGHT_GRAY;
155155

156-
if (colorPoints.isEmpty() || colorPoints.size() != colors.size()) {
156+
boolean useColorPoints = colorPoints != null && !colorPoints.isEmpty() && colorPoints.size() == colors.size();
157+
158+
if (!useColorPoints) {
157159
if (range != null && range.size() >= 2 && range.get(0) != null && range.get(1) != null) {
158-
final int colorsSize = colors != null ? colors.size() : 0;
159-
160+
int colorsSize = colors != null ? colors.size() : 0;
160161
if (colorsSize > 0) upperColor = colors.get(0);
161162
if (colorsSize > 1) zeroColor = colors.get(1);
162163
if (colorsSize > 2) lowerColor = colors.get(2);
@@ -175,18 +176,19 @@ public JFreeChart createChart(final PieDataset dataset) {
175176
if (v == null || !Double.isFinite(v)) {
176177
c = nanColor;
177178
} else {
178-
if (useColorsDirectly)
179+
if (useColorsDirectly) {
179180
c = colors.size() > i ? colors.get(i) : nanColor;
180-
else if (colorPoints.isEmpty() || colorPoints.size() != colors.size())
181-
c = range.size() > 1
182-
? ColorUtil.getColor(v, range.get(0), range.get(1), lowerColor, zeroColor, upperColor)
183-
: null;
184-
else
181+
} else if (useColorPoints) {
185182
c = ColorUtil.getColor(v, colors, colorPoints);
183+
}
184+
else {
185+
c = range.size() > 1 ? ColorUtil.getColor(v, range.get(0), range.get(1), lowerColor, zeroColor, upperColor) : null;
186+
}
186187
}
187188

188-
if (c == null)
189+
if (c == null) {
189190
c = nanColor;
191+
}
190192

191193
plot.setSectionPaint(k, c);
192194
plot.setSectionOutlinePaint(k, borderWidth > 0 ? borderColor : TRANSPARENT_COLOR);
@@ -195,4 +197,5 @@ else if (colorPoints.isEmpty() || colorPoints.size() != colors.size())
195197

196198
return chart;
197199
}
200+
198201
}

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/task/ApplyEMStyleTask.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,15 @@ public Map<String, Object> createChartProps() {
254254

255255
if (data == ChartData.DATA_SET) {
256256
List<CyColumnIdentifier> columns = Arrays.asList(columnIdFactory.createColumnIdentifier(columnDescriptor.with(prefix)));
257-
List<Color> colors = getColors(dataSets);
257+
List<Color> colors = dataSetColors(dataSets);
258258
props.put("cy_dataColumns", columns);
259259
props.put("cy_colors", colors);
260260
props.put("cy_showItemLabels", chartOptions.isShowLabels());
261261
props.put("cy_rotation", "CLOCKWISE");
262262

263263
} else {
264264
List<CyColumnIdentifier> columns = ChartUtil.getSortedColumnIdentifiers(prefix, dataSets, columnDescriptor, columnIdFactory);
265+
265266
List<Color> colors = ChartUtil.getChartColors(chartOptions, true);
266267
List<Double> range = ChartUtil.calculateGlobalRange(options.getNetworkView().getModel(), columns);
267268

@@ -296,11 +297,11 @@ public Map<String, Object> createChartProps() {
296297
}
297298
}
298299

299-
return props;
300+
return props;
300301
}
301302

302303

303-
public static List<Color> getColors(Collection<EMDataSet> dataSets) {
304+
public static List<Color> dataSetColors(Collection<EMDataSet> dataSets) {
304305
return dataSets.stream().map(EMDataSet::getColor).collect(Collectors.toList());
305306
}
306307

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/task/CreateEMNetworkTask.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ private CyTable createNodeColumns(CyNetwork network) {
335335
Columns.NODE_ES.createColumn(table, prefix, dataset);
336336
Columns.NODE_NES.createColumn(table, prefix, dataset);
337337
Columns.NODE_LOG_PVALUE.createColumn(table, prefix, dataset);
338+
Columns.NODE_LOG_PVALUE_NES.createColumn(table, prefix, dataset);
338339
Columns.NODE_COLOURING.createColumn(table, prefix, dataset);
339340

340341
params.addPValueColumnName(Columns.NODE_PVALUE.with(prefix, dataset));
@@ -361,7 +362,10 @@ private void setGenericResultNodeAttributes(CyRow row, EMDataSet dataset, Generi
361362
Columns.NODE_FDR_QVALUE.set(row, prefix, dataset, result.getFdrqvalue());
362363
Columns.NODE_NES.set(row, prefix, dataset, result.getNES());
363364
Columns.NODE_COLOURING.set(row, prefix, dataset, getColorScore(result));
364-
Columns.NODE_LOG_PVALUE.set(row, prefix, dataset, getNegLog10pval(dataset, result));
365+
366+
var log10 = getNegLog10pval(dataset, result);
367+
Columns.NODE_LOG_PVALUE.set(row, prefix, dataset, log10);
368+
Columns.NODE_LOG_PVALUE_NES.set(row, prefix, dataset, log10 * sign(result.getNES()));
365369
}
366370

367371
private void setGSEAResultNodeAttributes(CyRow row, EMDataSet dataset, GSEAResult result) {
@@ -371,12 +375,21 @@ private void setGSEAResultNodeAttributes(CyRow row, EMDataSet dataset, GSEAResul
371375
Columns.NODE_ES.set(row, prefix, dataset, result.getES());
372376
Columns.NODE_NES.set(row, prefix, dataset, result.getNES());
373377
Columns.NODE_COLOURING.set(row, prefix, dataset, getColorScore(result));
374-
Columns.NODE_LOG_PVALUE.set(row, prefix, dataset, getNegLog10pval(dataset, result));
378+
379+
var log10 = getNegLog10pval(dataset, result);
380+
Columns.NODE_LOG_PVALUE.set(row, prefix, dataset, log10);
381+
Columns.NODE_LOG_PVALUE_NES.set(row, prefix, dataset, log10 * sign(result.getNES()));
375382

376383
EMCreationParameters params = map.getParams();
377384
params.addPValueColumnName(Columns.NODE_PVALUE.with(prefix, dataset));
378385
}
379386

387+
private static double sign(double x) {
388+
// Math.signum() can return 0, we don't want that
389+
return x < 0 ? -1 : 1;
390+
}
391+
392+
380393
private static double getColorScore(EnrichmentResult result) {
381394
if(result == null)
382395
return 0.0;

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/task/UpdateAssociatedStyleTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ private CyCustomGraphics2<?> createChart() {
215215

216216
if (data == ChartData.DATA_SET) {
217217
List<CyColumnIdentifier> columns = Arrays.asList(columnIdFactory.createColumnIdentifier(columnDescriptor.with(prefix)));
218-
List<Color> colors = ApplyEMStyleTask.getColors(dataSets);
218+
List<Color> colors = ApplyEMStyleTask.dataSetColors(dataSets);
219219

220220
props.put("cy_dataColumns", columns);
221221
props.put("cy_colors", colors);

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
import static javax.swing.GroupLayout.Alignment.TRAILING;
88
import static org.baderlab.csplugins.enrichmentmap.view.util.IconUtil.*;
99
import static org.baderlab.csplugins.enrichmentmap.view.util.SwingUtil.makeSmall;
10-
import static org.cytoscape.util.swing.IconManager.*;
10+
import static org.cytoscape.util.swing.IconManager.ICON_BARS;
11+
import static org.cytoscape.util.swing.IconManager.ICON_FILE;
12+
import static org.cytoscape.util.swing.IconManager.ICON_PLUS;
13+
import static org.cytoscape.util.swing.IconManager.ICON_STAR;
1114
import static org.cytoscape.util.swing.LookAndFeelUtil.isAquaLAF;
1215

1316
import java.awt.BorderLayout;
@@ -886,6 +889,7 @@ JComboBox<ChartData> getChartDataCombo() {
886889
chartDataCombo.addItem(ChartData.NES_SIG);
887890
chartDataCombo.addItem(ChartData.P_VALUE);
888891
chartDataCombo.addItem(ChartData.LOG10_PVAL);
892+
chartDataCombo.addItem(ChartData.LOG10_PVAL_NES);
889893

890894
EnrichmentMap map = getEnrichmentMap();
891895
if (map != null) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ private void updateNodeChartColorPanel(Collection<EMDataSet> dataSets) {
353353
);
354354

355355

356-
if(data == ChartData.NES_VALUE || data == ChartData.NES_SIG) { // need to show negative range
356+
if(data == ChartData.NES_VALUE || data == ChartData.NES_SIG || data == ChartData.LOG10_PVAL_NES) { // need to show negative range
357357
String negMinLabel = min < 0 ? String.format("%.2f", min) : "N/A";
358358
Color negMaxColor = colors.get(colors.size()-1);
359359
Color negMinColor = colors.get(colors.size()/2);

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/util/ChartUtil.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,11 @@ public static List<Color> getChartColors(ChartOptions options, boolean forStyle)
157157
// The 3-color schemes need to be swapped when the chart only includes positive numbers.
158158
// Swap UP and ZERO colors if q or p-value (it should not have negative values!)
159159
if ((data == ChartData.FDR_VALUE || data == ChartData.P_VALUE) && colors.size() == 3) {
160-
colors = Arrays.asList(colors.get(0), colors.get(1));
161-
} else if(data == ChartData.LOG10_PVAL && colors.size() == 3) {
162160
colors = Arrays.asList(colors.get(1), colors.get(0));
163-
}
161+
}
162+
// else if(data == ChartData.LOG10_PVAL && colors.size() == 3) {
163+
// colors = Arrays.asList(colors.get(0), colors.get(1));
164+
// }
164165
}
165166

166167
return colors;

0 commit comments

Comments
 (0)