Search in sources :

Example 41 with CySubNetwork

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

the class GenericXGMMLReaderTest method check2xGroupMetadata.

private void check2xGroupMetadata(final CyNetwork net, final CyNode gn, final boolean expanded) {
    assertNotNull("The group node is null", gn);
    // Test 2.x group parsed as network pointer
    if (!expanded) {
        for (CyNode n : net.getNodeList()) {
            if (net.getRow(n, CyNetwork.HIDDEN_ATTRS).isSet(GroupUtil.GROUP_STATE_ATTRIBUTE))
                assertNotNull(n.getNetworkPointer());
            else
                // The other nodes have no network pointer!
                assertNull(n.getNetworkPointer());
        }
    } else {
        CyRootNetwork rootNet = ((CySubNetwork) net).getRootNetwork();
        for (CyNode n : rootNet.getNodeList()) {
            if (rootNet.getRow(n, CyNetwork.HIDDEN_ATTRS).isSet(GroupUtil.GROUP_STATE_ATTRIBUTE))
                assertNotNull(n.getNetworkPointer());
            else
                // The other nodes have no network pointer!
                assertNull(n.getNetworkPointer());
        }
    }
    CyNetwork np = gn.getNetworkPointer();
    assertNotNull(np);
    assertEquals(2, np.getNodeCount());
    assertEquals(1, np.getEdgeCount());
    // Check if the nested graph's attribute was imported to the network pointer
    CyRow npRow = np.getRow(np);
    assertEquals("Lorem Ipsum", npRow.get("gr_att_1", String.class));
    // Check external edges metadata (must be added by the reader!)
    CyRow nphRow = np.getRow(np, HIDDEN_ATTRS);
    List<Long> extEdgeIds = nphRow.getList(GroupUtil.EXTERNAL_EDGE_ATTRIBUTE, Long.class);
    assertEquals(1, extEdgeIds.size());
    CyRootNetwork rootNet = rootNetManager.getRootNetwork(np);
    assertNotNull(rootNet.getEdge(extEdgeIds.get(0)));
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) CyRow(org.cytoscape.model.CyRow) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 42 with CySubNetwork

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

the class CyNetworkManagerImpl method destroyNetwork.

@Override
public void destroyNetwork(final CyNetwork network) {
    if (network == null)
        throw new NullPointerException("Network is null");
    final Long networkId = network.getSUID();
    synchronized (lock) {
        if (!networkMap.containsKey(networkId))
            throw new IllegalArgumentException("network is not recognized by this NetworkManager");
    }
    final CyEventHelper cyEventHelper = serviceRegistrar.getService(CyEventHelper.class);
    // let everyone know!
    cyEventHelper.fireEvent(new NetworkAboutToBeDestroyedEvent(CyNetworkManagerImpl.this, network));
    synchronized (lock) {
        // check again within the lock in case something has changed
        if (!networkMap.containsKey(networkId))
            throw new IllegalArgumentException("network is not recognized by this NetworkManager");
        for (CyNode n : network.getNodeList()) network.getRow(n).set(CyNetwork.SELECTED, false);
        for (CyEdge e : network.getEdgeList()) network.getRow(e).set(CyNetwork.SELECTED, false);
        networkMap.remove(networkId);
    }
    if (network instanceof CySubNetwork) {
        final CySubNetwork subNetwork = (CySubNetwork) network;
        final CyRootNetwork rootNetwork = subNetwork.getRootNetwork();
        final CySubNetwork baseNetwork = rootNetwork.getBaseNetwork();
        if (!subNetwork.equals(baseNetwork) || rootNetwork.getSubNetworkList().size() > 1) {
            rootNetwork.removeSubNetwork(subNetwork);
            network.dispose();
        }
        if (!hasRegisteredNetworks(rootNetwork))
            rootNetwork.dispose();
    } else {
        network.dispose();
    }
    // let everyone know that some network is gone
    cyEventHelper.fireEvent(new NetworkDestroyedEvent(CyNetworkManagerImpl.this));
}
Also used : NetworkDestroyedEvent(org.cytoscape.model.events.NetworkDestroyedEvent) CyEventHelper(org.cytoscape.event.CyEventHelper) NetworkAboutToBeDestroyedEvent(org.cytoscape.model.events.NetworkAboutToBeDestroyedEvent) CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 43 with CySubNetwork

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

the class CyNetworkAutoDeleteTest method testRestoreBug3838_2.

@Test
public void testRestoreBug3838_2() {
    CyNetwork network1 = TestCyNetworkFactory.getInstance();
    CyRootNetwork rootNetwork = ((CySubNetwork) network1).getRootNetwork();
    CyNode n1 = network1.addNode();
    CyNode n2 = network1.addNode();
    CyEdge e1 = network1.addEdge(n1, n2, false);
    network1.removeNodes(Arrays.asList(n1, n2));
    assertFalse(rootNetwork.containsNode(n1));
    assertFalse(rootNetwork.containsNode(n2));
    assertFalse(rootNetwork.containsEdge(e1));
    assertFalse(network1.containsNode(n1));
    assertFalse(network1.containsNode(n2));
    assertFalse(network1.containsEdge(e1));
    rootNetwork.restoreEdge(e1);
    assertTrue(rootNetwork.containsNode(n1));
    assertTrue(rootNetwork.containsNode(n2));
    assertTrue(rootNetwork.containsEdge(e1));
    assertFalse(network1.containsNode(n1));
    assertFalse(network1.containsNode(n2));
    assertFalse(network1.containsEdge(e1));
    network1.removeNodes(Arrays.asList(n1, n2));
    assertTrue(rootNetwork.containsNode(n1));
    assertTrue(rootNetwork.containsNode(n2));
    assertTrue(rootNetwork.containsEdge(e1));
    assertFalse(network1.containsNode(n1));
    assertFalse(network1.containsNode(n2));
    assertFalse(network1.containsEdge(e1));
    rootNetwork.restoreEdge(e1);
    assertTrue(rootNetwork.containsNode(n1));
    assertTrue(rootNetwork.containsNode(n2));
    assertTrue(rootNetwork.containsEdge(e1));
    assertFalse(network1.containsNode(n1));
    assertFalse(network1.containsNode(n2));
    assertFalse(network1.containsEdge(e1));
}
Also used : CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork) Test(org.junit.Test)

Example 44 with CySubNetwork

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

the class CyNetworkAutoDeleteTest method testAutoDeleteFromRootNetwork.

@Test
public void testAutoDeleteFromRootNetwork() {
    CyNetwork network1 = TestCyNetworkFactory.getInstance();
    CyRootNetwork rootNetwork = ((CySubNetwork) network1).getRootNetwork();
    CyNode n1 = network1.addNode();
    CyNode n2 = network1.addNode();
    CyNode n3 = network1.addNode();
    CyEdge e1 = network1.addEdge(n1, n2, false);
    CyEdge e2 = network1.addEdge(n2, n3, false);
    CyNetwork network2 = rootNetwork.addSubNetwork(Arrays.asList(n1, n2, n3), Arrays.asList(e1, e2));
    // Things should work as expected when removing a node from a single subnetwork
    network1.removeNodes(Collections.singleton(n1));
    assertTrue(rootNetwork.containsNode(n1));
    assertFalse(network1.containsNode(n1));
    assertTrue(network2.containsNode(n1));
    // should also automatically remove the edge that's connected to n1, but only from network1
    assertTrue(rootNetwork.containsEdge(e1));
    assertFalse(network1.containsEdge(e1));
    assertTrue(network2.containsEdge(e1));
    assertNotNull(rootNetwork.getNode(n1.getSUID()));
    assertNull(network1.getNode(n1.getSUID()));
    rowExists(true, rootNetwork, n1);
    rowExists(false, network1, n1);
    rowExists(true, network2, n1);
    rowExists(true, rootNetwork, e1);
    rowExists(false, network1, e1);
    rowExists(true, network2, e1);
    // Now remove n1 and e1 from the other subnetwork, that should auto-delete from the root network
    network2.removeNodes(Collections.singleton(n1));
    assertFalse(rootNetwork.containsNode(n1));
    assertFalse(network1.containsNode(n1));
    assertFalse(network2.containsNode(n1));
    assertFalse(rootNetwork.containsEdge(e1));
    assertFalse(network1.containsEdge(e1));
    assertFalse(network2.containsEdge(e1));
    assertNull(rootNetwork.getNode(n1.getSUID()));
    assertNull(network1.getNode(n1.getSUID()));
    rowExists(false, rootNetwork, n1);
    rowExists(false, network1, n1);
    rowExists(false, network2, n1);
    rowExists(false, rootNetwork, e1);
    rowExists(false, network1, e1);
    rowExists(false, network2, e1);
}
Also used : CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork) Test(org.junit.Test)

Example 45 with CySubNetwork

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

the class CyNetworkAutoDeleteTest method testRestoreEdgeRestoresSourceAndTarget.

@Test
public void testRestoreEdgeRestoresSourceAndTarget() {
    // Better version of above test
    CyNetwork network1 = TestCyNetworkFactory.getInstance();
    CyRootNetwork rootNetwork = ((CySubNetwork) network1).getRootNetwork();
    CyNode n1 = network1.addNode();
    CyNode n2 = network1.addNode();
    CyNode n3 = network1.addNode();
    CyEdge e1 = network1.addEdge(n1, n2, false);
    CyEdge e2 = network1.addEdge(n2, n3, false);
    CyNetwork network2 = rootNetwork.addSubNetwork(Arrays.asList(n1, n2, n3), Arrays.asList(e1, e2));
    network1.removeNodes(Arrays.asList(n1, n2));
    network2.removeNodes(Arrays.asList(n1, n2));
    assertFalse(rootNetwork.containsNode(n1));
    assertFalse(rootNetwork.containsNode(n2));
    assertFalse(rootNetwork.containsEdge(e1));
    assertFalse(network1.containsNode(n1));
    assertFalse(network2.containsNode(n1));
    assertFalse(network1.containsNode(n2));
    assertFalse(network2.containsNode(n2));
    assertFalse(network1.containsEdge(e1));
    assertFalse(network2.containsEdge(e1));
    rootNetwork.restoreEdge(e1);
    assertTrue(rootNetwork.containsNode(n1));
    assertTrue(rootNetwork.containsNode(n2));
    assertTrue(rootNetwork.containsEdge(e1));
    assertFalse(network1.containsNode(n1));
    assertFalse(network2.containsNode(n1));
    assertFalse(network1.containsNode(n2));
    assertFalse(network2.containsNode(n2));
    assertFalse(network1.containsEdge(e1));
    assertFalse(network2.containsEdge(e1));
}
Also used : CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork) Test(org.junit.Test)

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