Search in sources :

Example 11 with VirtualColumnInfo

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);
            }
        }
    }
}
Also used : CyTable(org.cytoscape.model.CyTable) CyColumn(org.cytoscape.model.CyColumn) VirtualColumnInfo(org.cytoscape.model.VirtualColumnInfo) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 12 with VirtualColumnInfo

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);
            }
        }
    }
}
Also used : CyTable(org.cytoscape.model.CyTable) CyColumn(org.cytoscape.model.CyColumn) VirtualColumnInfo(org.cytoscape.model.VirtualColumnInfo) CyRow(org.cytoscape.model.CyRow)

Example 13 with VirtualColumnInfo

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;
}
Also used : CyTable(org.cytoscape.model.CyTable) CyTables(org.cytoscape.io.internal.util.cytables.model.CyTables) CyColumn(org.cytoscape.model.CyColumn) CyTableMetadata(org.cytoscape.model.CyTableMetadata) VirtualColumnInfo(org.cytoscape.model.VirtualColumnInfo) VirtualColumn(org.cytoscape.io.internal.util.cytables.model.VirtualColumn) VirtualColumns(org.cytoscape.io.internal.util.cytables.model.VirtualColumns)

Aggregations

VirtualColumnInfo (org.cytoscape.model.VirtualColumnInfo)13 CyColumn (org.cytoscape.model.CyColumn)11 CyTable (org.cytoscape.model.CyTable)5 CyRow (org.cytoscape.model.CyRow)4 ArrayList (java.util.ArrayList)2 List (java.util.List)2 CyEdge (org.cytoscape.model.CyEdge)2 CyIdentifiable (org.cytoscape.model.CyIdentifiable)2 CyNetwork (org.cytoscape.model.CyNetwork)2 CyNode (org.cytoscape.model.CyNode)2 ColumnCreatedEvent (org.cytoscape.model.events.ColumnCreatedEvent)2 RowSetRecord (org.cytoscape.model.events.RowSetRecord)2 CyRootNetwork (org.cytoscape.model.subnetwork.CyRootNetwork)2 CyApplicationManager (org.cytoscape.application.CyApplicationManager)1 ParseState (org.cytoscape.io.internal.read.xgmml.ParseState)1 CyTables (org.cytoscape.io.internal.util.cytables.model.CyTables)1 VirtualColumn (org.cytoscape.io.internal.util.cytables.model.VirtualColumn)1 VirtualColumns (org.cytoscape.io.internal.util.cytables.model.VirtualColumns)1 ObjectType (org.cytoscape.io.internal.util.xgmml.ObjectType)1 CyTableMetadata (org.cytoscape.model.CyTableMetadata)1