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