Search in sources :

Example 41 with CyTable

use of org.cytoscape.model.CyTable in project cytoscape-impl by cytoscape.

the class TableBrowserToolBar method getAttributeArray.

private String[] getAttributeArray() {
    final CyTable attrs = browserTableModel.getDataTable();
    final Collection<CyColumn> columns = attrs.getColumns();
    final String[] attributeArray = new String[columns.size() - 1];
    int index = 0;
    for (final CyColumn column : columns) {
        if (!column.isPrimaryKey())
            attributeArray[index++] = column.getName();
    }
    Arrays.sort(attributeArray);
    return attributeArray;
}
Also used : CyTable(org.cytoscape.model.CyTable) CyColumn(org.cytoscape.model.CyColumn)

Example 42 with CyTable

use of org.cytoscape.model.CyTable in project cytoscape-impl by cytoscape.

the class TableBrowserToolBar method createNewAttribute.

private void createNewAttribute(final String type, boolean isShared) {
    try {
        final String[] existingAttrs = getAttributeArray();
        String newAttribName = null;
        do {
            newAttribName = JOptionPane.showInputDialog(this, "Column Name: ", "Create New " + type + " Column", JOptionPane.QUESTION_MESSAGE);
            if (newAttribName == null)
                return;
            newAttribName = newAttribName.trim();
            if (newAttribName.isEmpty()) {
                JOptionPane.showMessageDialog(null, "Column name must not be blank.", "Error", JOptionPane.ERROR_MESSAGE);
                newAttribName = null;
            } else if (Arrays.binarySearch(existingAttrs, newAttribName) >= 0) {
                JOptionPane.showMessageDialog(null, "Column " + newAttribName + " already exists.", "Error", JOptionPane.ERROR_MESSAGE);
                newAttribName = null;
            }
        } while (newAttribName == null);
        final CyTable attrs;
        if (isShared) {
            final CyNetwork network = serviceRegistrar.getService(CyApplicationManager.class).getCurrentNetwork();
            if (network instanceof CySubNetwork) {
                final CyRootNetwork rootNetwork = ((CySubNetwork) network).getRootNetwork();
                CyTable sharedTable = null;
                if (this.objType == CyNode.class)
                    sharedTable = rootNetwork.getSharedNodeTable();
                else if (this.objType == CyEdge.class)
                    sharedTable = rootNetwork.getSharedEdgeTable();
                else if (this.objType == CyNetwork.class)
                    sharedTable = rootNetwork.getSharedNetworkTable();
                else
                    throw new IllegalStateException("Object type is not valid.  This should not happen.");
                attrs = sharedTable;
            } else {
                throw new IllegalArgumentException("This is not a CySubNetwork and there is no shared table.");
            }
        } else {
            attrs = browserTableModel.getDataTable();
        }
        if (type.equals("String"))
            attrs.createColumn(newAttribName, String.class, false);
        else if (type.equals("Floating Point"))
            attrs.createColumn(newAttribName, Double.class, false);
        else if (type.equals("Integer"))
            attrs.createColumn(newAttribName, Integer.class, false);
        else if (type.equals("Long Integer"))
            attrs.createColumn(newAttribName, Long.class, false);
        else if (type.equals("Boolean"))
            attrs.createColumn(newAttribName, Boolean.class, false);
        else if (type.equals("String List"))
            attrs.createListColumn(newAttribName, String.class, false);
        else if (type.equals("Floating Point List"))
            attrs.createListColumn(newAttribName, Double.class, false);
        else if (type.equals("Integer List"))
            attrs.createListColumn(newAttribName, Integer.class, false);
        else if (type.equals("Long Integer List"))
            attrs.createListColumn(newAttribName, Long.class, false);
        else if (type.equals("Boolean List"))
            attrs.createListColumn(newAttribName, Boolean.class, false);
        else
            throw new IllegalArgumentException("unknown column type \"" + type + "\".");
    } catch (IllegalArgumentException e) {
        JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyEdge(org.cytoscape.model.CyEdge) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyTable(org.cytoscape.model.CyTable) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 43 with CyTable

use of org.cytoscape.model.CyTable in project cytoscape-impl by cytoscape.

the class NetworkLineParser method mapAttribute.

/**
 * Based on the attribute types, map the entry to Node or Edge tables.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
private <T extends CyIdentifiable> void mapAttribute(final T element, final String entry, final int index) {
    if (entry == null || entry.length() == 0)
        return;
    final AttributeDataType type = mapping.getDataTypes()[index];
    if (type.isList()) {
        final CyTable table = network.getRow(element).getTable();
        if (table.getColumn(mapping.getAttributeNames()[index]) == null)
            table.createListColumn(mapping.getAttributeNames()[index], type.getListType(), false);
        final String[] delimiters = mapping.getListDelimiters();
        String delimiter = delimiters != null && delimiters.length > index ? delimiters[index] : AbstractMappingParameters.DEF_LIST_DELIMITER;
        if (delimiter == null || delimiter.isEmpty())
            delimiter = AbstractMappingParameters.DEF_LIST_DELIMITER;
        Object value = parse(entry, type, delimiter);
        if (value instanceof List) {
            // In case of list, do not overwrite the attribute. Get the existing list, and add it to the list.
            List<Object> curList = network.getRow(element).get(mapping.getAttributeNames()[index], List.class);
            if (curList == null)
                curList = new ArrayList<>();
            curList.addAll((List) value);
            value = curList;
        }
        network.getRow(element).set(mapping.getAttributeNames()[index], value);
    } else {
        createColumn(element, mapping.getAttributeNames()[index], type.getType());
        final Object value = parse(entry, type, null);
        network.getRow(element).set(mapping.getAttributeNames()[index], value);
    }
}
Also used : CyTable(org.cytoscape.model.CyTable) AttributeDataType(org.cytoscape.tableimport.internal.util.AttributeDataType) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 44 with CyTable

use of org.cytoscape.model.CyTable in project cytoscape-impl by cytoscape.

the class OBOReader method mapHeader.

private void mapHeader() {
    final CyTable networkTable = this.ontologyDAG.getDefaultNetworkTable();
    for (String tag : header.keySet()) {
        if (networkTable.getColumn(tag) == null)
            networkTable.createColumn(tag, String.class, false);
        networkTable.getRow(ontologyDAG.getSUID()).set(tag, header.get(tag));
    }
    if (networkTable.getColumn(DAG_ATTR) == null)
        networkTable.createColumn(DAG_ATTR, Boolean.class, true);
    networkTable.getRow(ontologyDAG.getSUID()).set(DAG_ATTR, true);
    ontologyDAG.getRow(ontologyDAG).set(CyNetwork.NAME, dagName);
}
Also used : CyTable(org.cytoscape.model.CyTable)

Example 45 with CyTable

use of org.cytoscape.model.CyTable in project cytoscape-impl by cytoscape.

the class LoadTableReaderTask method loadAnnotation.

private void loadAnnotation(TaskMonitor tm) {
    tm.setProgress(0.0);
    TextTableReader reader = this.reader;
    AttributeMappingParameters readerAMP = (AttributeMappingParameters) reader.getMappingParameter();
    String primaryKey = readerAMP.getAttributeNames()[readerAMP.getKeyIndex()];
    tm.setProgress(0.1);
    final CyTableFactory tableFactory = serviceRegistrar.getService(CyTableFactory.class);
    final CyTable table = tableFactory.createTable("AttrTable " + inputName.substring(inputName.lastIndexOf('/') + 1) + " " + Integer.toString(numImports++), primaryKey, String.class, true, true);
    cyTables = new CyTable[] { table };
    tm.setProgress(0.3);
    try {
        this.reader.readTable(table);
    } catch (IOException e) {
        e.printStackTrace();
    }
    tm.setProgress(1.0);
}
Also used : CyTableFactory(org.cytoscape.model.CyTableFactory) CyTable(org.cytoscape.model.CyTable) IOException(java.io.IOException) TextTableReader(org.cytoscape.tableimport.internal.reader.TextTableReader) AttributeMappingParameters(org.cytoscape.tableimport.internal.reader.AttributeMappingParameters)

Aggregations

CyTable (org.cytoscape.model.CyTable)282 CyNetwork (org.cytoscape.model.CyNetwork)79 CyRow (org.cytoscape.model.CyRow)73 CyColumn (org.cytoscape.model.CyColumn)71 ArrayList (java.util.ArrayList)55 CyNode (org.cytoscape.model.CyNode)43 CyEdge (org.cytoscape.model.CyEdge)35 Test (org.junit.Test)29 List (java.util.List)26 HashMap (java.util.HashMap)24 CyApplicationManager (org.cytoscape.application.CyApplicationManager)19 HashSet (java.util.HashSet)18 CyIdentifiable (org.cytoscape.model.CyIdentifiable)14 CyNetworkView (org.cytoscape.view.model.CyNetworkView)14 CyNetworkTableManager (org.cytoscape.model.CyNetworkTableManager)13 RowSetRecord (org.cytoscape.model.events.RowSetRecord)11 CyRootNetwork (org.cytoscape.model.subnetwork.CyRootNetwork)11 CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)11 CyEventHelper (org.cytoscape.event.CyEventHelper)10 CyTableManager (org.cytoscape.model.CyTableManager)10