Skip to content

Commit 30b80e7

Browse files
committed
Use column namespaces for associated network columns.
1 parent 13f7471 commit 30b80e7

File tree

7 files changed

+92
-72
lines changed

7 files changed

+92
-72
lines changed

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

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

33
import org.baderlab.csplugins.enrichmentmap.style.ColumnDescriptor;
4+
import org.baderlab.csplugins.enrichmentmap.style.EMStyleBuilder;
45

56
public interface Columns {
67

@@ -13,4 +14,9 @@ public interface Columns {
1314
// NODE
1415
ColumnDescriptor<String> STR_GENE_NAME = new ColumnDescriptor<>("display name", String.class);
1516
ColumnDescriptor<String> STR_QUERY_TERM = new ColumnDescriptor<>("query term", String.class);
17+
18+
// Hidden network attributes in associated networks
19+
// Hard code the namespace prefix because when we go from the associated network back to the EM network we don't know the EM network's prefix yet
20+
ColumnDescriptor<String> EM_ASSOCIATED_APP = new ColumnDescriptor<>(EMStyleBuilder.Columns.NAMESPACE_PREFIX + "Associated_App", String.class);
21+
ColumnDescriptor<Long> EM_NETWORK_SUID = new ColumnDescriptor<>(EMStyleBuilder.Columns.NAMESPACE_PREFIX + "Network.SUID", Long.class);
1622
}

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@
4343

4444
package org.baderlab.csplugins.enrichmentmap.model;
4545

46-
import static org.baderlab.csplugins.enrichmentmap.util.NetworkUtil.EM_ASSOCIATED_APP_COLUMN;
47-
import static org.baderlab.csplugins.enrichmentmap.util.NetworkUtil.EM_NETWORK_SUID_COLUMN;
48-
4946
import java.beans.PropertyChangeListener;
5047
import java.beans.PropertyChangeSupport;
5148
import java.util.HashMap;
@@ -122,16 +119,12 @@ public void addAssociatedAppAttributes(CyNetwork network, EnrichmentMap map, Ass
122119
// Add EM Network SUID to associated network's table.
123120
CyTable table = network.getTable(CyNetwork.class, CyNetwork.HIDDEN_ATTRS);
124121

125-
if (table.getColumn(EM_NETWORK_SUID_COLUMN) == null)
126-
table.createColumn(EM_NETWORK_SUID_COLUMN, Long.class, true);
127-
128-
table.getRow(network.getSUID()).set(EM_NETWORK_SUID_COLUMN, map.getNetworkID());
122+
Columns.EM_NETWORK_SUID.createColumnIfAbsent(table);
123+
Columns.EM_NETWORK_SUID.set(table.getRow(network.getSUID()), map.getNetworkID());
129124

130125
// Add App name to associated network's hidden table, to make it easier and more consistent later
131-
if (table.getColumn(EM_ASSOCIATED_APP_COLUMN) == null)
132-
table.createColumn(EM_ASSOCIATED_APP_COLUMN, String.class, true);
133-
134-
table.getRow(network.getSUID()).set(EM_ASSOCIATED_APP_COLUMN, app.name());
126+
Columns.EM_ASSOCIATED_APP.createColumnIfAbsent(table);
127+
Columns.EM_ASSOCIATED_APP.set(table.getRow(network.getSUID()), app.name());
135128

136129
// Update our internal map and fire an event if it changed
137130
Map<Long, EnrichmentMap> oldValue = getAssociatedEnrichmentMaps();

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ public String getBaseName() {
1717
return name;
1818
}
1919

20+
public String with(String prefix) {
21+
return with(prefix, null);
22+
}
23+
2024
public String with(String prefix, AbstractDataSet ds) {
2125
StringBuilder sb = new StringBuilder();
2226
if(prefix != null)
@@ -40,12 +44,20 @@ public String with(String prefix, AbstractDataSet ds) {
4044

4145
public abstract void createColumn(CyTable table);
4246

47+
public void createColumn(CyTable table, String prefix) {
48+
createColumn(table, prefix, null);
49+
}
50+
4351

4452
public void createColumnIfAbsent(CyTable table, String prefix, AbstractDataSet ds) {
4553
if(table.getColumn(with(prefix,ds)) == null)
4654
createColumn(table, prefix, ds);
4755
}
4856

57+
public void createColumnIfAbsent(CyTable table, String prefix) {
58+
createColumnIfAbsent(table, prefix);
59+
}
60+
4961
public void createColumnIfAbsent(CyTable table) {
5062
if(table.getColumn(name) == null)
5163
createColumn(table);
@@ -55,6 +67,14 @@ public boolean hasColumn(CyTable table) {
5567
return table.getColumn(name) != null;
5668
}
5769

70+
public boolean hasColumn(CyTable table, String prefix) {
71+
return hasColumn(table, prefix, null);
72+
}
73+
74+
public boolean hasColumn(CyTable table, String prefix, AbstractDataSet ds) {
75+
return table.getColumn(with(prefix,ds)) != null;
76+
}
77+
5878
/**
5979
* Returns the name.
6080
*/

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@ private void createDataSetColumn() {
8888
CyNetwork network = networkManager.getNetwork(map.getNetworkID());
8989
CyTable nodeTable = network.getDefaultNodeTable();
9090

91-
if (!Columns.DATASET_CHART.hasColumn(nodeTable)) {
92-
Columns.DATASET_CHART.createColumn(nodeTable);
91+
String prefix = map.getParams().getAttributePrefix();
92+
93+
if (!Columns.DATASET_CHART.hasColumn(nodeTable, prefix)) {
94+
Columns.DATASET_CHART.createColumn(nodeTable, prefix);
9395

9496
Map<Long, int[]> columnData = new HashMap<>();
9597
List<EMDataSet> dataSets = map.getDataSetList();
@@ -105,9 +107,9 @@ private void createDataSetColumn() {
105107
columnData.get(suid)[i] = 1;
106108
}
107109

108-
columnData.forEach((suid, data) -> {
109-
Columns.DATASET_CHART.set(nodeTable.getRow(suid), Ints.asList(data));
110-
});
110+
columnData.forEach((suid, data) ->
111+
Columns.DATASET_CHART.set(nodeTable.getRow(suid), prefix, Ints.asList(data))
112+
);
111113
}
112114
}
113115

@@ -165,18 +167,20 @@ public CyCustomGraphics2<?> createChart() {
165167
if (!dataSets.isEmpty()) {
166168
ChartType type = chartOptions.getType();
167169
Map<String, Object> props = new HashMap<>(type.getProperties());
170+
171+
String prefix = options.getAttributePrefix();
168172
AbstractColumnDescriptor columnDescriptor = data.getColumnDescriptor();
169173

170174
if (data == ChartData.DATA_SET) {
171-
List<CyColumnIdentifier> columns = Arrays.asList(columnIdFactory.createColumnIdentifier(columnDescriptor.getBaseName()));
175+
List<CyColumnIdentifier> columns = Arrays.asList(columnIdFactory.createColumnIdentifier(columnDescriptor.with(prefix)));
172176
List<Color> colors = options.getEnrichmentMap().getDataSetColors();
173177
props.put("cy_dataColumns", columns);
174178
props.put("cy_colors", colors);
175179
props.put("cy_showItemLabels", chartOptions.isShowLabels());
176180
props.put("cy_rotation", "CLOCKWISE");
177181

178182
} else {
179-
List<CyColumnIdentifier> columns = ChartUtil.getSortedColumnIdentifiers(options.getAttributePrefix(),
183+
List<CyColumnIdentifier> columns = ChartUtil.getSortedColumnIdentifiers(prefix,
180184
dataSets, columnDescriptor, columnIdFactory);
181185

182186
List<Color> colors = ChartUtil.getChartColors(chartOptions);

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

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -102,55 +102,60 @@ private void updateExpressionDataColumn() {
102102
CyNetwork network = options.getNetworkView().getModel();
103103
CyTable nodeTable = network.getDefaultNodeTable();
104104

105-
if (!Columns.EXPRESSION_DATA_CHART.hasColumn(nodeTable)) {
105+
String prefix = options.getEnrichmentMap().getParams().getAttributePrefix();
106+
107+
if (!Columns.EXPRESSION_DATA_CHART.hasColumn(nodeTable, prefix)) {
106108
try {
107-
Columns.EXPRESSION_DATA_CHART.createColumn(nodeTable);
109+
Columns.EXPRESSION_DATA_CHART.createColumn(nodeTable, prefix);
108110
} catch (Exception e) {
109-
logger.error("Cannot create column " + Columns.EXPRESSION_DATA_CHART.getBaseName(), e);
111+
logger.error("Cannot create column " + Columns.EXPRESSION_DATA_CHART.with(prefix), e);
110112
}
111-
}
112113

113-
Map<Long, double[]> columnData = new HashMap<>();
114-
EnrichmentMap map = options.getEnrichmentMap();
115-
ExpressionData exp = options.getExpressionData();
116114

117-
int n = exp.getSize();
118-
119-
for (CyNode node : network.getNodeList()) {
120-
double[] data = new double[n];
121-
columnData.put(node.getSUID(), data);
122-
123-
String name = NetworkUtil.getGeneName(network, node);
124-
125-
if (name == null)
126-
continue;
127-
128-
String queryTerm = NetworkUtil.getQueryTerm(network, name);
129-
Integer id = map.getHashFromGene(queryTerm != null ? queryTerm : name);
130-
131-
if (id == null)
132-
continue;
115+
Map<Long, double[]> columnData = new HashMap<>();
116+
EnrichmentMap map = options.getEnrichmentMap();
117+
ExpressionData exp = options.getExpressionData();
133118

134-
for (int i = 0; i < n; i++) {
135-
double value = exp.getValue(id, i, options.getCompress());
136-
data[i] = value;
119+
int n = exp.getSize();
120+
121+
for (CyNode node : network.getNodeList()) {
122+
double[] data = new double[n];
123+
columnData.put(node.getSUID(), data);
124+
125+
String name = NetworkUtil.getGeneName(network, node);
126+
127+
if (name == null)
128+
continue;
129+
130+
String queryTerm = NetworkUtil.getQueryTerm(network, name);
131+
Integer id = map.getHashFromGene(queryTerm != null ? queryTerm : name);
132+
133+
if (id == null)
134+
continue;
135+
136+
for (int i = 0; i < n; i++) {
137+
double value = exp.getValue(id, i, options.getCompress());
138+
data[i] = value;
139+
}
137140
}
141+
142+
columnData.forEach((suid, data) ->
143+
Columns.EXPRESSION_DATA_CHART.set(nodeTable.getRow(suid), prefix, Doubles.asList(data))
144+
);
138145
}
139-
140-
columnData.forEach((suid, data) -> {
141-
Columns.EXPRESSION_DATA_CHART.set(nodeTable.getRow(suid), Doubles.asList(data));
142-
});
143146
}
144147

145148
private void createDataSetColumn() {
146149
CyNetwork network = options.getNetworkView().getModel();
147150
CyTable nodeTable = network.getDefaultNodeTable();
148151

149-
if (!Columns.DATASET_CHART.hasColumn(nodeTable)) {
152+
String prefix = options.getEnrichmentMap().getParams().getAttributePrefix();
153+
154+
if (!Columns.DATASET_CHART.hasColumn(nodeTable, prefix)) {
150155
try {
151-
Columns.DATASET_CHART.createColumn(nodeTable);
156+
Columns.DATASET_CHART.createColumn(nodeTable, prefix);
152157
} catch (Exception e) {
153-
logger.error("Cannot create column " + Columns.DATASET_CHART.getBaseName(), e);
158+
logger.error("Cannot create column " + Columns.DATASET_CHART.with(prefix), e);
154159
}
155160

156161
Map<Long, int[]> columnData = new HashMap<>();
@@ -187,9 +192,9 @@ private void createDataSetColumn() {
187192
}
188193
}
189194

190-
columnData.forEach((suid, data) -> {
191-
Columns.DATASET_CHART.set(nodeTable.getRow(suid), Ints.asList(data));
192-
});
195+
columnData.forEach((suid, data) ->
196+
Columns.DATASET_CHART.set(nodeTable.getRow(suid), prefix, Ints.asList(data))
197+
);
193198
}
194199
}
195200

@@ -211,17 +216,19 @@ private CyCustomGraphics2<?> createChart() {
211216

212217
if (type != null && !dataSets.isEmpty()) {
213218
Map<String, Object> props = new HashMap<>(type.getProperties());
219+
220+
String prefix = options.getEnrichmentMap().getParams().getAttributePrefix();
214221
AbstractColumnDescriptor columnDescriptor = data.getColumnDescriptor();
215222

216223
if (data == ChartData.DATA_SET) {
217-
List<CyColumnIdentifier> columns = Arrays.asList(columnIdFactory.createColumnIdentifier(columnDescriptor.getBaseName()));
224+
List<CyColumnIdentifier> columns = Arrays.asList(columnIdFactory.createColumnIdentifier(columnDescriptor.with(prefix)));
218225
List<Color> colors = options.getEnrichmentMap().getDataSetColors();
219226

220227
props.put("cy_dataColumns", columns);
221228
props.put("cy_colors", colors);
222229
props.put("cy_showItemLabels", chartOptions.isShowLabels());
223230
} else if (data == ChartData.EXPRESSION_DATA) {
224-
List<CyColumnIdentifier> columns = Arrays.asList(columnIdFactory.createColumnIdentifier(columnDescriptor.getBaseName()));
231+
List<CyColumnIdentifier> columns = Arrays.asList(columnIdFactory.createColumnIdentifier(columnDescriptor.with(prefix)));
225232
List<Double> range = null;
226233
List<Color> colors = null;
227234

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/util/NetworkUtil.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.function.Function;
77

88
import org.baderlab.csplugins.enrichmentmap.model.AssociatedApp;
9+
import org.baderlab.csplugins.enrichmentmap.model.Columns;
910
import org.cytoscape.model.CyEdge;
1011
import org.cytoscape.model.CyIdentifiable;
1112
import org.cytoscape.model.CyNetwork;
@@ -17,9 +18,6 @@
1718

1819
public class NetworkUtil {
1920

20-
public static final String EM_NETWORK_SUID_COLUMN = "EM_Network.SUID";
21-
public static final String EM_ASSOCIATED_APP_COLUMN = "EM_Associated_App";
22-
2321
private NetworkUtil() { }
2422

2523
public static String getName(final CyNetwork network) {
@@ -96,10 +94,10 @@ public static List<Long> keys(Collection<? extends CyIdentifiable> nodesOrEdges)
9694
public static AssociatedApp getAssociatedApp(CyNetwork network) {
9795
CyTable table = network.getTable(CyNetwork.class, CyNetwork.HIDDEN_ATTRS);
9896

99-
if (table.getColumn(EM_ASSOCIATED_APP_COLUMN) == null)
97+
if(!Columns.EM_ASSOCIATED_APP.hasColumn(table))
10098
return null;
10199

102-
String app = network.getRow(network, CyNetwork.HIDDEN_ATTRS).get(EM_ASSOCIATED_APP_COLUMN, String.class);
100+
String app = Columns.EM_ASSOCIATED_APP.get(network.getRow(network, CyNetwork.HIDDEN_ATTRS));
103101

104102
if (AssociatedApp.GENEMANIA.name().equalsIgnoreCase(app))
105103
return AssociatedApp.GENEMANIA;
@@ -111,9 +109,7 @@ public static AssociatedApp getAssociatedApp(CyNetwork network) {
111109

112110
public static boolean isAssociatedNetwork(CyNetwork network) {
113111
CyTable table = network.getTable(CyNetwork.class, CyNetwork.HIDDEN_ATTRS);
114-
115-
return table.getColumn(EM_NETWORK_SUID_COLUMN) != null
116-
&& network.getRow(network, CyNetwork.HIDDEN_ATTRS).get(EM_NETWORK_SUID_COLUMN, Long.class) != null;
112+
return Columns.EM_NETWORK_SUID.hasColumn(table) && Columns.EM_NETWORK_SUID.get(network.getRow(network, CyNetwork.HIDDEN_ATTRS)) != null;
117113
}
118114

119115
/**

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ private void runGeneMANIA() {
496496
if (commands == null || !commands.contains(GENEMANIA_SEARCH_COMMAND)) {
497497
if (JOptionPane.showConfirmDialog(
498498
SwingUtilities.getWindowAncestor(getContentPanel()),
499-
"This action requires a version of the GeneMANIA app that is not installed?\n" +
499+
"This action requires a version of the GeneMANIA app that is not installed.\n" +
500500
"Would you like to install or update the GeneMANIA app now?",
501501
"Cannot Find GeneMANIA App",
502502
JOptionPane.YES_NO_OPTION
@@ -591,7 +591,7 @@ private void runString() {
591591
if (commands == null || !commands.contains(STRING_SPECIES_COMMAND)) {
592592
if (JOptionPane.showConfirmDialog(
593593
SwingUtilities.getWindowAncestor(getContentPanel()),
594-
"This action requires a version of the STRING app that is not installed?\n" +
594+
"This action requires a version of the STRING app that is not installed.\n" +
595595
"Would you like to install or update the STRING app now?",
596596
"Cannot Find STRING App",
597597
JOptionPane.YES_NO_OPTION
@@ -666,12 +666,6 @@ private void onStringQueryFinished(Long netId, EnrichmentMap map) {
666666
// Update the model
667667
map.addAssociatedNetworkID(net.getSUID());
668668
emManager.addAssociatedAppAttributes(net, map, AssociatedApp.STRING);
669-
// TODO
670-
// // Modify GeneMANIA's style
671-
// Collection<CyNetworkView> netViewList = netViewManager.getNetworkViews(strNet);
672-
//
673-
// for (CyNetworkView netView : netViewList)
674-
// updateGeneManiaStyle(netView);
675669
}
676670
}
677671

0 commit comments

Comments
 (0)