Search in sources :

Example 76 with CySubNetwork

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

the class SessionXGMMLNetworkWriterTest method testNetworkPointerFromSameRootNetwork.

@Test
public void testNetworkPointerFromSameRootNetwork() {
    // Create a subnetwork from the same root
    CySubNetwork subNet = rootNet.addSubNetwork();
    // To force all nested node graphs to be written as XLinks!
    setRegistered(subNet, true);
    // Set it as network pointer to 2 nodes
    CyNode n1 = net.getNodeList().get(0);
    CyNode n2 = net.getNodeList().get(1);
    n1.setNetworkPointer(subNet);
    n2.setNetworkPointer(subNet);
    write(rootNet);
    // Test
    assertEquals(2, evalNumber("count(/x:graph//x:node/x:att/x:graph)"));
    assertEquals("" + subNet.getSUID(), getElementId("//x:node[@id=" + n1.getSUID() + "]/x:att/x:graph"));
    assertEquals("" + subNet.getSUID(), getElementId("//x:node[@id=" + n2.getSUID() + "]/x:att/x:graph"));
}
Also used : CyNode(org.cytoscape.model.CyNode) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) Test(org.junit.Test)

Example 77 with CySubNetwork

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

the class SessionXGMMLNetworkWriterTest method testUnregisteredSubNetworkSavedIfSessionSavePolicy.

@Test
public void testUnregisteredSubNetworkSavedIfSessionSavePolicy() throws UnsupportedEncodingException {
    CySubNetwork sn = rootNet.addSubNetwork();
    // It doesn't matter
    setRegistered(sn, false);
    write(rootNet);
    assertEquals("0", evalString("/x:graph/x:att/x:graph[@id=" + sn.getSUID() + "]/@cy:registered"));
}
Also used : CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) Test(org.junit.Test)

Example 78 with CySubNetwork

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

the class GMLNetworkReaderTest method testReadGmlAttributes.

@Test
public void testReadGmlAttributes() throws Exception {
    final GMLNetworkReader reader = readGML("src/test/resources/testData/gml/example2.gml");
    final CyNetwork[] networks = reader.getNetworks();
    final CyNetworkView[] networkViews = new CyNetworkView[networks.length];
    int i = 0;
    for (CyNetwork net : networks) {
        networkViews[i] = reader.buildCyNetworkView(net);
        i++;
    }
    assertEquals(1, networkViews.length);
    final CyNetworkView view = networkViews[0];
    final CyNetwork net = view.getModel();
    assertEquals(2, net.getNodeCount());
    assertEquals(1, net.getEdgeCount());
    final CyNode n1 = getNodeByName(net, "node1");
    final CyNode n2 = getNodeByName(net, "node2");
    final CyEdge e = getEdgeByName(net, "node1 (pp) node2");
    assertNotNull(n1);
    assertNotNull(n2);
    assertNotNull(e);
    // CyTable Data:
    final CyRootNetwork rootNet = ((CySubNetwork) net).getRootNetwork();
    CyRow row = rootNet.getRow(n1, CyRootNetwork.SHARED_ATTRS);
    assertEquals(new Integer(0), row.get("att1", Integer.class));
    assertEquals(new Double(0.0), row.get("att2", Double.class));
    assertEquals("", row.get("att3", String.class));
    row = rootNet.getRow(n2, CyRootNetwork.SHARED_ATTRS);
    assertEquals(new Integer(10), row.get("att1", Integer.class));
    assertEquals(new Double(10.1), row.get("att2", Double.class));
    assertEquals("MyString", row.get("att3", String.class));
    row = rootNet.getRow(e, CyRootNetwork.SHARED_ATTRS);
    assertEquals(new Integer(2), row.get("att4", Integer.class));
    assertEquals(new Double(2.2), row.get("att5", Double.class));
    assertEquals("Another string...", row.get("att6", String.class));
    // Visual Properties:
    final View<CyNode> nv1 = view.getNodeView(n1);
    final View<CyNode> nv2 = view.getNodeView(n2);
    final View<CyEdge> ev = view.getEdgeView(e);
    assertNotNull(nv1);
    assertNotNull(nv2);
    assertNotNull(ev);
    assertEquals("My GML Network", view.getVisualProperty(NETWORK_TITLE));
    assertEquals(64.0, nv1.getVisualProperty(NODE_WIDTH), 0.0);
    assertEquals(32.0, nv1.getVisualProperty(NODE_HEIGHT), 0.0);
    assertEquals(-66.0, nv1.getVisualProperty(NODE_X_LOCATION), 0.0);
    assertEquals(-71.0, nv1.getVisualProperty(NODE_Y_LOCATION), 0.0);
    assertEquals(Color.decode("#ffcccc"), nv1.getVisualProperty(NODE_FILL_COLOR));
    assertEquals(Color.decode("#ff6666"), nv1.getVisualProperty(NODE_BORDER_PAINT));
    assertEquals(3.0, nv1.getVisualProperty(NODE_BORDER_WIDTH), 0.0);
    assertEquals(NodeShapeVisualProperty.TRIANGLE, nv1.getVisualProperty(NODE_SHAPE));
    assertEquals(40.0, nv2.getVisualProperty(NODE_WIDTH), 0.0);
    assertEquals(39.999, nv2.getVisualProperty(NODE_HEIGHT), 0.001);
    assertEquals(60.5289, nv2.getVisualProperty(NODE_X_LOCATION), 0.0001);
    assertEquals(77.4868, nv2.getVisualProperty(NODE_Y_LOCATION), 0.0001);
    assertEquals(Color.decode("#ffffcc"), nv2.getVisualProperty(NODE_FILL_COLOR));
    assertEquals(Color.decode("#999900"), nv2.getVisualProperty(NODE_BORDER_PAINT));
    assertEquals(4.0, nv2.getVisualProperty(NODE_BORDER_WIDTH), 0.0);
    assertEquals(NodeShapeVisualProperty.OCTAGON, nv2.getVisualProperty(NODE_SHAPE));
    assertEquals(4.0, ev.getVisualProperty(EDGE_WIDTH), 0.0);
    assertEquals(Color.decode("#660066"), ev.getVisualProperty(EDGE_UNSELECTED_PAINT));
    assertEquals(Color.decode("#660066"), ev.getVisualProperty(EDGE_STROKE_UNSELECTED_PAINT));
    assertEquals(LineTypeVisualProperty.SOLID, ev.getVisualProperty(EDGE_LINE_TYPE));
    assertEquals(ArrowShapeVisualProperty.CIRCLE, ev.getVisualProperty(EDGE_SOURCE_ARROW_SHAPE));
    assertEquals(ArrowShapeVisualProperty.DIAMOND, ev.getVisualProperty(EDGE_TARGET_ARROW_SHAPE));
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyRow(org.cytoscape.model.CyRow) CyEdge(org.cytoscape.model.CyEdge) CyNode(org.cytoscape.model.CyNode) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork) AbstractNetworkReaderTest(org.cytoscape.io.internal.read.AbstractNetworkReaderTest) Test(org.junit.Test)

Example 79 with CySubNetwork

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

the class ReadDataManager method createEdge.

protected CyEdge createEdge(final Object sourceId, final Object targetId, Object id, final String label, final boolean directed, final CyNetwork net) {
    if (id == null)
        id = label;
    CyNode source = cache.getNode(sourceId);
    CyNode target = cache.getNode(targetId);
    final boolean haveTarget = target != null;
    final boolean haveSource = source != null;
    // (it can happen if the edge is written before its nodes in the XGMML document)
    if (!haveSource)
        source = createNode(sourceId, null, net);
    if (!haveTarget)
        target = createNode(targetId, null, net);
    // Create the edge
    final CyNetwork curNet = getCurrentNetwork();
    final CyEdge edge = createEdge(source, target, id, label, directed, net);
    if (curNet instanceof CySubNetwork) {
        // If the actual node elements are not parsed later, they should be deleted from this subnetwork.
        if (!haveSource)
            cache.addUnresolvedNode(source, (CySubNetwork) curNet);
        if (!haveTarget)
            cache.addUnresolvedNode(target, (CySubNetwork) curNet);
    }
    return edge;
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork)

Example 80 with CySubNetwork

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

the class ReadDataManager method createEdge.

protected CyEdge createEdge(final CyNode source, final CyNode target, Object id, final String label, final boolean directed, CyNetwork net) {
    CyEdge edge = null;
    if (id == null)
        id = label;
    if (net instanceof CySubNetwork && this.getParentNetwork() != null) {
        // Do not create the element again if the network is a sub-network and the edge already exists!
        edge = cache.getEdge(id);
        if (edge != null)
            ((CySubNetwork) net).addEdge(edge);
    }
    if (edge == null) {
        // OK, create it
        // But first get the actual source/target instances from the current network,
        // because both node instances have to belong to the same root or sub-network.
        CyNode actualSrc = net.getNode(source.getSUID());
        CyNode actualTgt = net.getNode(target.getSUID());
        // For 2.x groups
        List<Long> extEdgeIds = null;
        if ((getDocumentVersion() < 3.0 || !isSessionFormat()) && (actualSrc == null || actualTgt == null)) {
            // The nodes might have been added to other sub-networks, but not to the current one.
            // If that is the case, the root network should have both nodes,
            // so let's just add the edge to the root.
            final CyRootNetwork rootNet = getRootNetwork();
            if (actualSrc == null)
                actualSrc = rootNet.getNode(source.getSUID());
            if (actualTgt == null)
                actualTgt = rootNet.getNode(target.getSUID());
            // Does the current subnetwork belong to a 2.x group?
            if (getDocumentVersion() < 3.0 && !compoundNodeStack.isEmpty() && networkStack.size() > 1) {
                // Get the current compound node
                final CyNode grNode = compoundNodeStack.peek();
                // Get the network of that node (the current one is its network pointer)
                final CyNetwork parentNet = cache.getNetwork(networkStack.elementAt(networkStack.size() - 2));
                // Check for the group's metadata attribute
                final CyRow gnhRow = parentNet.getRow(grNode, CyNetwork.HIDDEN_ATTRS);
                if (gnhRow.isSet(GROUP_STATE_ATTRIBUTE)) {
                    // It's a group!
                    // Get the network pointer's hidden row
                    final CyRow nphRow = net.getRow(net, CyNetwork.HIDDEN_ATTRS);
                    // Add extra metadata for external edges, so that the information is not lost
                    if (nphRow.getTable().getColumn(EXTERNAL_EDGE_ATTRIBUTE) == null) {
                        nphRow.getTable().createListColumn(EXTERNAL_EDGE_ATTRIBUTE, Long.class, false);
                        // These are already the new SUIDs. Let's tell the SUIDUpdater to ignore this column,
                        // in order to prevent it from replacing the correct list by an empty one.
                        suidUpdater.ignoreColumn(nphRow.getTable(), EXTERNAL_EDGE_ATTRIBUTE);
                    }
                    extEdgeIds = nphRow.getList(EXTERNAL_EDGE_ATTRIBUTE, Long.class);
                    if (extEdgeIds == null) {
                        nphRow.set(EXTERNAL_EDGE_ATTRIBUTE, new ArrayList<Long>());
                        extEdgeIds = nphRow.getList(EXTERNAL_EDGE_ATTRIBUTE, Long.class);
                    }
                }
            }
            net = rootNet;
        }
        edge = net.addEdge(actualSrc, actualTgt, directed);
        if (extEdgeIds != null)
            extEdgeIds.add(edge.getSUID());
        mapSUIDs(id, edge.getSUID());
    }
    // Add to internal cache:
    cache.cache(id, edge);
    return edge;
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) CyRow(org.cytoscape.model.CyRow) CyEdge(org.cytoscape.model.CyEdge) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Aggregations

CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)88 CyNode (org.cytoscape.model.CyNode)44 CyRootNetwork (org.cytoscape.model.subnetwork.CyRootNetwork)35 CyNetwork (org.cytoscape.model.CyNetwork)31 CyEdge (org.cytoscape.model.CyEdge)28 Test (org.junit.Test)19 CyRow (org.cytoscape.model.CyRow)15 ArrayList (java.util.ArrayList)12 CyTable (org.cytoscape.model.CyTable)11 CyNetworkView (org.cytoscape.view.model.CyNetworkView)11 HashSet (java.util.HashSet)7 CyGroup (org.cytoscape.group.CyGroup)7 HashMap (java.util.HashMap)6 CyNetworkManager (org.cytoscape.model.CyNetworkManager)6 CyApplicationManager (org.cytoscape.application.CyApplicationManager)5 CyEventHelper (org.cytoscape.event.CyEventHelper)5 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)5 Dimension (java.awt.Dimension)3 GroupCollapsedEvent (org.cytoscape.group.events.GroupCollapsedEvent)3 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)3