Search in sources :

Example 16 with CyRootNetwork

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

the class CyNetworkAutoDeleteTest method testUndoDeletedNodeAndEdge.

@Test
public void testUndoDeletedNodeAndEdge() {
    final String TEST_COLUMN = "testColumn";
    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);
    CyTable defaultNodeTable = network1.getDefaultNodeTable();
    defaultNodeTable.createColumn(TEST_COLUMN, String.class, false);
    CyTable defaultEdgeTable = network1.getDefaultEdgeTable();
    defaultEdgeTable.createColumn(TEST_COLUMN, String.class, false);
    network1.getRow(n1).set(TEST_COLUMN, "my node 1");
    network1.getRow(e1).set(TEST_COLUMN, "my edge 1");
    CyNetwork network2 = rootNetwork.addSubNetwork(Arrays.asList(n1, n2, n3), Arrays.asList(e1, e2));
    network1.removeNodes(Collections.singleton(n1));
    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));
    // restore the node to network1
    ((CySubNetwork) network1).addNode(n1);
    assertTrue(rootNetwork.containsNode(n1));
    assertTrue(network1.containsNode(n1));
    assertFalse(network2.containsNode(n1));
    assertFalse(rootNetwork.containsEdge(e1));
    assertFalse(network1.containsEdge(e1));
    assertFalse(network2.containsEdge(e1));
    ((CySubNetwork) network1).addEdge(e1);
    assertTrue(rootNetwork.containsNode(n1));
    assertTrue(network1.containsNode(n1));
    assertFalse(network2.containsNode(n1));
    assertTrue(rootNetwork.containsEdge(e1));
    assertTrue(network1.containsEdge(e1));
    assertFalse(network2.containsEdge(e1));
    // test that the attributes are restored
    assertEquals("my node 1", rootNetwork.getRow(n1).get(TEST_COLUMN, String.class));
    assertEquals("my edge 1", rootNetwork.getRow(e1).get(TEST_COLUMN, String.class));
}
Also used : CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork) Test(org.junit.Test)

Example 17 with CyRootNetwork

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

the class CyNetworkAutoDeleteTest method testUndoDeletedEdge.

@Test
public void testUndoDeletedEdge() {
    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(Collections.singleton(n1));
    network2.removeNodes(Collections.singleton(n1));
    assertFalse(rootNetwork.containsEdge(e1));
    assertFalse(rootNetwork.containsNode(n1));
    // restoring the edge should automatically restore its source and target nodes as well
    ((CySubNetwork) network1).addEdge(e1);
    assertTrue(rootNetwork.containsNode(n1));
    assertTrue(network1.containsNode(n1));
    assertFalse(network2.containsNode(n1));
    assertTrue(rootNetwork.containsEdge(e1));
    assertTrue(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)

Example 18 with CyRootNetwork

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

the class CyNetworkAutoDeleteTest method testRestoreBug3838_1.

@Test
public void testRestoreBug3838_1() {
    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.removeEdges(Arrays.asList(e1));
    assertTrue(rootNetwork.containsNode(n1));
    assertTrue(rootNetwork.containsNode(n2));
    assertFalse(rootNetwork.containsEdge(e1));
    assertTrue(network1.containsNode(n1));
    assertTrue(network1.containsNode(n2));
    assertFalse(network1.containsEdge(e1));
    rootNetwork.restoreEdge(e1);
    assertTrue(rootNetwork.containsNode(n1));
    assertTrue(rootNetwork.containsNode(n2));
    assertTrue(rootNetwork.containsEdge(e1));
    assertTrue(network1.containsNode(n1));
    assertTrue(network1.containsNode(n2));
    assertFalse(network1.containsEdge(e1));
    network1.removeNodes(Arrays.asList(n1));
    assertFalse(rootNetwork.containsNode(n1));
    assertTrue(rootNetwork.containsNode(n2));
    assertFalse(rootNetwork.containsEdge(e1));
    assertFalse(network1.containsNode(n1));
    assertTrue(network1.containsNode(n2));
    assertFalse(network1.containsEdge(e1));
    rootNetwork.restoreEdge(e1);
    assertTrue(rootNetwork.containsEdge(e1));
    assertTrue(rootNetwork.containsNode(n1));
    assertTrue(rootNetwork.containsNode(n2));
    assertFalse(network1.containsNode(n1));
    assertTrue(network1.containsNode(n2));
    assertFalse(network1.containsEdge(e1));
    CyRow row = rootNetwork.getDefaultEdgeTable().getRow(e1.getSUID());
    assertNotNull(row);
}
Also used : CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork) Test(org.junit.Test)

Example 19 with CyRootNetwork

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

the class CyNetworkAutoDeleteTest method testSubnetworkWorkaround.

@Test
public void testSubnetworkWorkaround() {
    CyNetwork network1 = TestCyNetworkFactory.getInstance();
    CyRootNetwork rootNetwork = ((CySubNetwork) network1).getRootNetwork();
    CyNode n1 = network1.addNode();
    CyNode n2 = network1.addNode();
    CyNode n3 = network1.addNode();
    CyNode n4 = 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, n4), Arrays.asList(e1, e2));
    // will also cause n2 to be saved because its attached to e1
    rootNetwork.addSubNetwork(Arrays.asList(n1), Arrays.asList(e1));
    network1.removeEdges(Arrays.asList(e1));
    network2.removeEdges(Arrays.asList(e1));
    // additional subnetwork keeps e1 alive
    assertTrue(rootNetwork.containsEdge(e1));
    assertTrue(rootNetwork.containsNode(n1));
    assertTrue(rootNetwork.containsNode(n2));
    assertTrue(rootNetwork.containsNode(n3));
    assertTrue(rootNetwork.containsNode(n4));
    assertTrue(rootNetwork.containsEdge(e2));
    rootNetwork.removeSubNetwork((CySubNetwork) network1);
    rootNetwork.removeSubNetwork((CySubNetwork) network2);
    // should flush nodes/edges not in the additional subnetwork
    assertTrue(rootNetwork.containsEdge(e1));
    assertTrue(rootNetwork.containsNode(n1));
    assertTrue(rootNetwork.containsNode(n2));
    assertFalse(rootNetwork.containsNode(n3));
    assertFalse(rootNetwork.containsNode(n4));
    assertFalse(rootNetwork.containsEdge(e2));
}
Also used : CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork) Test(org.junit.Test)

Example 20 with CyRootNetwork

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

the class CyNetworkAutoDeleteTest method testRestoreEdge.

@Test
public void testRestoreEdge() {
    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.removeEdges(Arrays.asList(e1));
    network2.removeEdges(Arrays.asList(e1));
    assertFalse(rootNetwork.containsEdge(e1));
    rootNetwork.restoreEdge(e1);
    assertTrue(rootNetwork.containsEdge(e1));
}
Also used : CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork) Test(org.junit.Test)

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