7
7
import java .util .ArrayList ;
8
8
import java .util .Collections ;
9
9
import java .util .HashMap ;
10
+ import java .util .LinkedHashMap ;
10
11
import java .util .List ;
11
12
import java .util .Map ;
12
13
15
16
16
17
import org .baderlab .csplugins .enrichmentmap .style .charts .AbstractChart ;
17
18
import org .baderlab .csplugins .enrichmentmap .style .charts .Rotation ;
19
+ import org .cytoscape .model .CyColumn ;
18
20
import org .cytoscape .model .CyIdentifiable ;
19
21
import org .cytoscape .model .CyNetwork ;
22
+ import org .cytoscape .model .CyRow ;
23
+ import org .cytoscape .model .CyTable ;
20
24
import org .cytoscape .service .util .CyServiceRegistrar ;
21
25
import org .cytoscape .view .model .CyNetworkView ;
22
26
import org .cytoscape .view .model .View ;
@@ -27,6 +31,11 @@ public class RadialHeatMapChart extends AbstractChart<RadialHeatMapLayer> {
27
31
public static final String FACTORY_ID = "org.baderlab.enrichmentmap.RadialHeatMapChart" ;
28
32
public static final String DISPLAY_NAME = "Radial Heat Map Chart" ;
29
33
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
+
30
39
public static final String START_ANGLE = "cy_startAngle" ;
31
40
32
41
public static ImageIcon ICON ;
@@ -52,6 +61,7 @@ public RadialHeatMapChart(final String input, final CyServiceRegistrar serviceRe
52
61
super (DISPLAY_NAME , input , serviceRegistrar );
53
62
}
54
63
64
+
55
65
@ Override
56
66
public List <RadialHeatMapLayer > getLayers (final CyNetworkView networkView , final View <? extends CyIdentifiable > view ) {
57
67
final CyNetwork network = networkView .getModel ();
@@ -92,8 +102,84 @@ public String getId() {
92
102
}
93
103
94
104
@ 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 ) {
97
183
final Map <String , List <Double >> data = new HashMap <>();
98
184
99
185
// 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
110
196
111
197
@ Override
112
198
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 ;
115
209
return super .getSettingType (key );
116
210
}
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
+ }
117
220
}
0 commit comments