Skip to content

Commit 2ddfd35

Browse files
committed
Better support for EM2 session files. Fixes many issues with styles.
1 parent a98b105 commit 2ddfd35

File tree

6 files changed

+95
-48
lines changed

6 files changed

+95
-48
lines changed

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/model/io/LegacySessionLoader.java

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.baderlab.csplugins.enrichmentmap.model.SetOfEnrichmentResults;
2929
import org.baderlab.csplugins.enrichmentmap.model.SetOfGeneSets;
3030
import org.baderlab.csplugins.enrichmentmap.parsers.ExpressionFileReaderTask;
31+
import org.baderlab.csplugins.enrichmentmap.style.EMStyleBuilder;
3132
import org.baderlab.csplugins.enrichmentmap.task.InitializeGenesetsOfInterestTask;
3233
import org.cytoscape.application.CyApplicationManager;
3334
import org.cytoscape.io.util.StreamUtil;
@@ -36,6 +37,7 @@
3637
import org.cytoscape.model.CyNetworkManager;
3738
import org.cytoscape.model.CyNode;
3839
import org.cytoscape.model.CyRow;
40+
import org.cytoscape.model.CyTable;
3941
import org.cytoscape.service.util.CyServiceRegistrar;
4042
import org.cytoscape.session.CySession;
4143

@@ -67,15 +69,15 @@ public static boolean isLegacy(CySession session) {
6769

6870

6971
public void loadSession(CySession session) {
70-
createModelFromSessionFiles(session);
71-
migrate();
72+
createModelFromFilesInSession(session);
73+
migrateModel();
7274
}
7375

7476

7577
/**
76-
* Reconstruct important model data using EM2 conventions.
78+
* Migrate the EM2 model to EM3.
7779
*/
78-
private void migrate() {
80+
private void migrateModel() {
7981
for(EnrichmentMap map : emManager.getAllEnrichmentMaps().values()) {
8082
if(map.isLegacy()) { // Is this check necessary?
8183
EMDataSet ds1 = map.getDataSet(LegacySupport.DATASET1);
@@ -85,7 +87,9 @@ private void migrate() {
8587
EMCreationParameters params = map.getParams();
8688
String prefix = params.getAttributePrefix();
8789

88-
// Restore column names for filtering
90+
CyNetwork network = cyNetworkManager.getNetwork(map.getNetworkID());
91+
92+
// Set column names for filtering
8993
params.addPValueColumnName(prefix + "pvalue_dataset1");
9094
params.addQValueColumnName(prefix + "fdr_qvalue_dataset1");
9195
params.addSimilarityCutoffColumnName(prefix + "similarity_coefficient");
@@ -94,8 +98,7 @@ private void migrate() {
9498
params.addQValueColumnName(prefix + "fdr_qvalue_dataset2");
9599
}
96100

97-
// Restore node SUIDs
98-
CyNetwork network = cyNetworkManager.getNetwork(map.getNetworkID());
101+
// Set node SUIDs
99102
for(CyNode node : network.getNodeList()) {
100103
CyRow row = network.getRow(node);
101104
if(ds1 != null) {
@@ -112,10 +115,11 @@ private void migrate() {
112115
Integer gsSize = row.get(prefix + "gs_size_signature", Integer.class);
113116
if(gsSize != null && gsSize > 0)
114117
dsSig.addNodeSuid(node.getSUID());
118+
row.set(prefix + "gs_size_dataset1", gsSize); // the style expects the gs sizes to be in the same attribute
115119
}
116120
}
117121

118-
// Restore edge SUIDs
122+
// Set edge SUIDs
119123
for(CyEdge edge : network.getEdgeList()) {
120124
CyRow row = network.getRow(edge);
121125
Integer emSet = row.get(prefix + "ENRICHMENT_SET", Integer.class);
@@ -128,13 +132,39 @@ else if(emSet == 4)
128132
dsSig.addEdgeSuid(edge.getSUID());
129133
}
130134
}
135+
136+
// Set the "dataset" column
137+
CyTable edgeTable = network.getDefaultEdgeTable();
138+
EMStyleBuilder.Columns.EDGE_DATASET.createColumn(edgeTable, prefix, null);
139+
140+
for(CyEdge edge : network.getEdgeList()) {
141+
CyRow row = network.getRow(edge);
142+
Integer emSet = row.get(prefix + "ENRICHMENT_SET", Integer.class);
143+
if(emSet != null) {
144+
String datasetName = null;
145+
if(emSet == 0)
146+
datasetName = EMStyleBuilder.Columns.EDGE_DATASET_VALUE_COMPOUND;
147+
else if(emSet == 1)
148+
datasetName = LegacySupport.DATASET1;
149+
else if(emSet == 2)
150+
datasetName = LegacySupport.DATASET2;
151+
else if(emSet == 4)
152+
datasetName = LegacySupport.DATASET1; // In EM2 all PA edges are added to dataset 1
153+
154+
EMStyleBuilder.Columns.EDGE_DATASET.set(row, prefix, datasetName);
155+
}
156+
}
131157
}
132158
}
133159
}
134160

135161

162+
163+
/**
164+
* This code is copy-pasted from EM2 with some slight modifications.
165+
*/
136166
@SuppressWarnings("unchecked")
137-
private void createModelFromSessionFiles(CySession session) {
167+
private void createModelFromFilesInSession(CySession session) {
138168
Map<Long, EnrichmentMapParameters> paramsMap = new HashMap<>();
139169
Map<Long, EnrichmentMap> enrichmentMapMap = new HashMap<>();
140170

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/style/ColumnDescriptor.java

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.baderlab.csplugins.enrichmentmap.style;
22

3+
import org.baderlab.csplugins.enrichmentmap.model.AbstractDataSet;
4+
import org.baderlab.csplugins.enrichmentmap.model.LegacySupport;
35
import org.cytoscape.model.CyRow;
46
import org.cytoscape.model.CyTable;
57

@@ -17,13 +19,22 @@ public String getBaseName() {
1719
return name;
1820
}
1921

20-
public String with(String prefix, String suffix) {
22+
public String with(String prefix, AbstractDataSet ds) {
2123
StringBuilder sb = new StringBuilder();
2224
if(prefix != null)
2325
sb.append(prefix);
2426
sb.append(name);
25-
if(suffix != null)
26-
sb.append(" (").append(suffix).append(")");
27+
if(ds != null) {
28+
String suffix = " (" + ds.getName() + ")";
29+
if(ds.getMap().isLegacy()) {
30+
if(LegacySupport.DATASET1.equals(ds.getName())) {
31+
suffix = "_dataset1";
32+
} else if(LegacySupport.DATASET2.equals(ds.getName())) {
33+
suffix = "_dataset2";
34+
}
35+
}
36+
sb.append(suffix);
37+
}
2738
return sb.toString();
2839
}
2940

@@ -32,8 +43,8 @@ public Class<?> getType() {
3243
return type;
3344
}
3445

35-
public T get(CyRow row, String prefix, String suffix) {
36-
return row.get(with(prefix,suffix), type);
46+
public T get(CyRow row, String prefix, AbstractDataSet ds) {
47+
return row.get(with(prefix,ds), type);
3748
}
3849

3950
public T get(CyRow row, String prefix) {
@@ -44,8 +55,8 @@ public T get(CyRow row) {
4455
return row.get(name, type);
4556
}
4657

47-
public void set(CyRow row, String prefix, String suffix, T value) {
48-
row.set(with(prefix,suffix), value);
58+
public void set(CyRow row, String prefix, AbstractDataSet ds, T value) {
59+
row.set(with(prefix,ds), value);
4960
}
5061

5162
public void set(CyRow row, String prefix, T value) {
@@ -56,17 +67,17 @@ public void set(CyRow row, T value) {
5667
row.set(name, value);
5768
}
5869

59-
public void createColumn(CyTable table, String prefix, String suffix) {
60-
table.createColumn(with(prefix,suffix), type, true);
70+
public void createColumn(CyTable table, String prefix,AbstractDataSet ds) {
71+
table.createColumn(with(prefix,ds), type, true);
6172
}
6273

6374
public void createColumn(CyTable table) {
6475
table.createColumn(name, type, true);
6576
}
6677

67-
public void createColumnIfAbsent(CyTable table, String prefix, String suffix) {
68-
if(table.getColumn(with(prefix,suffix)) == null)
69-
createColumn(table, prefix, suffix);
78+
public void createColumnIfAbsent(CyTable table, String prefix, AbstractDataSet ds) {
79+
if(table.getColumn(with(prefix,ds)) == null)
80+
createColumn(table, prefix, ds);
7081
}
7182

7283
public void createColumnIfAbsent(CyTable table) {

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/style/ColumnListDescriptor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import org.cytoscape.model.CyRow;
66
import org.cytoscape.model.CyTable;
77

8+
/**
9+
* MKTODO Replace the "String suffix" parameters with "AbstractDataSet" like in ColumnDescriptor.
10+
*/
811
public class ColumnListDescriptor<T> {
912

1013
private final String name;

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/style/EMStyleBuilder.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,7 @@ private void setNodeColors(VisualStyle vs, EMStyleOptions options) {
491491

492492
// Continuous Mapping - set node colour based on the sign of the ES score of the dataset
493493
ContinuousMapping<Double, Paint> cm = (ContinuousMapping<Double, Paint>) cmFactory
494-
.createVisualMappingFunction(Columns.NODE_COLOURING.with(prefix, ds.getName()), Double.class,
495-
BasicVisualLexicon.NODE_FILL_COLOR);
494+
.createVisualMappingFunction(Columns.NODE_COLOURING.with(prefix, ds), Double.class, BasicVisualLexicon.NODE_FILL_COLOR);
496495

497496
// Silence events fired by this mapping to prevent unnecessary style and view updates
498497
eventHelper.silenceEventSource(cm);
@@ -570,6 +569,10 @@ private void setNodeSize(VisualStyle vs, EMStyleOptions options, ChartType chart
570569
if (chartType == null || chartType == ChartType.RADIAL_HEAT_MAP) {
571570
String prefix = options.getAttributePrefix();
572571
String columnName = Columns.NODE_GS_SIZE.with(prefix, null);
572+
if(options.getEnrichmentMap().isLegacy()) {
573+
columnName += "_dataset1";
574+
}
575+
573576
int val0 = 10;
574577
int val1 = 474;
575578

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

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ private Map<String, CyNode> createNodes(CyNetwork network) {
124124

125125
// if result is null it will fail both instanceof checks
126126
if(result instanceof GSEAResult)
127-
setGSEAResultNodeAttributes(row, ds.getName(), (GSEAResult) result);
127+
setGSEAResultNodeAttributes(row, ds, (GSEAResult) result);
128128
else if(result instanceof GenericResult)
129-
setGenericResultNodeAttributes(row, ds.getName(), (GenericResult) result);
129+
setGenericResultNodeAttributes(row, ds, (GenericResult) result);
130130
}
131131
}
132132

@@ -188,17 +188,17 @@ private CyTable createNodeColumns(CyNetwork network) {
188188

189189
EMCreationParameters params = map.getParams();
190190

191-
for (String datasetName : map.getDataSetNames()) {
192-
Columns.NODE_PVALUE.createColumn(table, prefix, datasetName);
193-
Columns.NODE_FDR_QVALUE.createColumn(table, prefix, datasetName);
194-
Columns.NODE_FWER_QVALUE.createColumn(table, prefix, datasetName);
191+
for (EMDataSet dataset : map.getDataSetList()) {
192+
Columns.NODE_PVALUE.createColumn(table, prefix, dataset);
193+
Columns.NODE_FDR_QVALUE.createColumn(table, prefix, dataset);
194+
Columns.NODE_FWER_QVALUE.createColumn(table, prefix, dataset);
195195
// MKTODO only create these if method is GSEA?
196-
Columns.NODE_ES.createColumn(table, prefix, datasetName);
197-
Columns.NODE_NES.createColumn(table, prefix, datasetName);
198-
Columns.NODE_COLOURING.createColumn(table, prefix, datasetName);
196+
Columns.NODE_ES.createColumn(table, prefix, dataset);
197+
Columns.NODE_NES.createColumn(table, prefix, dataset);
198+
Columns.NODE_COLOURING.createColumn(table, prefix, dataset);
199199

200-
params.addPValueColumnName(Columns.NODE_PVALUE.with(prefix, datasetName));
201-
params.addQValueColumnName(Columns.NODE_FDR_QVALUE.with(prefix, datasetName));
200+
params.addPValueColumnName(Columns.NODE_PVALUE.with(prefix, dataset));
201+
params.addQValueColumnName(Columns.NODE_FDR_QVALUE.with(prefix, dataset));
202202
}
203203

204204
return table;
@@ -216,23 +216,23 @@ private CyTable createEdgeColumns(CyNetwork network) {
216216
return table;
217217
}
218218

219-
private void setGenericResultNodeAttributes(CyRow row, String datasetName, GenericResult result) {
220-
Columns.NODE_PVALUE.set(row, prefix, datasetName, result.getPvalue());
221-
Columns.NODE_FDR_QVALUE.set(row, prefix, datasetName, result.getFdrqvalue());
222-
Columns.NODE_NES.set(row, prefix, datasetName, result.getNES());
223-
Columns.NODE_COLOURING.set(row, prefix, datasetName, getColorScore(result));
219+
private void setGenericResultNodeAttributes(CyRow row, EMDataSet dataset, GenericResult result) {
220+
Columns.NODE_PVALUE.set(row, prefix, dataset, result.getPvalue());
221+
Columns.NODE_FDR_QVALUE.set(row, prefix, dataset, result.getFdrqvalue());
222+
Columns.NODE_NES.set(row, prefix, dataset, result.getNES());
223+
Columns.NODE_COLOURING.set(row, prefix, dataset, getColorScore(result));
224224
}
225225

226-
private void setGSEAResultNodeAttributes(CyRow row, String datasetName, GSEAResult result) {
227-
Columns.NODE_PVALUE.set(row, prefix, datasetName, result.getPvalue());
228-
Columns.NODE_FDR_QVALUE.set(row, prefix, datasetName, result.getFdrqvalue());
229-
Columns.NODE_FWER_QVALUE.set(row, prefix, datasetName, result.getFwerqvalue());
230-
Columns.NODE_ES.set(row, prefix, datasetName, result.getES());
231-
Columns.NODE_NES.set(row, prefix, datasetName, result.getNES());
232-
Columns.NODE_COLOURING.set(row, prefix, datasetName, getColorScore(result));
226+
private void setGSEAResultNodeAttributes(CyRow row, EMDataSet dataset, GSEAResult result) {
227+
Columns.NODE_PVALUE.set(row, prefix, dataset, result.getPvalue());
228+
Columns.NODE_FDR_QVALUE.set(row, prefix, dataset, result.getFdrqvalue());
229+
Columns.NODE_FWER_QVALUE.set(row, prefix, dataset, result.getFwerqvalue());
230+
Columns.NODE_ES.set(row, prefix, dataset, result.getES());
231+
Columns.NODE_NES.set(row, prefix, dataset, result.getNES());
232+
Columns.NODE_COLOURING.set(row, prefix, dataset, getColorScore(result));
233233

234234
EMCreationParameters params = map.getParams();
235-
params.addPValueColumnName(Columns.NODE_PVALUE.with(prefix, datasetName));
235+
params.addPValueColumnName(Columns.NODE_PVALUE.with(prefix, dataset));
236236
}
237237

238238
private static double getColorScore(EnrichmentResult result) {

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/view/util/ChartUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static List<CyColumnIdentifier> getSortedColumnIdentifiers(String attribu
5454
CyColumnIdentifierFactory columnIdFactory) {
5555
List<CyColumnIdentifier> columns = dataSets
5656
.stream()
57-
.map(ds -> columnDescriptor.with(attributePrefix, ds.getName())) // column name
57+
.map(ds -> columnDescriptor.with(attributePrefix, ds)) // column name
5858
.map(columnIdFactory::createColumnIdentifier) // column id
5959
.collect(Collectors.toList());
6060

0 commit comments

Comments
 (0)