Author: clopes
Date: 2012-06-27 09:31:05 -0700 (Wed, 27 Jun 2012)
New Revision: 29705
Modified:
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/AttributeValueUtil.java
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/write/xgmml/GenericXGMMLWriter.java
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CySubNetworkImpl.java
Log:
XGMML Import/Export: handling virtual columns.
CySubNetworkImpl now checks if shared column values are null, before setting
their initial values.
Modified:
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/AttributeValueUtil.java
===================================================================
---
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/AttributeValueUtil.java
2012-06-27 16:23:44 UTC (rev 29704)
+++
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/read/xgmml/handler/AttributeValueUtil.java
2012-06-27 16:31:05 UTC (rev 29705)
@@ -27,6 +27,7 @@
*/
package org.cytoscape.io.internal.read.xgmml.handler;
+import java.util.Collection;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -43,6 +44,7 @@
import org.cytoscape.model.CyRow;
import org.cytoscape.model.CyTable;
import org.cytoscape.model.CyIdentifiable;
+import org.cytoscape.model.VirtualColumnInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.Attributes;
@@ -192,9 +194,43 @@
curNet = manager.getRootNetwork();
}
- final CyRow row = curNet.getRow(curElement, tableName);
- final CyColumn column = row.getTable().getColumn(name);
+ CyRow row = curNet.getRow(curElement, tableName);
+ CyTable table = row.getTable();
+ CyColumn column = table.getColumn(name);
+ if (column != null) {
+ // Check if it's a virtual column
+ final VirtualColumnInfo info = column.getVirtualColumnInfo();
+
+ if (info.isVirtual()) {
+ final CyTable srcTable = info.getSourceTable();
+ final CyColumn srcColumn =
srcTable.getColumn(info.getSourceColumn());
+ final Class<?> jkColType =
table.getColumn(info.getTargetJoinKey()).getType();
+ final Object jkValue = row.get(info.getTargetJoinKey(),
jkColType);
+ final Collection<CyRow> srcRowList =
srcTable.getMatchingRows(info.getSourceJoinKey(), jkValue);
+ final CyRow srcRow;
+
+ if (srcRowList == null || srcRowList.isEmpty()) {
+ if
(info.getTargetJoinKey().equals(CyIdentifiable.SUID)) {
+ // Try to create the row
+ srcRow = srcTable.getRow(jkValue);
+ } else {
+ logger.error("Unable to import
virtual column \"" + name + "\": The source table \""
+ +
srcTable.getTitle() + "\" does not have any matching rows for join key \""
+ +
info.getSourceJoinKey() + "=" + jkValue + "\".");
+ return parseState;
+ }
+ } else {
+ srcRow = srcRowList.iterator().next();
+ }
+
+ // Use the source table instead
+ table = srcTable;
+ column = srcColumn;
+ row = srcRow;
+ }
+ }
+
Object value = null;
ObjectType objType = typeMap.getType(type);
Modified:
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/write/xgmml/GenericXGMMLWriter.java
===================================================================
---
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/write/xgmml/GenericXGMMLWriter.java
2012-06-27 16:23:44 UTC (rev 29704)
+++
core3/impl/trunk/io-impl/impl/src/main/java/org/cytoscape/io/internal/write/xgmml/GenericXGMMLWriter.java
2012-06-27 16:31:05 UTC (rev 29705)
@@ -502,7 +502,7 @@
// because they are also returned as NETWORK's descendants
if (root == BasicVisualLexicon.NETWORK &&
vp.getTargetDataType() != CyNetwork.class)
continue;
-
+ // TODO: not exactly the right thing to do here:
if (disabledVisualProperties.contains(vp))
continue;
@@ -673,7 +673,7 @@
// create an attribute and its type:
final CyColumn column = row.getTable().getColumn(attName);
- if (column == null || column.getVirtualColumnInfo().isVirtual())
+ if (column == null)
return;
final Class<?> attType = column.getType();
Modified:
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CySubNetworkImpl.java
===================================================================
---
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CySubNetworkImpl.java
2012-06-27 16:23:44 UTC (rev 29704)
+++
core3/impl/trunk/model-impl/impl/src/main/java/org/cytoscape/model/internal/CySubNetworkImpl.java
2012-06-27 16:31:05 UTC (rev 29705)
@@ -271,16 +271,20 @@
}
private void updateSharedNames(CyTable src, CyTable tgt) {
- for ( CyRow sr : src.getAllRows() ) {
- CyRow tr = tgt.getRow(
sr.get(CyIdentifiable.SUID,Long.class) );
- tr.set( CyRootNetwork.SHARED_NAME,
sr.get(CyNetwork.NAME,String.class) );
+ for (CyRow sr : src.getAllRows()) {
+ CyRow tr = tgt.getRow(sr.get(CyIdentifiable.SUID,
Long.class));
+
+ if (tr.get(CyRootNetwork.SHARED_NAME, String.class) ==
null)
+ tr.set(CyRootNetwork.SHARED_NAME,
sr.get(CyNetwork.NAME, String.class));
}
}
private void updateSharedInteractions(CyTable src, CyTable tgt) {
- for ( CyRow sr : src.getAllRows() ) {
- CyRow tr = tgt.getRow(
sr.get(CyIdentifiable.SUID,Long.class) );
- tr.set( CyRootNetwork.SHARED_INTERACTION,
sr.get(CyEdge.INTERACTION,String.class) );
+ for (CyRow sr : src.getAllRows()) {
+ CyRow tr = tgt.getRow(sr.get(CyIdentifiable.SUID,
Long.class));
+
+ if (tr.get(CyRootNetwork.SHARED_INTERACTION,
String.class) == null)
+ tr.set(CyRootNetwork.SHARED_INTERACTION,
sr.get(CyEdge.INTERACTION, String.class));
}
}
@Override
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.