Skip to content

Commit 78bb8a1

Browse files
committed
Filter HeatMap based on data set of selected node/edge. Refs #396
1 parent f90e0b0 commit 78bb8a1

File tree

4 files changed

+62
-9
lines changed

4 files changed

+62
-9
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public interface PropertyListener<T> {
3636
public static final Property<Boolean> HEATMAP_AUTOFOCUS = Property.of("heatmapAutofocus", false);
3737
public static final Property<Boolean> HEATMAP_DATASET_SYNC = Property.of("heatmapDatasetSync", true);
3838
public static final Property<Boolean> HEATMAP_AUTO_SORT = Property.of("heatmapAutoSort", true);
39+
public static final Property<Boolean> HEATMAP_SELECT_SYNC = Property.of("heatmapSelectSync", true);
3940
public static final Property<Double> P_VALUE = Property.of("default.pvalue", 1.0);
4041
public static final Property<Double> Q_VALUE = Property.of("default.qvalue", 0.1);
4142
public static final Property<Boolean> CREATE_WARN = Property.of("create.warn", true);
@@ -98,6 +99,10 @@ public <T> T getValue(Property<T> property) {
9899
}
99100
}
100101

102+
public boolean isTrue(Property<Boolean> property) {
103+
return Boolean.TRUE.equals(getValue(property));
104+
}
105+
101106
@SuppressWarnings("rawtypes")
102107
public static List<Property<?>> getAllProperties() {
103108
List<Property<?>> properties = new ArrayList<>();

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/model/AbstractDataSet.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package org.baderlab.csplugins.enrichmentmap.model;
22

33
import java.text.Collator;
4+
import java.util.Collection;
45
import java.util.Collections;
56
import java.util.HashSet;
67
import java.util.Set;
78

9+
import org.cytoscape.model.CyEdge;
10+
import org.cytoscape.model.CyNode;
11+
812
public abstract class AbstractDataSet implements Comparable<AbstractDataSet> {
913

1014
private final String name;
@@ -42,6 +46,24 @@ public EnrichmentMap getMap() {
4246
return map;
4347
}
4448

49+
public boolean containsAnyNode(Collection<CyNode> nodes) {
50+
for(CyNode node : nodes) {
51+
if(nodeSuids.contains(node.getSUID())) {
52+
return true;
53+
}
54+
}
55+
return false;
56+
}
57+
58+
public boolean containsAnyEdge(Collection<CyEdge> edges) {
59+
for(CyEdge edge : edges) {
60+
if(edgeSuids.contains(edge.getSUID())) {
61+
return true;
62+
}
63+
}
64+
return false;
65+
}
66+
4567
public Set<Long> getNodeSuids() {
4668
synchronized (lock) {
4769
return Collections.unmodifiableSet(nodeSuids);

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/heatmap/HeatMapMediator.java

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.Collection;
88
import java.util.Collections;
99
import java.util.HashSet;
10+
import java.util.Iterator;
1011
import java.util.List;
1112
import java.util.Map;
1213
import java.util.Optional;
@@ -104,6 +105,7 @@ public class HeatMapMediator implements RowsSetListener, SetCurrentNetworkViewLi
104105
@AfterInjection
105106
public void setPropertyListeners() {
106107
propertyManager.addListener(PropertyManager.HEATMAP_DATASET_SYNC, (prop, value) -> reset());
108+
propertyManager.addListener(PropertyManager.HEATMAP_SELECT_SYNC, (prop, value) -> reset());
107109
}
108110

109111

@@ -235,21 +237,38 @@ private void heatMapParamsChanged(HeatMapParams params) {
235237
}
236238
}
237239

238-
private Collection<EMDataSet> getEnabledDataSets(CyNetworkView networkView, EnrichmentMap map) {
239-
if(Boolean.TRUE.equals(propertyManager.getValue(PropertyManager.HEATMAP_DATASET_SYNC))) {
240-
// sync with the data set list on the control panel
240+
241+
private Collection<EMDataSet> getEnabledDataSets(
242+
CyNetworkView networkView, EnrichmentMap map,
243+
List<CyNode> selectedNodes, List<CyEdge> selectedEdges
244+
) {
245+
// must maintain the order returned by map.getDataSetList() (issue #390)
246+
List<EMDataSet> dataSets = new ArrayList<>(map.getDataSetList());
247+
248+
// Remove Data Sets that are not selected in the control panel
249+
if(propertyManager.isTrue(PropertyManager.HEATMAP_DATASET_SYNC)) {
241250
ViewParams params = controlPanelMediatorProvider.get().getAllViewParams().get(networkView.getSUID());
242251
if(params != null) {
243-
// important to maintain the order returned by map.getDataSetList() (issue #390)
244-
List<EMDataSet> dataSets = new ArrayList<>(map.getDataSetList());
245252
Set<String> filter = params.getFilteredOutDataSets();
246253
dataSets.removeIf(ds -> filter.contains(ds.getName()));
247-
return dataSets;
248254
}
249255
}
250-
return map.getDataSetList();
256+
257+
// Remove Data Sets that are not part of the selected nodes/edges
258+
if(propertyManager.isTrue(PropertyManager.HEATMAP_SELECT_SYNC)) {
259+
Iterator<EMDataSet> iter = dataSets.iterator();
260+
while(iter.hasNext()) {
261+
EMDataSet ds = iter.next();
262+
if(!ds.containsAnyNode(selectedNodes) && !ds.containsAnyEdge(selectedEdges)) {
263+
iter.remove();
264+
}
265+
}
266+
}
267+
268+
return dataSets;
251269
}
252270

271+
253272
private void updateHeatMap(CyNetworkView networkView) {
254273
if (!isHeatMapPanelRegistered())
255274
return;
@@ -271,7 +290,7 @@ private void updateHeatMap(CyNetworkView networkView) {
271290
if (emManager.isEnrichmentMap(networkView)) {
272291
String prefix = map.getParams().getAttributePrefix();
273292

274-
dataSets = getEnabledDataSets(networkView, map);
293+
dataSets = getEnabledDataSets(networkView, map, selectedNodes, selectedEdges);
275294
Map<String,Set<Integer>> geneSetToGenes = map.unionGeneSetsOfInterest(dataSets);
276295

277296
union = unionGenesets(geneSetToGenes, map, network, selectedNodes, selectedEdges, prefix);

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/heatmap/OptionsPopup.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,18 @@ private void createContents() {
9595
propertyManager.setValue(PropertyManager.HEATMAP_AUTOFOCUS, autofocusCheckbox.isSelected());
9696
});
9797

98-
JCheckBoxMenuItem syncCheckbox = new JCheckBoxMenuItem("Sync with Control Panel");
98+
JCheckBoxMenuItem syncCheckbox = new JCheckBoxMenuItem("Sync Data Sets with Control Panel");
9999
syncCheckbox.setSelected(propertyManager.getValue(PropertyManager.HEATMAP_DATASET_SYNC));
100100
syncCheckbox.addActionListener(e -> {
101101
propertyManager.setValue(PropertyManager.HEATMAP_DATASET_SYNC, syncCheckbox.isSelected());
102102
});
103103

104+
JCheckBoxMenuItem selectedCheckbox = new JCheckBoxMenuItem("Display only selected Data Sets");
105+
selectedCheckbox.setSelected(propertyManager.getValue(PropertyManager.HEATMAP_SELECT_SYNC));
106+
selectedCheckbox.addActionListener(e -> {
107+
propertyManager.setValue(PropertyManager.HEATMAP_SELECT_SYNC, selectedCheckbox.isSelected());
108+
});
109+
104110
JCheckBoxMenuItem autoSortCheckbox = new JCheckBoxMenuItem("Auto sort leading edge");
105111
autoSortCheckbox.setSelected(propertyManager.getValue(PropertyManager.HEATMAP_AUTO_SORT));
106112
autoSortCheckbox.addActionListener(e -> {
@@ -118,6 +124,7 @@ private void createContents() {
118124
add(distanceMenu);
119125
add(autofocusCheckbox);
120126
add(syncCheckbox);
127+
add(selectedCheckbox);
121128
add(autoSortCheckbox);
122129
}
123130

0 commit comments

Comments
 (0)