Skip to content

Commit f238065

Browse files
committed
Filter signature edges by dataset.
Refs #462
1 parent f2fa936 commit f238065

File tree

6 files changed

+92
-24
lines changed

6 files changed

+92
-24
lines changed

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

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.stream.Collectors;
1919

2020
import org.baderlab.csplugins.enrichmentmap.model.EMDataSet.Method;
21+
import org.baderlab.csplugins.enrichmentmap.style.EMStyleBuilder;
2122
import org.baderlab.csplugins.enrichmentmap.util.NetworkUtil;
2223
import org.cytoscape.model.CyNetwork;
2324
import org.cytoscape.model.CyNetworkManager;
@@ -420,16 +421,74 @@ public static Set<Long> getNodesIntersection(Collection<? extends AbstractDataSe
420421
return getIntersection(dataSets, AbstractDataSet::getNodeSuids);
421422
}
422423

424+
423425
/**
424426
* Returns the SUIDs for all the gene-sets in the given collection of DataSets.
425427
* Each returned gene-set is contained in at least one of the given DataSets.
426428
*
427429
* Note, this will only return distinct edges, not compound edges.
430+
*
431+
* This method considers edges that are connected to signature gene sets to be part of the
432+
* signature data set.
428433
*/
429434
public static Set<Long> getEdgesUnion(Collection<? extends AbstractDataSet> dataSets) {
430435
return getUnion(dataSets, AbstractDataSet::getEdgeSuids);
431436
}
432437

438+
/**
439+
* This method checks if signature edges are actually part of one of the given regular data sets
440+
* when including them or not.
441+
*/
442+
public static Set<Long> getEdgesUnionForFiltering(Collection<? extends AbstractDataSet> dataSets, EnrichmentMap map, CyNetwork network) {
443+
List<EMDataSet> regularDatasets = new ArrayList<>();
444+
List<EMSignatureDataSet> signatureDatasets = new ArrayList<>();
445+
446+
for(var ds : dataSets) {
447+
if(ds instanceof EMDataSet) {
448+
regularDatasets.add((EMDataSet)ds);
449+
} else if(ds instanceof EMSignatureDataSet) {
450+
signatureDatasets.add((EMSignatureDataSet)ds);
451+
}
452+
}
453+
454+
Set<Long> regularEdgesUnion = getUnion(regularDatasets, AbstractDataSet::getEdgeSuids);
455+
456+
if(map == null || network == null || signatureDatasets.isEmpty()) {
457+
return regularEdgesUnion;
458+
}
459+
460+
// The problem with Signature edges is that they are associated with the Signature Data Set,
461+
// not the data set they were computed against. This information is only available in the
462+
// edge table. So we have to go through all the Signature edges and check if they are associated
463+
// with any of the regular data sets.
464+
465+
Set<Long> allEdges = new HashSet<>();
466+
allEdges.addAll(regularEdgesUnion);
467+
468+
469+
Set<String> regularDataSetNames = new HashSet<>();
470+
for(var ds : regularDatasets) {
471+
regularDataSetNames.add(ds.getName());
472+
}
473+
474+
var edgeTable = network.getDefaultEdgeTable();
475+
476+
for(var sigDS : signatureDatasets) {
477+
for(Long suid : sigDS.getEdgeSuids()) {
478+
if(edgeTable.rowExists(suid)) {
479+
var row = edgeTable.getRow(suid);
480+
String prefix = map.getParams().getAttributePrefix();
481+
String dsname = EMStyleBuilder.Columns.EDGE_DATASET.get(row, prefix);
482+
if(regularDataSetNames.contains(dsname)) {
483+
allEdges.add(suid);
484+
}
485+
}
486+
}
487+
}
488+
489+
return allEdges;
490+
}
491+
433492
/**
434493
* Returns the SUIDs for all the gene-sets in the given collection of DataSets.
435494
* Each returned gene-set is contained all of the given DataSets.

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/task/SelectNodesEdgesTask.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,29 @@
3030

3131
public class SelectNodesEdgesTask extends AbstractTask {
3232

33+
private final EnrichmentMap map;
3334
private final CyNetworkView networkView;
3435
private final Set<AbstractDataSet> dataSets;
3536
private final boolean distinctEdges;
3637

3738
@Inject private CyEventHelper eventHelper;
3839

3940
public interface Factory {
40-
SelectNodesEdgesTask create(CyNetworkView networkView, Set<AbstractDataSet> dataSets, boolean distinctEdges);
41+
SelectNodesEdgesTask create(
42+
EnrichmentMap map,
43+
CyNetworkView networkView,
44+
Set<AbstractDataSet> dataSets,
45+
boolean distinctEdges);
4146
}
4247

4348
@Inject
44-
public SelectNodesEdgesTask(@Assisted CyNetworkView networkView, @Assisted Set<AbstractDataSet> dataSets,
45-
@Assisted boolean distinctEdges) {
49+
public SelectNodesEdgesTask(
50+
@Assisted EnrichmentMap map,
51+
@Assisted CyNetworkView networkView,
52+
@Assisted Set<AbstractDataSet> dataSets,
53+
@Assisted boolean distinctEdges
54+
) {
55+
this.map = map;
4656
this.networkView = networkView;
4757
this.dataSets = dataSets;
4858
this.distinctEdges = distinctEdges;
@@ -58,7 +68,7 @@ public void run(TaskMonitor tm) {
5868
final Set<Long> dataSetEdges;
5969

6070
if (distinctEdges) {
61-
dataSetEdges = EnrichmentMap.getEdgesUnion(dataSets);
71+
dataSetEdges = EnrichmentMap.getEdgesUnionForFiltering(dataSets, map, networkView.getModel());
6272
} else {
6373
dataSetEdges = new HashSet<>();
6474

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/task/postanalysis/CreatePANetworkTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ private void createEdge(SimilarityKey similarityKey, CyNetwork network, CyNetwor
329329
Columns.EDGE_OVERLAP_GENES.set(row, prefix, null, geneList);
330330
Columns.EDGE_OVERLAP_SIZE.set(row, prefix, null, genesetSimilarity.getSizeOfOverlap());
331331
Columns.EDGE_SIMILARITY_COEFF.set(row, prefix, null, genesetSimilarity.getSimilarityCoeffecient());
332-
Columns.EDGE_DATASET.set(row, prefix, null, similarityKey.getName());
332+
Columns.EDGE_DATASET.set(row, prefix, null, similarityKey.getName()); // the similarityKey name is the same as the dataset name
333333
Columns.EDGE_SIG_DATASET.set(row, prefix, null, sigDataSet.getName());
334334

335335
String dataset = genesetSimilarity.getDataSetName();

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/task/postanalysis/PASimilarityTaskParallel.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,9 @@ public class PASimilarityTaskParallel extends CancellableParallelTask<Map<Simila
5151

5252

5353
public static interface Factory {
54-
PASimilarityTaskParallel create(PostAnalysisParameters params, EnrichmentMap map);
5554
PASimilarityTaskParallel create(PostAnalysisParameters params, EnrichmentMap map, List<EMDataSet> dataSets);
5655
}
5756

58-
@AssistedInject
59-
public PASimilarityTaskParallel(@Assisted PostAnalysisParameters params, @Assisted EnrichmentMap map) {
60-
this(params, map, map.getDataSetList());
61-
}
6257

6358
@AssistedInject
6459
public PASimilarityTaskParallel(@Assisted PostAnalysisParameters params, @Assisted EnrichmentMap map, @Assisted List<EMDataSet> dataSets) {
@@ -138,10 +133,11 @@ public Map<SimilarityKey,SignatureGenesetSimilarity> compute(TaskMonitor tm, Exe
138133
boolean passesCutoff = metric.passes(value);
139134
comparison.setPassesCutoff(passesCutoff);
140135

136+
// Very important that the SimilarityKey name is the dataset name.
137+
// This gets picked up by the CreatePANetworkTask and set on the "Dataset" edge column.
141138
SimilarityKey key = new SimilarityKey(hubName, geneSetName, INTERACTION, dataSet.getName());
142139
geneSetSimilarities.put(key, comparison);
143-
}
144-
140+
}
145141
}
146142
}
147143
}

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/task/postanalysis/RemoveSignatureDataSetsTask.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ private Set<Long> getNodesToDelete() {
6767
}
6868

6969
private Set<Long> getEdgesToDelete() {
70+
// TODO Won't deleting the nodes automatically delete the adjacent edges???
7071
Set<Long> edgesToDelete = EnrichmentMap.getEdgesUnion(signatureDataSets);
7172
return edgesToDelete;
7273
}

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/control/ControlPanelMediator.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,7 @@ private void addListeners(EMViewControlPanel viewPanel, EnrichmentMap map) {
572572

573573
viewPanel.getDataSetSelector().getSelectNodesMenuItem().addActionListener(evt -> {
574574
selectNodesEdges(
575+
map,
575576
viewPanel.getNetworkView(),
576577
viewPanel.getDataSetSelector().getSelectedItems(),
577578
map.getParams().getCreateDistinctEdges()
@@ -1050,8 +1051,8 @@ private void showContextMenu(final JPopupMenu contextMenu, final MouseEvent e) {
10501051
});
10511052
}
10521053

1053-
private void selectNodesEdges(CyNetworkView netView, Set<AbstractDataSet> dataSets, boolean distinctEdges) {
1054-
SelectNodesEdgesTask task = selectNodesEdgesTaskFactory.create(netView, dataSets, distinctEdges);
1054+
private void selectNodesEdges(EnrichmentMap map, CyNetworkView netView, Set<AbstractDataSet> dataSets, boolean distinctEdges) {
1055+
SelectNodesEdgesTask task = selectNodesEdgesTaskFactory.create(map, netView, dataSets, distinctEdges);
10551056
dialogTaskManager.execute(new TaskIterator(task));
10561057
}
10571058

@@ -1079,21 +1080,19 @@ public void actionPerformed(ActionEvent evt) {
10791080

10801081
// Find nodes and edges that must be displayed
10811082
Set<CyNode> filteredInNodes = getFilteredInNodes(selectedDataSets);
1082-
10831083
if (cancelled)
10841084
return;
10851085

10861086
Set<CyEdge> filteredInEdges = getFilteredInEdges(selectedDataSets);
1087-
10881087
if (cancelled)
10891088
return;
10901089

10911090
// Run Task
10921091
task = filterNodesEdgesTaskFactory.create(map, netView, filteredInNodes, filteredInEdges, filterMode);
10931092
dialogTaskManager.execute(new TaskIterator(task), TaskUtil.allFinished(finishStatus -> {
1094-
task = null;
1095-
if (!cancelled)
1096-
netView.updateView();
1093+
task = null;
1094+
if (!cancelled)
1095+
netView.updateView();
10971096
}));
10981097
}
10991098

@@ -1138,20 +1137,23 @@ private Set<CyEdge> getFilteredInEdges(Set<AbstractDataSet> selectedDataSets) {
11381137
EMCreationParameters params = map.getParams();
11391138

11401139
// Compound edges are not associated with a specific data set
1141-
Set<Long> dataSetEdges = EnrichmentMap.getEdgesUnion(selectedDataSets);
1140+
Set<Long> dataSetEdges = EnrichmentMap.getEdgesUnionForFiltering(selectedDataSets, map, netView.getModel());
11421141

1143-
if (viewPanel.getSimilaritySliderPanel() != null)
1144-
return getFilteredInEdges(viewPanel.getSimilaritySliderPanel(), map, netView,
1145-
params.getSimilarityCutoffColumnNames(), dataSetEdges);
1142+
var sliderPanel = viewPanel.getSimilaritySliderPanel();
1143+
if (sliderPanel != null) {
1144+
var names = params.getSimilarityCutoffColumnNames();
1145+
return getFilteredInEdges(sliderPanel, map, netView, names, dataSetEdges);
1146+
}
11461147

11471148
Set<CyEdge> filteredInEdges = new HashSet<>();
11481149
CyNetwork net = netView.getModel();
11491150
boolean distinct = params.getCreateDistinctEdges();
11501151

11511152
if (distinct) {
11521153
for (CyEdge e : net.getEdgeList()) {
1153-
if (dataSetEdges.contains(e.getSUID()))
1154+
if (dataSetEdges.contains(e.getSUID())) {
11541155
filteredInEdges.add(e);
1156+
}
11551157
}
11561158
} else {
11571159
// If compound edges, all edges are filtered in, no matter the selected data sets

0 commit comments

Comments
 (0)