use of org.cytoscape.model.subnetwork.CyRootNetwork 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));
}
use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.
the class PerfTest method testNetworkCapability.
private void testNetworkCapability(String name) throws Exception {
CyNetwork[] nets = getNetworks(name);
CyNetwork net = nets[0];
List<CyNode> nodeList = net.getNodeList();
long start = System.currentTimeMillis();
for (CyNode n : nodeList) {
List<CyEdge> edges = net.getAdjacentEdgeList(n, CyEdge.Type.ANY);
}
long end = System.currentTimeMillis();
System.out.println("Getting all adjacent edges: " + (end - start));
/*
start = System.currentTimeMillis();
for ( CyNode n : nodeList ) {
for ( CyNode nn : nodeList ) {
List<CyEdge> edges = net.getConnectingEdgeList(n,nn,CyEdge.Type.ANY);
}
}
end = System.currentTimeMillis();
System.out.println("Getting all connecting edges: " + (end - start));
*/
start = System.currentTimeMillis();
for (CyNode n : nodeList) {
List<CyNode> nodes = net.getNeighborList(n, CyEdge.Type.ANY);
}
end = System.currentTimeMillis();
System.out.println("Getting all neighbor nodes: " + (end - start));
// create subnetworks
CyRootNetwork root = rootNetManager.getRootNetwork(net);
int i = 0;
for (CyNode n : net.getNodeList()) {
if (i++ > 1000)
break;
List<CyNode> nl = net.getNeighborList(n, CyEdge.Type.ANY);
Set<CyEdge> es = new HashSet<CyEdge>();
for (CyNode nn : nl) {
List<CyEdge> ee = net.getConnectingEdgeList(n, nn, CyEdge.Type.ANY);
es.addAll(ee);
}
root.addSubNetwork(nl, es);
}
}
use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.
the class GenericXGMMLReaderTest method testParseCollapsedGroupFrom2x.
@Test
public void testParseCollapsedGroupFrom2x() throws Exception {
List<CyNetworkView> views = getViews("group_2x_collapsed.xgmml");
// The group network should not be registered, so the network list must contain only the base network
assertEquals(1, reader.getNetworks().length);
CyNetwork net = checkSingleNetwork(views, 2, 1);
CyRootNetwork rootNet = rootNetManager.getRootNetwork(net);
CyNode grNode = getNodeByName(rootNet, "metanode 1");
check2xGroupMetadata(net, grNode, false);
// Check group network data
CyNetwork grNet = grNode.getNetworkPointer();
for (CyNode n : grNet.getNodeList()) {
assertNotNull(grNet.getRow(n, HIDDEN_ATTRS).get("__metanodeHintX", Double.class));
assertNotNull(grNet.getRow(n, HIDDEN_ATTRS).get("__metanodeHintY", Double.class));
}
assertCustomColumnsAreMutable(rootNet);
assertCustomColumnsAreMutable(net);
assertCustomColumnsAreMutable(grNet);
assertEquals(1, groupManager.getGroupSet(net).size());
assertTrue(groupManager.isGroup(grNode, net));
}
use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.
the class GenericXGMMLReaderTest method testParseExpandedGroupFrom2x.
@Test
public void testParseExpandedGroupFrom2x() throws Exception {
List<CyNetworkView> views = getViews("group_2x_expanded.xgmml");
// The group network should not be registered, so the network list must contain only the base network
assertEquals(1, reader.getNetworks().length);
CyNetwork net = checkSingleNetwork(views, 3, 2);
CyRootNetwork rootNet = rootNetManager.getRootNetwork(net);
CyNode grNode = getNodeByName(rootNet, "metanode 1");
check2xGroupMetadata(net, grNode, true);
assertCustomColumnsAreMutable(rootNetManager.getRootNetwork(net));
assertCustomColumnsAreMutable(net);
assertCustomColumnsAreMutable(grNode.getNetworkPointer());
assertEquals(1, groupManager.getGroupSet(net).size());
assertTrue(groupManager.isGroup(grNode, net));
}
use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.
the class CySessionManagerImpl method restoreTables.
private void restoreTables(final CySession sess) {
final Set<CyTable> allTables = new HashSet<>();
// Register all tables sent through the CySession, if not already registered
for (final CyTableMetadata metadata : sess.getTables()) {
allTables.add(metadata.getTable());
}
// There may be other network tables in the CyNetworkTableManager that were not serialized in the session file
// (e.g. Table Facades), so it's necessary to add them to CyTableManager as well
final CyNetworkTableManager netTblMgr = serviceRegistrar.getService(CyNetworkTableManager.class);
final CyRootNetworkManager rootNetMgr = serviceRegistrar.getService(CyRootNetworkManager.class);
for (final CyNetwork net : sess.getNetworks()) {
allTables.addAll(netTblMgr.getTables(net, CyNetwork.class).values());
allTables.addAll(netTblMgr.getTables(net, CyNode.class).values());
allTables.addAll(netTblMgr.getTables(net, CyEdge.class).values());
if (!(net instanceof CyRootNetwork)) {
final CyRootNetwork root = rootNetMgr.getRootNetwork(net);
allTables.addAll(netTblMgr.getTables(root, CyNetwork.class).values());
allTables.addAll(netTblMgr.getTables(root, CyNode.class).values());
allTables.addAll(netTblMgr.getTables(root, CyEdge.class).values());
}
}
// Register all tables sent through the CySession, if not already registered
final CyTableManager tblMgr = serviceRegistrar.getService(CyTableManager.class);
for (final CyTable tbl : allTables) {
if (tblMgr.getTable(tbl.getSUID()) == null)
tblMgr.addTable(tbl);
}
}
Aggregations