Skip to content

Commit 3c83241

Browse files
committed
Add chart option to color by significant NES only.
Refs #446
1 parent 3a9e1e8 commit 3c83241

File tree

7 files changed

+134
-30
lines changed

7 files changed

+134
-30
lines changed

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
package org.baderlab.csplugins.enrichmentmap.commands.tunables;
22

33
import static org.baderlab.csplugins.enrichmentmap.commands.tunables.CommandUtil.lssFromEnum;
4-
import static org.baderlab.csplugins.enrichmentmap.style.ChartData.DATA_SET;
5-
import static org.baderlab.csplugins.enrichmentmap.style.ChartData.EXPRESSION_DATA;
6-
import static org.baderlab.csplugins.enrichmentmap.style.ChartData.FDR_VALUE;
7-
import static org.baderlab.csplugins.enrichmentmap.style.ChartData.NES_VALUE;
8-
import static org.baderlab.csplugins.enrichmentmap.style.ChartData.NONE;
9-
import static org.baderlab.csplugins.enrichmentmap.style.ChartData.PHENOTYPES;
10-
import static org.baderlab.csplugins.enrichmentmap.style.ChartData.P_VALUE;
4+
import static org.baderlab.csplugins.enrichmentmap.style.ChartData.*;
115
import static org.baderlab.csplugins.enrichmentmap.style.ChartType.DATASET_PIE;
126
import static org.baderlab.csplugins.enrichmentmap.style.ChartType.HEAT_MAP;
137
import static org.baderlab.csplugins.enrichmentmap.style.ChartType.HEAT_STRIPS;
@@ -35,7 +29,7 @@ public class ChartTunables {
3529

3630

3731
public ChartTunables() {
38-
data = lssFromEnum(NES_VALUE, P_VALUE, FDR_VALUE, PHENOTYPES, DATA_SET, EXPRESSION_DATA, NONE); // want NES to be the default
32+
data = lssFromEnum(NES_VALUE, P_VALUE, FDR_VALUE, PHENOTYPES, DATA_SET, EXPRESSION_DATA, NES_SIG, NONE); // want NES to be the default
3933
type = lssFromEnum(RADIAL_HEAT_MAP, HEAT_STRIPS, HEAT_MAP); // don't include DATASET_PIE
4034
colors = lssFromEnum(ColorScheme.values());
4135
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
public enum ChartData {
77
NONE(Labels.NONE, null),
88
NES_VALUE("NES Columns", Columns.NODE_NES),
9+
NES_SIG("NES Columns (significant)", Columns.NODE_NES),
910
P_VALUE("P-value Columns", Columns.NODE_PVALUE),
1011
FDR_VALUE("Q-value (FDR) Columns", Columns.NODE_FDR_QVALUE),
1112
PHENOTYPES("Phenotypes", Columns.NODE_COLOURING),

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

Lines changed: 107 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.ArrayList;
88
import java.util.Collections;
99
import java.util.HashMap;
10+
import java.util.LinkedHashMap;
1011
import java.util.List;
1112
import java.util.Map;
1213

@@ -15,8 +16,11 @@
1516

1617
import org.baderlab.csplugins.enrichmentmap.style.charts.AbstractChart;
1718
import org.baderlab.csplugins.enrichmentmap.style.charts.Rotation;
19+
import org.cytoscape.model.CyColumn;
1820
import org.cytoscape.model.CyIdentifiable;
1921
import org.cytoscape.model.CyNetwork;
22+
import org.cytoscape.model.CyRow;
23+
import org.cytoscape.model.CyTable;
2024
import org.cytoscape.service.util.CyServiceRegistrar;
2125
import org.cytoscape.view.model.CyNetworkView;
2226
import org.cytoscape.view.model.View;
@@ -27,6 +31,11 @@ public class RadialHeatMapChart extends AbstractChart<RadialHeatMapLayer> {
2731
public static final String FACTORY_ID = "org.baderlab.enrichmentmap.RadialHeatMapChart";
2832
public static final String DISPLAY_NAME = "Radial Heat Map Chart";
2933

34+
public static final String P_VALUE_COLS = "cy_p_value_cols";
35+
public static final String Q_VALUE_COLS = "cy_q_value_cols";
36+
public static final String P_VALUE = "cy_p_value";
37+
public static final String Q_VALUE = "cy_q_value";
38+
3039
public static final String START_ANGLE = "cy_startAngle";
3140

3241
public static ImageIcon ICON;
@@ -52,6 +61,7 @@ public RadialHeatMapChart(final String input, final CyServiceRegistrar serviceRe
5261
super(DISPLAY_NAME, input, serviceRegistrar);
5362
}
5463

64+
5565
@Override
5666
public List<RadialHeatMapLayer> getLayers(final CyNetworkView networkView, final View<? extends CyIdentifiable> view) {
5767
final CyNetwork network = networkView.getModel();
@@ -92,8 +102,84 @@ public String getId() {
92102
}
93103

94104
@Override
95-
public Map<String, List<Double>> getDataFromColumns(final CyNetwork network, final CyIdentifiable model,
96-
final List<CyColumnIdentifier> columnNames) {
105+
public Map<String, List<Double>> getDataFromColumns(CyNetwork network, CyIdentifiable model, List<CyColumnIdentifier> columnNames) {
106+
List<CyColumnIdentifier> pValueCols = get(P_VALUE_COLS, List.class);
107+
List<CyColumnIdentifier> qValueCols = get(Q_VALUE_COLS, List.class);
108+
Double pFilter = get(P_VALUE, Double.class);
109+
Double qFilter = get(Q_VALUE, Double.class);
110+
111+
if(pValueCols == null || pFilter == null) {
112+
// do it exactly like it was done before, for backwards compatibility
113+
return getDataFromColumnsNormal(network, model, columnNames);
114+
}
115+
116+
List<Double> allValues = new ArrayList<>();
117+
118+
for(int i = 0; i < columnNames.size(); i++) {
119+
CyColumnIdentifier vCol = columnNames.get(i);
120+
CyColumnIdentifier pCol = pValueCols.get(i);
121+
122+
CyRow row = network.getRow(model);
123+
124+
Double v = getDouble(row, vCol);
125+
Double p = getDouble(row, pCol);
126+
127+
if((!Double.isFinite(p) || p <= pFilter)) {
128+
if(qValueCols != null && qFilter != null) {
129+
CyColumnIdentifier qCol = qValueCols.get(i);
130+
Double q = getDouble(row, qCol);
131+
132+
if((!Double.isFinite(q) || q <= qFilter)) {
133+
allValues.add(v);
134+
} else {
135+
allValues.add(Double.NaN); // results in gray slice
136+
}
137+
} else {
138+
allValues.add(v);
139+
}
140+
} else {
141+
allValues.add(Double.NaN); // results in gray slice
142+
}
143+
}
144+
145+
Map<String,List<Double>> data = new LinkedHashMap<>();
146+
data.put("Values", allValues);
147+
return data;
148+
}
149+
150+
151+
private static Double getDouble(CyRow row, CyColumnIdentifier colId) {
152+
if(colId == null)
153+
return Double.NaN;
154+
CyTable table = row.getTable();
155+
String colName = colId.getColumnName();
156+
CyColumn col = table.getColumn(colName);
157+
if(col == null)
158+
return Double.NaN;
159+
Class<?> type = col.getType();
160+
161+
if (Number.class.isAssignableFrom(type)) {
162+
if (!row.isSet(colName)) {
163+
return Double.NaN;
164+
} else if (type == Double.class) {
165+
return row.get(colName, Double.class);
166+
} else if (type == Integer.class) {
167+
Integer i = row.get(colName, Integer.class);
168+
if(i != null) {
169+
return i.doubleValue();
170+
}
171+
} else if (type == Float.class) {
172+
Float f = row.get(colName, Float.class);
173+
if(f != null) {
174+
return f.doubleValue();
175+
}
176+
}
177+
}
178+
return Double.NaN;
179+
}
180+
181+
182+
private Map<String, List<Double>> getDataFromColumnsNormal(CyNetwork network, CyIdentifiable model, List<CyColumnIdentifier> columnNames) {
97183
final Map<String, List<Double>> data = new HashMap<>();
98184

99185
// Values from multiple series have to be merged into one single series
@@ -110,8 +196,25 @@ public Map<String, List<Double>> getDataFromColumns(final CyNetwork network, fin
110196

111197
@Override
112198
public Class<?> getSettingType(final String key) {
113-
if (key.equalsIgnoreCase(START_ANGLE)) return Double.class;
114-
199+
if (key.equalsIgnoreCase(START_ANGLE))
200+
return Double.class;
201+
if (key.equalsIgnoreCase(P_VALUE_COLS))
202+
return List.class;
203+
if (key.equalsIgnoreCase(Q_VALUE_COLS))
204+
return List.class;
205+
if (key.equalsIgnoreCase(P_VALUE))
206+
return Double.class;
207+
if (key.equalsIgnoreCase(Q_VALUE))
208+
return Double.class;
115209
return super.getSettingType(key);
116210
}
211+
212+
@Override
213+
public Class<?> getSettingElementType(final String key) {
214+
if (key.equalsIgnoreCase(P_VALUE_COLS))
215+
return CyColumnIdentifier.class;
216+
if (key.equalsIgnoreCase(Q_VALUE_COLS))
217+
return CyColumnIdentifier.class;
218+
return super.getSettingElementType(key);
219+
}
117220
}

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.baderlab.csplugins.enrichmentmap.style.EMStyleBuilder.Columns;
2424
import org.baderlab.csplugins.enrichmentmap.style.EMStyleOptions;
2525
import org.baderlab.csplugins.enrichmentmap.style.charts.AbstractChart;
26+
import org.baderlab.csplugins.enrichmentmap.style.charts.radialheatmap.RadialHeatMapChart;
2627
import org.baderlab.csplugins.enrichmentmap.view.control.ControlPanelMediator;
2728
import org.baderlab.csplugins.enrichmentmap.view.control.FilterUtil;
2829
import org.baderlab.csplugins.enrichmentmap.view.control.io.ViewParams;
@@ -235,8 +236,7 @@ public CyCustomGraphics2<?> createChart() {
235236
props.put("cy_rotation", "CLOCKWISE");
236237

237238
} else {
238-
List<CyColumnIdentifier> columns = ChartUtil.getSortedColumnIdentifiers(prefix,
239-
dataSets, columnDescriptor, columnIdFactory);
239+
List<CyColumnIdentifier> columns = ChartUtil.getSortedColumnIdentifiers(prefix, dataSets, columnDescriptor, columnIdFactory);
240240

241241
List<Color> colors = ChartUtil.getChartColors(chartOptions, true);
242242
List<Double> range = ChartUtil.calculateGlobalRange(options.getNetworkView().getModel(), columns);
@@ -248,6 +248,21 @@ public CyCustomGraphics2<?> createChart() {
248248
props.put("cy_showItemLabels", chartOptions.isShowLabels());
249249
props.put("cy_colors", colors);
250250

251+
if(data == ChartData.NES_SIG) {
252+
EnrichmentMap map = options.getEnrichmentMap();
253+
EMCreationParameters params = map.getParams();
254+
255+
props.put(RadialHeatMapChart.P_VALUE, params.getPvalue());
256+
List<CyColumnIdentifier> pValueCols = ChartUtil.getSortedColumnIdentifiers(prefix, dataSets, Columns.NODE_PVALUE, columnIdFactory);
257+
props.put(RadialHeatMapChart.P_VALUE_COLS, pValueCols);
258+
259+
if(params.isFDR()) {
260+
props.put(RadialHeatMapChart.Q_VALUE, params.getQvalue());
261+
List<CyColumnIdentifier> qValueCols = ChartUtil.getSortedColumnIdentifiers(prefix, dataSets, Columns.NODE_FDR_QVALUE, columnIdFactory);
262+
props.put(RadialHeatMapChart.Q_VALUE_COLS, qValueCols);
263+
}
264+
}
265+
251266
ColorScheme colorScheme = chartOptions != null ? chartOptions.getColorScheme() : null;
252267

253268
if (colorScheme != null && colorScheme.getPoints() != null) {

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

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,9 @@
66
import static javax.swing.GroupLayout.Alignment.LEADING;
77
import static javax.swing.GroupLayout.Alignment.TRAILING;
88
import static org.baderlab.csplugins.enrichmentmap.EMBuildProps.HELP_URL_CONTROL;
9-
import static org.baderlab.csplugins.enrichmentmap.view.util.IconUtil.EM_ICON_COLORS;
10-
import static org.baderlab.csplugins.enrichmentmap.view.util.IconUtil.GENEMANIA_ICON;
11-
import static org.baderlab.csplugins.enrichmentmap.view.util.IconUtil.GENEMANIA_ICON_COLOR;
12-
import static org.baderlab.csplugins.enrichmentmap.view.util.IconUtil.LAYERED_EM_ICON;
13-
import static org.baderlab.csplugins.enrichmentmap.view.util.IconUtil.LAYERED_STRING_ICON;
14-
import static org.baderlab.csplugins.enrichmentmap.view.util.IconUtil.STRING_ICON_COLORS;
15-
import static org.baderlab.csplugins.enrichmentmap.view.util.IconUtil.getIconFont;
9+
import static org.baderlab.csplugins.enrichmentmap.view.util.IconUtil.*;
1610
import static org.baderlab.csplugins.enrichmentmap.view.util.SwingUtil.makeSmall;
17-
import static org.cytoscape.util.swing.IconManager.ICON_BARS;
18-
import static org.cytoscape.util.swing.IconManager.ICON_FILE;
19-
import static org.cytoscape.util.swing.IconManager.ICON_PLUS;
20-
import static org.cytoscape.util.swing.IconManager.ICON_REFRESH;
21-
import static org.cytoscape.util.swing.IconManager.ICON_STAR;
11+
import static org.cytoscape.util.swing.IconManager.*;
2212
import static org.cytoscape.util.swing.LookAndFeelUtil.isAquaLAF;
2313

2414
import java.awt.BorderLayout;
@@ -604,7 +594,7 @@ void updateChartColorsCombo() {
604594
if (data.isChartTypeSelectable()) {
605595
for (ColorScheme scheme : ColorScheme.values()) {
606596
// If "NES" and Radial Heat Map, use RD_BU_9 instead of RD_BU_3
607-
if (data == ChartData.NES_VALUE && type == ChartType.RADIAL_HEAT_MAP) {
597+
if ((data == ChartData.NES_VALUE || data == ChartData.NES_SIG) && type == ChartType.RADIAL_HEAT_MAP) {
608598
if (scheme == ColorScheme.RD_BU_3)
609599
continue;
610600
} else if (scheme == ColorScheme.RD_BU_9) {
@@ -884,6 +874,7 @@ JComboBox<ChartData> getChartDataCombo() {
884874
chartDataCombo = new JComboBox<>();
885875
chartDataCombo.addItem(ChartData.NONE);
886876
chartDataCombo.addItem(ChartData.NES_VALUE);
877+
chartDataCombo.addItem(ChartData.NES_SIG);
887878
chartDataCombo.addItem(ChartData.P_VALUE);
888879

889880
EnrichmentMap map = getEnrichmentMap();

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
@@ -345,7 +345,7 @@ private void updateNodeChartColorPanel(Collection<EMDataSet> dataSets) {
345345
);
346346

347347

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,13 @@ public static List<Color> getChartColors(ChartOptions options, boolean forStyle)
141141
ChartData data = options != null ? options.getData() : null;
142142

143143
if (colors == null || colors.size() < 3) // UP, ZERO, DOWN:
144-
colors = Arrays.asList(new Color[] { Color.LIGHT_GRAY, Color.WHITE, Color.DARK_GRAY });
144+
colors = Arrays.asList(Color.LIGHT_GRAY, Color.WHITE, Color.DARK_GRAY);
145145

146146
if(forStyle) {
147147
// The 3-color schemes need to be swapped when the chart only includes positive numbers.
148148
// Swap UP and ZERO colors if q or p-value (it should not have negative values!)
149149
if ((data == ChartData.FDR_VALUE || data == ChartData.P_VALUE) && colors.size() == 3)
150-
colors = Arrays.asList(new Color[] { colors.get(1), colors.get(0), colors.get(1) });
150+
colors = Arrays.asList(colors.get(1), colors.get(0), colors.get(1));
151151
}
152152

153153
return colors;

0 commit comments

Comments
 (0)