2
2
3
3
import java .awt .Color ;
4
4
import java .awt .Paint ;
5
- import java .util .HashMap ;
6
- import java .util .Map ;
7
5
8
6
import org .baderlab .csplugins .enrichmentmap .task .BuildDiseaseSignatureTaskResult ;
9
- import org .cytoscape .equations .Equation ;
10
- import org .cytoscape .equations .EquationCompiler ;
11
- import org .cytoscape .model .CyColumn ;
12
7
import org .cytoscape .model .CyEdge ;
13
8
import org .cytoscape .model .CyNetwork ;
14
9
import org .cytoscape .model .CyNode ;
15
- import org .cytoscape .model .CyRow ;
16
- import org .cytoscape .model .CyTable ;
17
10
import org .cytoscape .view .model .View ;
18
11
import org .cytoscape .view .presentation .property .BasicVisualLexicon ;
19
12
import org .cytoscape .view .presentation .property .LineTypeVisualProperty ;
24
17
import org .cytoscape .view .vizmap .VisualStyle ;
25
18
import org .cytoscape .view .vizmap .mappings .DiscreteMapping ;
26
19
import org .cytoscape .view .vizmap .mappings .PassthroughMapping ;
20
+ import org .cytoscape .work .TaskMonitor ;
27
21
28
22
public class PostAnalysisVisualStyle {
29
23
30
24
public static final String NAME = "Post_analysis_style" ;
31
25
32
- public static final double DEFAULT_WIDTH_EM_LOWER = 1.0 ;
33
- public static final double DEFAULT_WIDTH_EM_UPPER = 5.0 ;
34
- public static final double DEFAULT_WIDTH_PA_LESS_THAN_100 = 8.0 ;
35
- public static final double DEFAULT_WIDTH_PA_LESS_THAN_10 = 4.5 ;
36
- public static final double DEFAULT_WIDTH_PA_GREATER = 1.0 ;
37
-
38
-
39
- @ SuppressWarnings ("unused" )
40
26
private final VisualMappingFunctionFactory vmfFactoryContinuous ;
41
27
private final VisualMappingFunctionFactory vmfFactoryDiscrete ;
42
28
private final VisualMappingFunctionFactory vmfFactoryPassthrough ;
43
- private final EquationCompiler equationCompiler ;
44
29
45
30
private final EnrichmentMapVisualStyle delegateStyle ;
46
31
47
- // Column in edge table that holds the formula
48
- public static final String EDGE_WIDTH_FORMULA_COLUMN = "Edge_width_formula" ;
49
- // Column in network table that holds the edge parameters
50
- public static final String EDGE_WIDTH_PARAMETERS_COLUMN = "EM_Edge_width_parameters" ;
51
-
52
32
private static final Color PINK = new Color (255 ,0 ,200 );
53
33
private static final Color YELLOW = new Color (255 ,255 ,0 );
54
34
55
35
56
- public PostAnalysisVisualStyle (EnrichmentMapParameters emParsms , EquationCompiler equationCompiler ,
57
- VisualMappingFunctionFactory vmfFactoryContinuous , VisualMappingFunctionFactory vmfFactoryDiscrete , VisualMappingFunctionFactory vmfFactoryPassthrough ) {
36
+ public PostAnalysisVisualStyle (EnrichmentMapParameters emParsms ,
37
+ VisualMappingFunctionFactory vmfFactoryContinuous ,
38
+ VisualMappingFunctionFactory vmfFactoryDiscrete ,
39
+ VisualMappingFunctionFactory vmfFactoryPassthrough ) {
58
40
59
41
this .delegateStyle = new EnrichmentMapVisualStyle (emParsms , vmfFactoryContinuous , vmfFactoryDiscrete , vmfFactoryPassthrough );
60
42
this .vmfFactoryContinuous = vmfFactoryContinuous ;
61
43
this .vmfFactoryDiscrete = vmfFactoryDiscrete ;
62
44
this .vmfFactoryPassthrough = vmfFactoryPassthrough ;
63
- this .equationCompiler = equationCompiler ;
64
45
}
65
46
66
47
/**
@@ -74,16 +55,12 @@ public void createVisualStyle(VisualStyle vs, String prefix) {
74
55
/**
75
56
* Sets node bypasses and edge equations.
76
57
*/
77
- public void applyNetworkSpeficifProperties (BuildDiseaseSignatureTaskResult taskResult , String prefix ) {
58
+ public void applyNetworkSpeficifProperties (BuildDiseaseSignatureTaskResult taskResult , String prefix , TaskMonitor taskMonitor ) {
78
59
createNodeBypassForColor (taskResult );
79
60
CyNetwork network = taskResult .getNetwork ();
80
-
81
- CyTable networkTable = network .getDefaultNetworkTable ();
82
- if (networkTable .getColumn (EDGE_WIDTH_PARAMETERS_COLUMN ) == null ) {
83
- networkTable .createColumn (EDGE_WIDTH_PARAMETERS_COLUMN , String .class , false );
84
- }
85
-
86
- applyWidthEquation (equationCompiler , prefix , network );
61
+
62
+ WidthFunction widthFunction = new WidthFunction (vmfFactoryContinuous );
63
+ widthFunction .setEdgeWidths (network , prefix , taskMonitor );
87
64
}
88
65
89
66
@@ -109,7 +86,7 @@ private void createPostAnalysisAppearance(VisualStyle vs, String prefix) {
109
86
vs .addVisualMappingFunction (disMapping_nodeShape );
110
87
111
88
// Replace the edge width mapping that was created by EnrichmentMapVisualStyle
112
- String widthAttribute = prefix + EDGE_WIDTH_FORMULA_COLUMN ;
89
+ String widthAttribute = prefix + WidthFunction . EDGE_WIDTH_FORMULA_COLUMN ;
113
90
PassthroughMapping <Double ,Double > edgeWidthMapping = (PassthroughMapping <Double ,Double >) vmfFactoryPassthrough .createVisualMappingFunction (widthAttribute , Double .class , BasicVisualLexicon .EDGE_WIDTH );
114
91
vs .addVisualMappingFunction (edgeWidthMapping );
115
92
}
@@ -126,90 +103,4 @@ private void createNodeBypassForColor(BuildDiseaseSignatureTaskResult taskResult
126
103
}
127
104
128
105
129
- public static void applyWidthEquation (EquationCompiler equationCompiler , String prefix , CyNetwork network ) {
130
- String widthAttribute = prefix + EDGE_WIDTH_FORMULA_COLUMN ;
131
- CyTable edgeTable = network .getDefaultEdgeTable ();
132
- if (edgeTable .getColumn (widthAttribute ) == null ) {
133
- edgeTable .createColumn (widthAttribute , Double .class , false );
134
- }
135
-
136
- String formula = "=" + WidthFunction .NAME + "($SUID)" ;
137
-
138
- Equation equation = compileEquation (equationCompiler , edgeTable , formula );
139
- for (CyRow row : edgeTable .getAllRows ()) {
140
- row .set (widthAttribute , equation );
141
- }
142
- }
143
-
144
-
145
- private static Equation compileEquation (EquationCompiler equationCompiler , CyTable edgeTable , String formula ) {
146
- Map <String , Class <?>> attribNameToType = attributeToTypeMap (edgeTable );
147
- if (equationCompiler .compile (formula , attribNameToType )) {
148
- return equationCompiler .getEquation ();
149
- }
150
- else {
151
- throw new RuntimeException (equationCompiler .getLastErrorMsg ());
152
- }
153
- }
154
-
155
- private static Map <String ,Class <?>> attributeToTypeMap (CyTable table ) {
156
- Map <String ,Class <?>> map = new HashMap <>();
157
- for (CyColumn column : table .getColumns ())
158
- map .put (column .getName (), column .getType ());
159
- return map ;
160
- }
161
-
162
-
163
- public static boolean appliesTo (CyNetwork network ) {
164
- CyTable networkTable = network .getDefaultNetworkTable ();
165
- return networkTable .getColumn (EDGE_WIDTH_PARAMETERS_COLUMN ) != null ;
166
- }
167
-
168
-
169
- /**
170
- * Parameters typically used by the EdgeWidthDialog and stored in the network table.
171
- */
172
- public static class EdgeWidthParams {
173
- public final double em_lower ;
174
- public final double em_upper ;
175
- public final double pa_lessThan100 ;
176
- public final double pa_lessThan10 ;
177
- public final double pa_greater ;
178
-
179
- public EdgeWidthParams (double em_lower , double em_upper , double pa_lessThan100 , double pa_lessThan10 , double pa_greater ) {
180
- this .em_lower = em_lower ;
181
- this .em_upper = em_upper ;
182
- this .pa_lessThan100 = pa_lessThan100 ;
183
- this .pa_lessThan10 = pa_lessThan10 ;
184
- this .pa_greater = pa_greater ;
185
- }
186
-
187
- public static EdgeWidthParams defaultValues () {
188
- return new EdgeWidthParams (DEFAULT_WIDTH_EM_LOWER , DEFAULT_WIDTH_EM_UPPER ,
189
- DEFAULT_WIDTH_PA_LESS_THAN_100 , DEFAULT_WIDTH_PA_LESS_THAN_10 , DEFAULT_WIDTH_PA_GREATER );
190
- }
191
-
192
- public static EdgeWidthParams restore (CyNetwork network ) {
193
- try {
194
- String val = network .getRow (network ).get (EDGE_WIDTH_PARAMETERS_COLUMN , String .class );
195
- String [] params = val .split ("," );
196
- double em_lower = Double .parseDouble (params [0 ]);
197
- double em_upper = Double .parseDouble (params [1 ]);
198
- double pa_lessThan100 = Double .parseDouble (params [2 ]);
199
- double pa_lessThan10 = Double .parseDouble (params [3 ]);
200
- double pa_greater = Double .parseDouble (params [4 ]);
201
- return new EdgeWidthParams (em_lower , em_upper , pa_lessThan100 , pa_lessThan10 , pa_greater );
202
- } catch (NullPointerException | ArrayIndexOutOfBoundsException | IllegalArgumentException e ) {
203
- return defaultValues ();
204
- }
205
- }
206
-
207
- public void save (CyNetwork network ) {
208
- CyRow row = network .getRow (network );
209
- String val = String .format ("%f,%f,%f,%f,%f" , em_lower , em_upper , pa_lessThan100 , pa_lessThan10 , pa_greater );
210
- row .set (EDGE_WIDTH_PARAMETERS_COLUMN , val );
211
- }
212
- }
213
-
214
-
215
106
}
0 commit comments