Search in sources :

Example 76 with CyRootNetwork

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

the class SessionXGMMLNetworkWriter method writeSubGraph.

@Override
protected void writeSubGraph(final CyNetwork net) throws IOException {
    if (net == null)
        return;
    final CyRootNetwork otherRoot = serviceRegistrar.getService(CyRootNetworkManager.class).getRootNetwork(net);
    final boolean sameRoot = rootNetwork.equals(otherRoot);
    if (!sameRoot) {
        // This network belongs to another XGMML file, but that's ok because this XGMML is part of a CYS file,
        // which means that both files will be saved.
        writeSubGraphReference(net);
    } else {
        super.writeSubGraph(net);
    }
}
Also used : CyRootNetworkManager(org.cytoscape.model.subnetwork.CyRootNetworkManager) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 77 with CyRootNetwork

use of org.cytoscape.model.subnetwork.CyRootNetwork 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 78 with CyRootNetwork

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));
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyRow(org.cytoscape.model.CyRow) CyEdge(org.cytoscape.model.CyEdge) CyNode(org.cytoscape.model.CyNode) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork) AbstractNetworkReaderTest(org.cytoscape.io.internal.read.AbstractNetworkReaderTest) Test(org.junit.Test)

Example 79 with CyRootNetwork

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);
    }
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork) HashSet(java.util.HashSet)

Example 80 with CyRootNetwork

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));
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork) AbstractNetworkReaderTest(org.cytoscape.io.internal.read.AbstractNetworkReaderTest) 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