use of org.cytoscape.model.VirtualColumnInfo in project cytoscape-impl by cytoscape.
the class CloneNetworkTask method addColumns.
private void addColumns(final CyNetwork origNet, final CyNetwork newNet, final Class<? extends CyIdentifiable> tableType, final String namespace) {
final CyTable from = origNet.getTable(tableType, namespace);
final CyTable to = newNet.getTable(tableType, namespace);
final CyRootNetwork origRoot = rootNetMgr.getRootNetwork(origNet);
final CyRootNetwork newRoot = rootNetMgr.getRootNetwork(newNet);
final Map<String, CyTable> origRootTables = netTableMgr.getTables(origRoot, tableType);
for (final CyColumn col : from.getColumns()) {
final String name = col.getName();
if (to.getColumn(name) == null) {
final VirtualColumnInfo info = col.getVirtualColumnInfo();
if (info.isVirtual()) {
if (origRootTables.containsValue(info.getSourceTable())) {
// If the virtual column is from a root-network table, do NOT set this virtual column directly to
// the new table:
// Get the original column (not the virtual one!)
final CyColumn origCol = info.getSourceTable().getColumn(info.getSourceColumn());
// Copy the original column to the root-network's table first
String sourceNamespace = netTableMgr.getTableNamespace(info.getSourceTable());
final CyTable newRootTable = newRoot.getTable(tableType, sourceNamespace);
if (newRootTable.getColumn(origCol.getName()) == null)
copyColumn(origCol, newRootTable);
// Now we can add the new "root" column as a virtual one to the new network's table
to.addVirtualColumn(name, origCol.getName(), newRootTable, CyIdentifiable.SUID, col.isImmutable());
} else {
// Otherwise (e.g. virtual column from a global table) just add the virtual column directly
addVirtualColumn(col, to);
}
} else {
// Not a virtual column, so just copy it to the new network's table
copyColumn(col, to);
}
}
}
}
use of org.cytoscape.model.VirtualColumnInfo in project cytoscape-impl by cytoscape.
the class ClipboardImpl method copyRows.
private void copyRows(Map<CyRow, CyRow> rowMap) {
if (rowMap == null || rowMap.size() == 0)
return;
for (CyRow sourceRow : rowMap.keySet()) {
CyRow targetRow = rowMap.get(sourceRow);
CyTable destTable = targetRow.getTable();
CyTable sourceTable = sourceRow.getTable();
Map<String, Object> oldDataMap;
if (oldValueMap.containsKey(sourceRow))
oldDataMap = oldValueMap.get(sourceRow);
else
oldDataMap = sourceRow.getAllValues();
for (String colName : oldDataMap.keySet()) {
CyColumn column = destTable.getColumn(colName);
if (column == null) {
CyColumn sourceColumn = sourceTable.getColumn(colName);
if (sourceColumn.getType() == List.class) {
destTable.createListColumn(colName, sourceColumn.getListElementType(), sourceColumn.isImmutable());
} else {
destTable.createColumn(colName, sourceColumn.getType(), sourceColumn.isImmutable());
}
} else if (column.isPrimaryKey()) {
continue;
} else {
// Column already exists. We need to check for virtual columns that don't join
// on SUID (since that's the only thing we're changing). If they don't, we need to skip them.
VirtualColumnInfo virtualInfo = column.getVirtualColumnInfo();
if (virtualInfo.isVirtual() && !virtualInfo.getTargetJoinKey().equals(CyNetwork.SUID))
continue;
}
// want to copy it.
try {
targetRow.set(colName, oldDataMap.get(colName));
} catch (IllegalArgumentException e) {
// Log a warning
System.out.println("Set failed! " + e);
}
}
}
}
use of org.cytoscape.model.VirtualColumnInfo in project cytoscape-impl by cytoscape.
the class CyTablesXMLWriter method buildModel.
private CyTables buildModel() {
CyTables model = new CyTables();
VirtualColumns virtualColumns = new VirtualColumns();
model.setVirtualColumns(virtualColumns);
List<VirtualColumn> columns = virtualColumns.getVirtualColumn();
for (CyTableMetadata metadata : tables) {
CyTable table = metadata.getTable();
String targetTable = tableFileNamesBySUID.get(table.getSUID());
if (targetTable == null) {
continue;
}
for (CyColumn cyColumn : table.getColumns()) {
VirtualColumnInfo info = cyColumn.getVirtualColumnInfo();
if (!info.isVirtual()) {
continue;
}
String sourceTable = tableFileNamesBySUID.get(info.getSourceTable().getSUID());
if (sourceTable == null) {
// log this
continue;
}
VirtualColumn column = new VirtualColumn();
column.setName(cyColumn.getName());
column.setSourceColumn(info.getSourceColumn());
column.setSourceTable(sourceTable);
column.setSourceJoinKey(info.getSourceJoinKey());
column.setTargetTable(targetTable);
column.setTargetJoinKey(info.getTargetJoinKey());
columns.add(column);
}
}
return model;
}
Aggregations