Search in sources :

Example 26 with CyRootNetwork

use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.

the class GraphMLReader method run.

@Override
public void run(final TaskMonitor taskMonitor) throws Exception {
    this.taskMonitor = taskMonitor;
    try {
        final SAXParserFactory spf = SAXParserFactory.newInstance();
        spf.setNamespaceAware(true);
        final SAXParser sp = spf.newSAXParser();
        final XMLReader xmlReader = sp.getXMLReader();
        CyRootNetwork root = getRootNetwork();
        final CySubNetwork newNetwork;
        if (root != null) {
            newNetwork = root.addSubNetwork();
        } else {
            // Need to create new network with new root.
            newNetwork = (CySubNetwork) cyNetworkFactory.createNetwork();
            root = newNetwork.getRootNetwork();
        }
        parser = new GraphMLParser(taskMonitor, cyNetworkFactory, cyRootNetworkManager, root, newNetwork);
        xmlReader.setContentHandler(parser);
        final InputSource inputSource = new InputSource(inputStream);
        inputSource.setEncoding("UTF-8");
        xmlReader.parse(inputSource);
        createGroups(root, newNetwork);
    } finally {
        if (inputStream != null) {
            try {
                inputStream.close();
                inputStream = null;
            } catch (Exception e) {
                logger.warn("Cannot close GraphML input stream", e);
            }
        }
    }
}
Also used : InputSource(org.xml.sax.InputSource) SAXParser(javax.xml.parsers.SAXParser) XMLReader(org.xml.sax.XMLReader) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) SAXParserFactory(javax.xml.parsers.SAXParserFactory) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 27 with CyRootNetwork

use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.

the class GenericXGMMLReaderTest method assertCustomColumnsAreMutable.

private void assertCustomColumnsAreMutable(CyNetwork net) {
    // User or non-default columns should be immutable
    List<CyTable> tables = new ArrayList<CyTable>();
    tables.add(net.getTable(CyNetwork.class, LOCAL_ATTRS));
    tables.add(net.getTable(CyNetwork.class, HIDDEN_ATTRS));
    tables.add(net.getTable(CyNetwork.class, DEFAULT_ATTRS));
    tables.add(net.getTable(CyNode.class, LOCAL_ATTRS));
    tables.add(net.getTable(CyNode.class, HIDDEN_ATTRS));
    tables.add(net.getTable(CyNode.class, DEFAULT_ATTRS));
    tables.add(net.getTable(CyEdge.class, LOCAL_ATTRS));
    tables.add(net.getTable(CyEdge.class, HIDDEN_ATTRS));
    tables.add(net.getTable(CyEdge.class, DEFAULT_ATTRS));
    if (net instanceof CyRootNetwork) {
        tables.add(net.getTable(CyNetwork.class, SHARED_ATTRS));
        tables.add(net.getTable(CyNode.class, SHARED_ATTRS));
        tables.add(net.getTable(CyEdge.class, SHARED_ATTRS));
    }
    for (CyTable t : tables) {
        for (CyColumn c : t.getColumns()) {
            String name = c.getName();
            if (!name.equals(CyNetwork.SUID) && !name.equals(NAME) && !name.equals(CyNetwork.SELECTED) && !name.equals(CyEdge.INTERACTION) && !name.equals(CyRootNetwork.SHARED_NAME) && !name.equals(CyRootNetwork.SHARED_INTERACTION)) {
                assertFalse("Column " + c.getName() + " should NOT be immutable", c.isImmutable());
            }
        }
    }
}
Also used : CyTable(org.cytoscape.model.CyTable) ArrayList(java.util.ArrayList) CyColumn(org.cytoscape.model.CyColumn) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 28 with CyRootNetwork

use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.

the class GroupUtil method updateGroupNodeLocation.

private void updateGroupNodeLocation(final CyNetworkView view, final CyNode groupNode) {
    if (view == null)
        return;
    CyRootNetwork rootNetwork = ((CySubNetwork) view.getModel()).getRootNetwork();
    View<CyNode> nView = view.getNodeView(groupNode);
    double x = nView.getVisualProperty(BasicVisualLexicon.NODE_X_LOCATION);
    double y = nView.getVisualProperty(BasicVisualLexicon.NODE_Y_LOCATION);
    // Save it
    // TODO these attributes will not work with multiple views per network!
    CyRow hRow = rootNetwork.getRow(groupNode, CyNetwork.HIDDEN_ATTRS);
    createColumn(hRow.getTable(), X_LOCATION_ATTR, Double.class);
    createColumn(hRow.getTable(), Y_LOCATION_ATTR, Double.class);
    hRow.set(X_LOCATION_ATTR, new Double(x));
    hRow.set(Y_LOCATION_ATTR, new Double(y));
}
Also used : CyNode(org.cytoscape.model.CyNode) CyRow(org.cytoscape.model.CyRow) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 29 with CyRootNetwork

use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.

the class GroupUtil method getGroupNodeEdges.

public List<CyEdge> getGroupNodeEdges(final CyNetwork network) {
    CyRootNetwork rootNetwork = ((CySubNetwork) network).getRootNetwork();
    // Don't need to worry about this for collapsed groups
    List<CyNode> groupNodes = getExpandedGroups(network);
    List<CyEdge> groupNodeEdges = new ArrayList<>();
    for (CyNode groupNode : groupNodes) {
        groupNodeEdges.addAll(rootNetwork.getAdjacentEdgeList(groupNode, CyEdge.Type.ANY));
    }
    return groupNodeEdges;
}
Also used : ArrayList(java.util.ArrayList) CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 30 with CyRootNetwork

use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.

the class GenericXGMMLWriter method getRowFromNetOrRoot.

protected CyRow getRowFromNetOrRoot(final CyNetwork network, final CyIdentifiable entry, String namespace) {
    CyRow row = null;
    try {
        row = namespace == null ? network.getRow(entry) : network.getRow(entry, namespace);
    } catch (final IllegalArgumentException e) {
    // Ignore this exception
    } catch (final RuntimeException e) {
        logger.error("Cannot get \"" + namespace + "\" row for entry \"" + entry + "\" in network \"" + network + "\".", e);
    }
    if (row == null && network instanceof CySubNetwork) {
        // Doesn't exist in subnetwork? Try to get it from the root network.
        final CyRootNetwork root = ((CySubNetwork) network).getRootNetwork();
        row = namespace == null ? root.getRow(entry) : root.getRow(entry, namespace);
    }
    return row;
}
Also used : CyRow(org.cytoscape.model.CyRow) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Aggregations

CyRootNetwork (org.cytoscape.model.subnetwork.CyRootNetwork)83 CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)37 CyNetwork (org.cytoscape.model.CyNetwork)36 CyNode (org.cytoscape.model.CyNode)28 CyEdge (org.cytoscape.model.CyEdge)15 CyRow (org.cytoscape.model.CyRow)15 CyRootNetworkManager (org.cytoscape.model.subnetwork.CyRootNetworkManager)15 ArrayList (java.util.ArrayList)13 Test (org.junit.Test)13 CyTable (org.cytoscape.model.CyTable)11 CyNetworkView (org.cytoscape.view.model.CyNetworkView)11 CyGroup (org.cytoscape.group.CyGroup)7 HashSet (java.util.HashSet)6 Dimension (java.awt.Dimension)4 IOException (java.io.IOException)4 CyNetworkManager (org.cytoscape.model.CyNetworkManager)4 Image (java.awt.Image)3 BufferedImage (java.awt.image.BufferedImage)3 CyApplicationManager (org.cytoscape.application.CyApplicationManager)3 CyEventHelper (org.cytoscape.event.CyEventHelper)3