Skip to content

Commit 2655500

Browse files
committed
Fixes #120, Fixes #108. Run UpdateHeatMapTask in a separate thread to
avaoid UI deadlock.
1 parent 41c484a commit 2655500

File tree

3 files changed

+105
-22
lines changed

3 files changed

+105
-22
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ public void start(BundleContext bc) {
144144
registerService(bc, autoAnnotationManager, ColumnCreatedListener.class, new Properties());
145145
registerService(bc, autoAnnotationManager, ColumnDeletedListener.class, new Properties());
146146
registerService(bc, autoAnnotationManager, ColumnNameChangedListener.class, new Properties());
147+
registerService(bc, autoAnnotationManager, RowsSetListener.class, new Properties());
147148

148149
//Create each Action within Enrichment map as a service
149150
Map<String,String> serviceProperties;

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/autoannotate/AutoAnnotationManager.java

Lines changed: 104 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22

33
import java.util.Collections;
44
import java.util.HashMap;
5+
import java.util.List;
56
import java.util.SortedMap;
67
import java.util.TreeMap;
78

9+
import javax.swing.ListSelectionModel;
10+
import javax.swing.table.TableModel;
11+
812
import org.baderlab.csplugins.enrichmentmap.actions.EnrichmentMapActionListener;
913
import org.baderlab.csplugins.enrichmentmap.autoannotate.action.DisplayOptionsPanelAction;
14+
import org.baderlab.csplugins.enrichmentmap.autoannotate.model.AnnotationSet;
15+
import org.baderlab.csplugins.enrichmentmap.autoannotate.model.Cluster;
1016
import org.baderlab.csplugins.enrichmentmap.autoannotate.view.AutoAnnotationPanel;
1117
import org.baderlab.csplugins.enrichmentmap.autoannotate.view.DisplayOptionsPanel;
1218
import org.baderlab.csplugins.enrichmentmap.view.HeatMapPanel;
@@ -21,7 +27,9 @@
2127
import org.cytoscape.group.CyGroupFactory;
2228
import org.cytoscape.group.CyGroupManager;
2329
import org.cytoscape.model.CyNetwork;
30+
import org.cytoscape.model.CyNode;
2431
import org.cytoscape.model.CyTableManager;
32+
import org.cytoscape.model.CyTableUtil;
2533
import org.cytoscape.model.events.ColumnCreatedEvent;
2634
import org.cytoscape.model.events.ColumnCreatedListener;
2735
import org.cytoscape.model.events.ColumnDeletedEvent;
@@ -50,7 +58,7 @@
5058
public class AutoAnnotationManager implements
5159
SetSelectedNetworkViewsListener, ColumnCreatedListener,
5260
ColumnDeletedListener, ColumnNameChangedListener,
53-
NetworkViewAboutToBeDestroyedListener {
61+
NetworkViewAboutToBeDestroyedListener, RowsSetListener {
5462

5563
// instance variable used to get the manager from other parts of the program
5664
private static AutoAnnotationManager instance = null;
@@ -180,6 +188,101 @@ public void handleEvent(NetworkViewAboutToBeDestroyedEvent e) {
180188
}
181189
}
182190

191+
@Override
192+
public void handleEvent(RowsSetEvent e) {
193+
if (annotationPanel != null && e.getColumnRecords(CyNetwork.SELECTED).size() > 0) {
194+
195+
//get the current network
196+
CyNetwork network = this.applicationManager.getCurrentNetwork();
197+
CyNetworkView view = this.applicationManager.getCurrentNetworkView();
198+
List<CyNode> selectedNodes = CyTableUtil.getNodesInState(network, CyNetwork.SELECTED, true);
199+
200+
//if the network has been autoannotated we need to make sure the clusters have been selected
201+
//also only handle the node selection events (not edges)
202+
//TODO:need a cleaner way to find out if the currentView has an annotation
203+
if(AutoAnnotationManager.getInstance().getAnnotationPanel()!=null && !AutoAnnotationManager.getInstance().isClusterTableUpdating()
204+
&& e.getSource() == network.getDefaultNodeTable()) {
205+
206+
//go through all the clusters for this network to see if any of the cluster have all of their nodes selected
207+
HashMap<CyNetworkView, AutoAnnotationParameters> annotations = AutoAnnotationManager.getInstance().getNetworkViewToAutoAnnotationParameters();
208+
if(annotations.containsKey(view)){
209+
AnnotationSet currentAnnotation = annotations.get(view).getSelectedAnnotationSet();
210+
TableModel clusterTableModel = currentAnnotation.getClusterTable().getModel();
211+
ListSelectionModel clusterListSelectionModel = currentAnnotation.getClusterTable().getSelectionModel();
212+
System.out.println("HERE");
213+
//if there are clusters to add or to remove only do it once we have gone through all the clusters - to avoid race conditions.
214+
clusterListSelectionModel.setValueIsAdjusting(true);
215+
216+
TreeMap<Integer, Cluster> clusters = currentAnnotation.getClusterMap();
217+
//go through each cluster - figure out which ones need to be selected and
218+
//which ones need to deselected
219+
//If any nodes in a cluster are no longer selected then deselect cluster
220+
//If all nodes in a cluster are selected then select cluster (in table and annotation)
221+
for(Cluster cluster:clusters.values()){
222+
223+
boolean select = true;
224+
boolean unselectCluster = false;
225+
for (CyNode node : cluster.getNodes()) {
226+
//if any of the nodes that belong to this cluster are not in the selected set
227+
//And the cluster is current marked as selected
228+
//then unselect the cluster
229+
if (!selectedNodes.contains(node) && cluster.isSelected()) {
230+
unselectCluster = true;
231+
break;
232+
}
233+
//if any of the nodes that belong to this cluster are not in the selected set
234+
//then do not select this cluster.
235+
if (!selectedNodes.contains(node)) {
236+
select = false;
237+
break;
238+
}
239+
}
240+
241+
//one last check, if the cluster is already selected and all its nodes are
242+
//already selected then this is not a new selection event
243+
if(select == true && cluster.isSelected())
244+
select = false;
245+
246+
//Cluster has been selected
247+
//if all nodes in a cluster are selected
248+
//update the cluster table
249+
if (select) {
250+
//set flag to tell listener that it shouldn't reselect the nodes as the user manually selected them.
251+
currentAnnotation.setManualSelection(true);
252+
for (int rowIndex = 0; rowIndex < clusterTableModel.getRowCount(); rowIndex++) {
253+
if (cluster.equals(clusterTableModel.getValueAt(rowIndex, 0))) {
254+
clusterListSelectionModel.addSelectionInterval(rowIndex, rowIndex);
255+
//AutoAnnotationManager.getInstance().flushPayloadEvents();
256+
break;
257+
}
258+
}
259+
}
260+
261+
//Cluster has been unselected
262+
//update the cluster table
263+
if(unselectCluster){
264+
//set flag to tell listener that it shouldn't reselect the nodes as the user manually selected them.
265+
currentAnnotation.setManualSelection(true);
266+
for (int rowIndex = 0; rowIndex < clusterTableModel.getRowCount(); rowIndex++) {
267+
if (cluster.equals(clusterTableModel.getValueAt(rowIndex, 0))) {
268+
clusterListSelectionModel.removeSelectionInterval(rowIndex, rowIndex);
269+
//AutoAnnotationManager.getInstance().flushPayloadEvents();
270+
break;
271+
}//end of if
272+
}//end of for
273+
274+
}//end of if unselectedcluster
275+
276+
}//end of For going through all clusters
277+
278+
//if there are clusters to add or to remove only do it once we have gone through all the clusters - to avoid race conditions.
279+
clusterListSelectionModel.setValueIsAdjusting(false);
280+
281+
}
282+
}
283+
}
284+
}
285+
183286
public HashMap<CyNetworkView, AutoAnnotationParameters> getNetworkViewToAutoAnnotationParameters() {
184287
return networkViewToAutoAnnotationParameters;
185288
}
@@ -277,10 +380,6 @@ public CytoPanel getSouthPanel() {
277380
return application.getCytoPanel(CytoPanelName.SOUTH);
278381
}
279382

280-
public boolean isHeatMapUpdating() {
281-
return EMActionListener.isHeatMapUpdating();
282-
}
283-
284383
public void flushPayloadEvents() {
285384
eventHelper.flushPayloadEvents();
286385
}

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/autoannotate/task/cluster/SelectClusterTask.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
import org.baderlab.csplugins.enrichmentmap.autoannotate.AutoAnnotationManager;
77
import org.baderlab.csplugins.enrichmentmap.autoannotate.model.Cluster;
88
import org.baderlab.csplugins.enrichmentmap.autoannotate.task.VisualizeClusterAnnotationTaskFactory;
9-
import org.cytoscape.command.CommandExecutorTaskFactory;
109
import org.cytoscape.model.CyNetwork;
1110
import org.cytoscape.model.CyNode;
1211
import org.cytoscape.work.AbstractTask;
13-
import org.cytoscape.work.SynchronousTaskManager;
1412
import org.cytoscape.work.TaskIterator;
1513
import org.cytoscape.work.TaskMonitor;
1614

@@ -79,11 +77,6 @@ public void selectCluster_withnodes() {
7977
CyNetwork network = cluster.getParent().getView().getModel();
8078
AutoAnnotationManager autoAnnotationManager = AutoAnnotationManager.getInstance();
8179
autoAnnotationManager.flushPayloadEvents();
82-
// Wait for heatmap to finish updating
83-
boolean heatMapUpdating = true;
84-
while (heatMapUpdating) {
85-
heatMapUpdating = autoAnnotationManager.isHeatMapUpdating();
86-
}
8780
cluster.setSelected(true);
8881
// Select node(s) in the cluster
8982
if (cluster.isCollapsed()) {
@@ -121,11 +114,6 @@ public void selectCluster_nonodes() {
121114

122115
AutoAnnotationManager autoAnnotationManager = AutoAnnotationManager.getInstance();
123116
autoAnnotationManager.flushPayloadEvents();
124-
// Wait for heatmap to finish updating
125-
boolean heatMapUpdating = true;
126-
while (heatMapUpdating) {
127-
heatMapUpdating = autoAnnotationManager.isHeatMapUpdating();
128-
}
129117
cluster.setSelected(true);
130118
updateCloud( "wordcloud select cloudName=\"" + cluster.getCloudName() + "\" updateNodeSelection=false");
131119
selectCluster(cluster);
@@ -138,11 +126,6 @@ public void selectCluster_nonodes_nocloud() {
138126

139127
AutoAnnotationManager autoAnnotationManager = AutoAnnotationManager.getInstance();
140128
autoAnnotationManager.flushPayloadEvents();
141-
// Wait for heatmap to finish updating
142-
boolean heatMapUpdating = true;
143-
while (heatMapUpdating) {
144-
heatMapUpdating = autoAnnotationManager.isHeatMapUpdating();
145-
}
146129
cluster.setSelected(true);
147130

148131
selectCluster(cluster);

0 commit comments

Comments
 (0)