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));
}
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));
}
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);
}
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));
}
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));
}
Aggregations