4
4
import java .util .Arrays ;
5
5
import java .util .Collection ;
6
6
import java .util .HashMap ;
7
+ import java .util .Iterator ;
7
8
import java .util .List ;
8
9
import java .util .Map ;
9
- import java .util .Set ;
10
10
import java .util .stream .Collectors ;
11
11
12
12
import org .baderlab .csplugins .enrichmentmap .model .AbstractDataSet ;
@@ -74,7 +74,7 @@ public void run(TaskMonitor tm) throws Exception {
74
74
75
75
if (chartOptions != null && chartOptions .getData () == ChartData .DATA_SET ) {
76
76
tm .setStatusMessage ("Updating Data Columns..." );
77
- createDataSetColumn ();
77
+ createOrUpdateDataSetColumn ();
78
78
}
79
79
80
80
tm .setStatusMessage ("Updating Style..." );
@@ -83,34 +83,38 @@ public void run(TaskMonitor tm) throws Exception {
83
83
applyVisualStyle ();
84
84
}
85
85
86
- private void createDataSetColumn () {
86
+ private void createOrUpdateDataSetColumn () {
87
87
EnrichmentMap map = options .getEnrichmentMap ();
88
88
CyNetwork network = networkManager .getNetwork (map .getNetworkID ());
89
89
CyTable nodeTable = network .getDefaultNodeTable ();
90
+ Collection <? extends AbstractDataSet > dataSets = options .getDataSets ();
90
91
91
92
String prefix = map .getParams ().getAttributePrefix ();
92
93
93
- if (!Columns .DATASET_CHART .hasColumn (nodeTable , prefix )) {
94
+ if (!Columns .DATASET_CHART .hasColumn (nodeTable , prefix )) {
94
95
Columns .DATASET_CHART .createColumn (nodeTable , prefix );
96
+ }
95
97
96
- Map <Long , int []> columnData = new HashMap <>();
97
- List <EMDataSet > dataSets = map .getDataSetList ();
98
- int n = dataSets .size ();
98
+ Map <Long , int []> columnData = new HashMap <>();
99
+ int n = dataSets .size ();
99
100
100
- for (CyNode node : network .getNodeList ())
101
- columnData .put (node .getSUID (), new int [n ]);
101
+ for (CyNode node : network .getNodeList ()) {
102
+ columnData .put (node .getSUID (), new int [n ]);
103
+ }
102
104
103
- for (int i = 0 ; i < n ; i ++) {
104
- EMDataSet dataSet = dataSets .get (i );
105
-
106
- for (Long suid : dataSet .getNodeSuids ())
107
- columnData .get (suid )[i ] = 1 ;
105
+ Iterator <? extends AbstractDataSet > iter = dataSets .iterator ();
106
+ int i = 0 ;
107
+ while (iter .hasNext ()) {
108
+ AbstractDataSet ds = iter .next ();
109
+ for (Long suid : ds .getNodeSuids ()) {
110
+ columnData .get (suid )[i ] = 1 ;
108
111
}
109
-
110
- columnData .forEach ((suid , data ) ->
111
- Columns .DATASET_CHART .set (nodeTable .getRow (suid ), prefix , Ints .asList (data ))
112
- );
112
+ i ++;
113
113
}
114
+
115
+ columnData .forEach ((suid , data ) ->
116
+ Columns .DATASET_CHART .set (nodeTable .getRow (suid ), prefix , Ints .asList (data ))
117
+ );
114
118
}
115
119
116
120
private void applyVisualStyle () {
@@ -161,8 +165,7 @@ public CyCustomGraphics2<?> createChart() {
161
165
ChartData data = chartOptions != null ? chartOptions .getData () : null ;
162
166
163
167
if (data != null && data != ChartData .NONE ) {
164
- // Ignore Signature Data Sets in charts
165
- Set <EMDataSet > dataSets = filterEMDataSets (options .getDataSets ());
168
+ List <EMDataSet > dataSets = filterEMDataSets (options .getDataSets ()); // Ignore Signature Data Sets in charts
166
169
167
170
if (!dataSets .isEmpty ()) {
168
171
ChartType type = chartOptions .getType ();
@@ -173,7 +176,7 @@ public CyCustomGraphics2<?> createChart() {
173
176
174
177
if (data == ChartData .DATA_SET ) {
175
178
List <CyColumnIdentifier > columns = Arrays .asList (columnIdFactory .createColumnIdentifier (columnDescriptor .with (prefix )));
176
- List <Color > colors = options . getEnrichmentMap (). getDataSetColors ( );
179
+ List <Color > colors = getColors ( dataSets );
177
180
props .put ("cy_dataColumns" , columns );
178
181
props .put ("cy_colors" , colors );
179
182
props .put ("cy_showItemLabels" , chartOptions .isShowLabels ());
@@ -216,12 +219,17 @@ public CyCustomGraphics2<?> createChart() {
216
219
return chart ;
217
220
}
218
221
222
+
223
+ public static List <Color > getColors (Collection <EMDataSet > dataSets ) {
224
+ return dataSets .stream ().map (EMDataSet ::getColor ).collect (Collectors .toList ());
225
+ }
226
+
219
227
@ SuppressWarnings ("unchecked" )
220
- private static Set <EMDataSet > filterEMDataSets (Collection <AbstractDataSet > abstractDataSets ) {
221
- Set <?> set = abstractDataSets .stream ()
228
+ public static List <EMDataSet > filterEMDataSets (Collection <? extends AbstractDataSet > abstractDataSets ) {
229
+ Collection <?> set = abstractDataSets .stream ()
222
230
.filter (ds -> ds instanceof EMDataSet ) // Ignore Signature Data Sets
223
- .collect (Collectors .toSet ());
231
+ .collect (Collectors .toList ());
224
232
225
- return (Set <EMDataSet >) set ;
233
+ return (List <EMDataSet >) set ;
226
234
}
227
235
}
0 commit comments