Skip to content

Commit 41c484a

Browse files
committed
Fixes #121. Post-Analysis edge width no longer uses an Equation.
1 parent bbeaf04 commit 41c484a

File tree

13 files changed

+225
-293
lines changed

13 files changed

+225
-293
lines changed

EnrichmentMapPlugin/.classpath

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<attribute name="maven.pomderived" value="true"/>
1313
</attributes>
1414
</classpathentry>
15-
<classpathentry excluding="**" including="**/*.java" kind="src" output="target/classes" path="src/main/resources">
15+
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
1616
<attributes>
1717
<attribute name="maven.pomderived" value="true"/>
1818
</attributes>

EnrichmentMapPlugin/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,6 @@
9999
<artifactId>group-api</artifactId>
100100
<version>${cy3.version}</version>
101101
</dependency>
102-
<dependency>
103-
<groupId>org.cytoscape</groupId>
104-
<artifactId>equations-api</artifactId>
105-
<version>${cy3.version}</version>
106-
</dependency>
107102

108103
<!-- additional libraries -->
109104
<dependency>

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/CyActivator.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import org.baderlab.csplugins.enrichmentmap.actions.LoadEnrichmentsPanelAction;
1313
import org.baderlab.csplugins.enrichmentmap.actions.LoadPostAnalysisPanelAction;
1414
import org.baderlab.csplugins.enrichmentmap.actions.ShowAboutPanelAction;
15-
import org.baderlab.csplugins.enrichmentmap.actions.ShowEdgeWidthPanelAction;
15+
import org.baderlab.csplugins.enrichmentmap.actions.ShowEdgeWidthDialogAction;
1616
import org.baderlab.csplugins.enrichmentmap.autoannotate.AutoAnnotationManager;
1717
import org.baderlab.csplugins.enrichmentmap.autoannotate.action.AutoAnnotationPanelAction;
1818
import org.baderlab.csplugins.enrichmentmap.autoannotate.action.DisplayOptionsPanelAction;
@@ -31,7 +31,6 @@
3131
import org.cytoscape.application.swing.CyAction;
3232
import org.cytoscape.application.swing.CySwingApplication;
3333
import org.cytoscape.command.CommandExecutorTaskFactory;
34-
import org.cytoscape.equations.EquationCompiler;
3534
import org.cytoscape.event.CyEventHelper;
3635
import org.cytoscape.group.CyGroupFactory;
3736
import org.cytoscape.group.CyGroupManager;
@@ -78,13 +77,8 @@ public class CyActivator extends AbstractCyActivator {
7877
public void start(BundleContext bc) {
7978

8079
//fetch Cytoscape OSGi services that EM needs
81-
//main service for dealing with the cytoscape application. (used when putting in cytopanels...)
8280
CySwingApplication cySwingApplicationRef = getService(bc,CySwingApplication.class);
83-
84-
//open browser used by about, enrichment map panel,
8581
OpenBrowser openBrowserRef = getService(bc, OpenBrowser.class);
86-
87-
//get FileUtil
8882
FileUtil fileUtil = getService(bc,FileUtil.class);
8983
StreamUtil streamUtil = getService(bc, StreamUtil.class);
9084
CyApplicationManager cyApplicationManagerRef = getService(bc,CyApplicationManager.class);
@@ -118,13 +112,12 @@ public void start(BundleContext bc) {
118112
CommandExecutorTaskFactory commandExecutor = getService(bc, CommandExecutorTaskFactory.class);
119113
//get the service registrar so we can register new services in different classes
120114
CyServiceRegistrar registrar = getService(bc, CyServiceRegistrar.class);
121-
EquationCompiler compilerServiceRef = getService(bc, EquationCompiler.class);
122115

123116

124117
//create the Panels
125118
BulkEMCreationPanel bulkEmPanel = new BulkEMCreationPanel(cySwingApplicationRef,fileUtil,registrar, sessionManager, streamUtil, cyApplicationManagerRef);
126119
EnrichmentMapInputPanel emPanel = new EnrichmentMapInputPanel(cyNetworkFactoryRef, cyApplicationManagerRef, cyNetworkManagerRef, cyNetworkViewManagerRef, tableFactory, tableManager, cyNetworkViewFactoryRef, visualMappingManagerRef, visualStyleFactoryRef, continuousMappingFunctionFactoryRef,discreteMappingFunctionFactoryRef, passthroughMappingFunctionFactoryRef, dialogTaskManager, sessionManager, cySwingApplicationRef, openBrowserRef,fileUtil,streamUtil,registrar,layoutManager,mapTableToNetworkTable,bulkEmPanel);
127-
PostAnalysisPanel postEMPanel = new PostAnalysisPanel(cyApplicationManagerRef,cySwingApplicationRef, openBrowserRef,fileUtil,sessionManager, streamUtil,registrar, dialogTaskManager, syncTaskManager, eventHelper, compilerServiceRef, visualMappingManagerRef, visualStyleFactoryRef, continuousMappingFunctionFactoryRef, discreteMappingFunctionFactoryRef, passthroughMappingFunctionFactoryRef);
120+
PostAnalysisPanel postEMPanel = new PostAnalysisPanel(cyApplicationManagerRef,cySwingApplicationRef, openBrowserRef,fileUtil,sessionManager, streamUtil,registrar, dialogTaskManager, syncTaskManager, eventHelper, visualMappingManagerRef, visualStyleFactoryRef, continuousMappingFunctionFactoryRef, discreteMappingFunctionFactoryRef, passthroughMappingFunctionFactoryRef);
128121
//create two instances of the heatmap panel
129122
HeatMapPanel heatMapPanel_node = new HeatMapPanel(true, cySwingApplicationRef, fileUtil, cyApplicationManagerRef, openBrowserRef,dialogTaskManager,streamUtil);
130123
HeatMapPanel heatMapPanel_edge = new HeatMapPanel(false, cySwingApplicationRef, fileUtil, cyApplicationManagerRef, openBrowserRef,dialogTaskManager,streamUtil);
@@ -152,8 +145,6 @@ public void start(BundleContext bc) {
152145
registerService(bc, autoAnnotationManager, ColumnDeletedListener.class, new Properties());
153146
registerService(bc, autoAnnotationManager, ColumnNameChangedListener.class, new Properties());
154147

155-
WidthFunction widthFunction = new WidthFunction(cyNetworkManagerRef, continuousMappingFunctionFactoryRef, manager);
156-
157148
//Create each Action within Enrichment map as a service
158149
Map<String,String> serviceProperties;
159150

@@ -195,7 +186,7 @@ public void start(BundleContext bc) {
195186
serviceProperties = new HashMap<>();
196187
serviceProperties.put("inMenuBar", "true");
197188
serviceProperties.put("preferredMenu", "Apps.EnrichmentMap");
198-
ShowEdgeWidthPanelAction edgeWidthPanelAction = new ShowEdgeWidthPanelAction(serviceProperties, cyApplicationManagerRef ,cyNetworkViewManagerRef, cySwingApplicationRef, manager, compilerServiceRef);
189+
ShowEdgeWidthDialogAction edgeWidthPanelAction = new ShowEdgeWidthDialogAction(serviceProperties, cyApplicationManagerRef, continuousMappingFunctionFactoryRef, dialogTaskManager, cyNetworkViewManagerRef, cySwingApplicationRef);
199190

200191
//register the services
201192
registerService(bc, LoadEnrichmentMapInputPanelAction, CyAction.class, new Properties());
@@ -229,7 +220,5 @@ public void start(BundleContext bc) {
229220
tableColumnTaskFactoryProps.setProperty("tableTypes", "edge");
230221
registerService(bc, tableColumnTaskFactory, TableColumnTaskFactory.class, tableColumnTaskFactoryProps);
231222

232-
// register width function (used in formulas/equations in the table browser)
233-
compilerServiceRef.getParser().registerFunction(widthFunction);
234223
}
235224
}

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/PostAnalysisVisualStyle.java

Lines changed: 10 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,11 @@
22

33
import java.awt.Color;
44
import java.awt.Paint;
5-
import java.util.HashMap;
6-
import java.util.Map;
75

86
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;
127
import org.cytoscape.model.CyEdge;
138
import org.cytoscape.model.CyNetwork;
149
import org.cytoscape.model.CyNode;
15-
import org.cytoscape.model.CyRow;
16-
import org.cytoscape.model.CyTable;
1710
import org.cytoscape.view.model.View;
1811
import org.cytoscape.view.presentation.property.BasicVisualLexicon;
1912
import org.cytoscape.view.presentation.property.LineTypeVisualProperty;
@@ -24,43 +17,31 @@
2417
import org.cytoscape.view.vizmap.VisualStyle;
2518
import org.cytoscape.view.vizmap.mappings.DiscreteMapping;
2619
import org.cytoscape.view.vizmap.mappings.PassthroughMapping;
20+
import org.cytoscape.work.TaskMonitor;
2721

2822
public class PostAnalysisVisualStyle {
2923

3024
public static final String NAME = "Post_analysis_style";
3125

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")
4026
private final VisualMappingFunctionFactory vmfFactoryContinuous;
4127
private final VisualMappingFunctionFactory vmfFactoryDiscrete;
4228
private final VisualMappingFunctionFactory vmfFactoryPassthrough;
43-
private final EquationCompiler equationCompiler;
4429

4530
private final EnrichmentMapVisualStyle delegateStyle;
4631

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-
5232
private static final Color PINK = new Color(255,0,200);
5333
private static final Color YELLOW = new Color(255,255,0);
5434

5535

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) {
5840

5941
this.delegateStyle = new EnrichmentMapVisualStyle(emParsms, vmfFactoryContinuous, vmfFactoryDiscrete, vmfFactoryPassthrough);
6042
this.vmfFactoryContinuous = vmfFactoryContinuous;
6143
this.vmfFactoryDiscrete = vmfFactoryDiscrete;
6244
this.vmfFactoryPassthrough = vmfFactoryPassthrough;
63-
this.equationCompiler = equationCompiler;
6445
}
6546

6647
/**
@@ -74,16 +55,12 @@ public void createVisualStyle(VisualStyle vs, String prefix) {
7455
/**
7556
* Sets node bypasses and edge equations.
7657
*/
77-
public void applyNetworkSpeficifProperties(BuildDiseaseSignatureTaskResult taskResult, String prefix) {
58+
public void applyNetworkSpeficifProperties(BuildDiseaseSignatureTaskResult taskResult, String prefix, TaskMonitor taskMonitor) {
7859
createNodeBypassForColor(taskResult);
7960
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);
8764
}
8865

8966

@@ -109,7 +86,7 @@ private void createPostAnalysisAppearance(VisualStyle vs, String prefix) {
10986
vs.addVisualMappingFunction(disMapping_nodeShape);
11087

11188
// 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;
11390
PassthroughMapping<Double,Double> edgeWidthMapping = (PassthroughMapping<Double,Double>) vmfFactoryPassthrough.createVisualMappingFunction(widthAttribute, Double.class, BasicVisualLexicon.EDGE_WIDTH);
11491
vs.addVisualMappingFunction(edgeWidthMapping);
11592
}
@@ -126,90 +103,4 @@ private void createNodeBypassForColor(BuildDiseaseSignatureTaskResult taskResult
126103
}
127104

128105

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-
215106
}

0 commit comments

Comments
 (0)