Search in sources :

Example 86 with CyEdge

use of org.cytoscape.model.CyEdge in project cytoscape-impl by cytoscape.

the class GroupViewCollapseHandler method addMemberEdges.

private void addMemberEdges(CyGroup group, CyNetwork network) {
    CyRootNetwork rootNetwork = ((CySubNetwork) network).getRootNetwork();
    CyNode groupNode = group.getGroupNode();
    List<CyEdge> newEdges = new ArrayList<CyEdge>();
    for (CyNode node : group.getNodeList()) {
        if (!network.containsEdge(groupNode, node)) {
            CyEdge edge = network.addEdge(groupNode, node, true);
            CyRow edgeRow = network.getRow(edge);
            CyRow edgeRootRow = rootNetwork.getRow(edge, CyRootNetwork.SHARED_ATTRS);
            // Add a name
            String name = getNodeName(groupNode, network) + " (member) " + getNodeName(node, network);
            edgeRow.set(CyNetwork.NAME, name);
            edgeRootRow.set(CyRootNetwork.SHARED_NAME, name);
            // Set the interaction
            edgeRow.set(CyEdge.INTERACTION, "member");
            edgeRootRow.set(CyRootNetwork.SHARED_INTERACTION, "member");
            newEdges.add(edge);
        }
    }
    if (newEdges.size() > 0)
        group.addEdges(newEdges);
}
Also used : ArrayList(java.util.ArrayList) CyNode(org.cytoscape.model.CyNode) CyRow(org.cytoscape.model.CyRow) CyEdge(org.cytoscape.model.CyEdge) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 87 with CyEdge

use of org.cytoscape.model.CyEdge in project cytoscape-impl by cytoscape.

the class GraphMLWriter method writeEdges.

private void writeEdges(Document doc, Element parent) {
    final List<CyEdge> edges = network.getEdgeList();
    final CyTable table = network.getDefaultEdgeTable();
    final Collection<CyColumn> edgeColumns = table.getColumns();
    for (final CyEdge edge : edges) {
        final Element edgeElm = doc.createElement(EDGE);
        edgeElm.setAttribute(SOURCE, edge.getSource().getSUID().toString());
        edgeElm.setAttribute(TARGET, edge.getTarget().getSUID().toString());
        final CyRow row = network.getRow(edge);
        appendData(row, edgeColumns, doc, edgeElm, edge);
        parent.appendChild(edgeElm);
    }
}
Also used : CyTable(org.cytoscape.model.CyTable) Element(org.w3c.dom.Element) CyColumn(org.cytoscape.model.CyColumn) CyRow(org.cytoscape.model.CyRow) CyEdge(org.cytoscape.model.CyEdge)

Example 88 with CyEdge

use of org.cytoscape.model.CyEdge in project cytoscape-impl by cytoscape.

the class TestCyGroupFactory method testMetaEdges.

// Test maintenance of meta-edges
// Create two groups that share edges
// Collapse both and expand them in the opposite order
@Test
public void testMetaEdges() throws Exception {
    // Set up our data structures
    final CyGroupFactory factory = TestCyGroupFactory.getFactory();
    final NetworkTestSupport support = new NetworkTestSupport();
    final CyNetwork net = support.getNetwork();
    final CyNode nodeA = net.addNode();
    final CyNode nodeB = net.addNode();
    final CyNode nodeC = net.addNode();
    final CyNode nodeD = net.addNode();
    final CyNode nodeE = net.addNode();
    final CyEdge edge1 = net.addEdge(nodeA, nodeE, false);
    final CyEdge edge2 = net.addEdge(nodeE, nodeB, false);
    final CyEdge edge3 = net.addEdge(nodeE, nodeC, false);
    final CyEdge edge4 = net.addEdge(nodeE, nodeD, false);
    final CyEdge edge5 = net.addEdge(nodeC, nodeB, false);
    final CyEdge edge6 = net.addEdge(nodeC, nodeD, false);
    final CyGroup group1 = factory.createGroup(net, null, Arrays.asList(nodeA, nodeB, nodeC), null, true);
    assertNotNull(group1);
    assertEqualWithoutOrder(group1.getNodeList(), Arrays.asList(nodeA, nodeB, nodeC));
    assertEqualWithoutOrder(group1.getInternalEdgeList(), Arrays.asList(edge5));
    assertEqualWithoutOrder(group1.getExternalEdgeList(), Arrays.asList(edge1, edge2, edge3, edge6));
    final CyGroup group2 = factory.createGroup(net, null, Arrays.asList(nodeD, nodeE), null, true);
    assertNotNull(group2);
    assertEqualWithoutOrder(group2.getNodeList(), Arrays.asList(nodeD, nodeE));
    assertEqualWithoutOrder(group2.getInternalEdgeList(), Arrays.asList(edge4));
    // 4 external edges, we create meta-edges when we collapse
    assertTrue(group2.getExternalEdgeList().size() == 4);
    // Collapse both groups
    group1.collapse(net);
    assertTrue(group1.isCollapsed(net));
    group2.collapse(net);
    assertTrue(group2.isCollapsed(net));
    assertEqualWithoutOrder(net.getNodeList(), Arrays.asList(group1.getGroupNode(), group2.getGroupNode()));
    // Expand in opposite order
    group1.expand(net);
    assertEqualWithoutOrder(net.getNodeList(), Arrays.asList(nodeA, nodeB, nodeC, group2.getGroupNode()));
    // 1 internal edge + 3 meta-edges
    assertTrue(net.getEdgeList().size() == 4);
    group2.expand(net);
    assertEqualWithoutOrder(net.getNodeList(), Arrays.asList(nodeA, nodeB, nodeC, nodeD, nodeE));
    assertEqualWithoutOrder(net.getEdgeList(), Arrays.asList(edge1, edge2, edge3, edge4, edge5, edge6));
}
Also used : NetworkTestSupport(org.cytoscape.model.NetworkTestSupport) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge) Test(org.junit.Test)

Example 89 with CyEdge

use of org.cytoscape.model.CyEdge in project cytoscape-impl by cytoscape.

the class FilterWorker method doWork.

@Override
public void doWork(ProgressMonitor monitor) {
    if (controller == null) {
        return;
    }
    final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
    CyNetworkView networkView = applicationManager.getCurrentNetworkView();
    CyNetwork network;
    if (networkView != null) {
        network = networkView.getModel();
    } else {
        network = applicationManager.getCurrentNetwork();
    }
    if (network == null) {
        return;
    }
    monitor.setProgress(0);
    monitor.setStatusMessage(null);
    int nodeCount = 0;
    int edgeCount = 0;
    int counter = 0;
    long startTime = System.currentTimeMillis();
    try {
        Filter<CyNetwork, CyIdentifiable> filter = controller.getFilter();
        if (filter instanceof CompositeFilter) {
            // If we have an empty CompositeFilter, bail out.
            CompositeFilter<CyNetwork, CyIdentifiable> composite = (CompositeFilter<CyNetwork, CyIdentifiable>) filter;
            if (composite.getLength() == 0) {
                return;
            }
        }
        if (filter instanceof MemoizableTransformer) {
            ((MemoizableTransformer) filter).startCaching();
        }
        try {
            List<CyNode> nodeList = network.getNodeList();
            List<CyEdge> edgeList = network.getEdgeList();
            double total = nodeList.size() + edgeList.size();
            List<CyIdentifiable> selected = new ArrayList<>();
            List<CyIdentifiable> unselected = new ArrayList<>();
            for (CyNode node : nodeList) {
                if (monitor.isCancelled()) {
                    return;
                }
                boolean accepted = filter.accepts(network, node);
                if (accepted) {
                    selected.add(node);
                    nodeCount++;
                } else {
                    unselected.add(node);
                }
                monitor.setProgress(++counter / total);
            }
            for (CyEdge edge : edgeList) {
                if (monitor.isCancelled()) {
                    return;
                }
                boolean accepted = filter.accepts(network, edge);
                if (accepted) {
                    selected.add(edge);
                    edgeCount++;
                } else {
                    unselected.add(edge);
                }
                monitor.setProgress(++counter / total);
            }
            // now do the selection
            for (CyIdentifiable element : unselected) {
                CyRow row = network.getRow(element);
                if (row.get(CyNetwork.SELECTED, Boolean.class)) {
                    row.set(CyNetwork.SELECTED, Boolean.FALSE);
                }
            }
            for (CyIdentifiable element : selected) {
                CyRow row = network.getRow(element);
                if (!row.get(CyNetwork.SELECTED, Boolean.class)) {
                    row.set(CyNetwork.SELECTED, Boolean.TRUE);
                }
            }
        } finally {
            if (filter instanceof MemoizableTransformer) {
                ((MemoizableTransformer) filter).clearCache();
            }
        }
        if (networkView != null) {
            networkView.updateView();
        }
    } finally {
        long duration = System.currentTimeMillis() - startTime;
        monitor.setProgress(1.0);
        monitor.setStatusMessage(String.format("Selected %d %s and %d %s in %dms", nodeCount, nodeCount == 1 ? "node" : "nodes", edgeCount, edgeCount == 1 ? "edge" : "edges", duration));
    }
}
Also used : CompositeFilter(org.cytoscape.filter.model.CompositeFilter) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyRow(org.cytoscape.model.CyRow) CyEdge(org.cytoscape.model.CyEdge) MemoizableTransformer(org.cytoscape.filter.internal.MemoizableTransformer) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyNode(org.cytoscape.model.CyNode) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Example 90 with CyEdge

use of org.cytoscape.model.CyEdge in project cytoscape-impl by cytoscape.

the class GetEdgeAttributeTask method run.

@Override
public void run(final TaskMonitor taskMonitor) {
    CyNetwork network = edgeTunable.getNetwork();
    edgeTable = getNetworkTable(network, CyEdge.class, columnTunable.getNamespace());
    edgeDataMap = new HashMap<CyIdentifiable, Map<String, Object>>();
    for (CyEdge edge : edgeTunable.getEdgeList()) {
        Map<String, Object> edgeData = getCyIdentifierData(edgeTable, edge, columnTunable.getColumnNames(edgeTable));
        if (edgeData == null || edgeData.size() == 0)
            continue;
        edgeDataMap.put(edge, edgeData);
        taskMonitor.showMessage(TaskMonitor.Level.INFO, "   Edge table values for edge " + DataUtils.getEdgeName(edgeTable, edge) + ":");
        for (String column : edgeData.keySet()) {
            if (edgeData.get(column) != null)
                taskMonitor.showMessage(TaskMonitor.Level.INFO, "        " + column + "=" + DataUtils.convertData(edgeData.get(column)));
        }
    }
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyEdge(org.cytoscape.model.CyEdge) HashMap(java.util.HashMap) Map(java.util.Map) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Aggregations

CyEdge (org.cytoscape.model.CyEdge)302 CyNode (org.cytoscape.model.CyNode)231 CyNetwork (org.cytoscape.model.CyNetwork)103 ArrayList (java.util.ArrayList)77 Test (org.junit.Test)71 CyNetworkView (org.cytoscape.view.model.CyNetworkView)55 HashSet (java.util.HashSet)42 CyRow (org.cytoscape.model.CyRow)41 CyIdentifiable (org.cytoscape.model.CyIdentifiable)29 HashMap (java.util.HashMap)26 CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)25 CyTable (org.cytoscape.model.CyTable)21 DummyCyEdge (org.cytoscape.model.DummyCyEdge)21 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)18 DummyCyNode (org.cytoscape.model.DummyCyNode)17 View (org.cytoscape.view.model.View)16 List (java.util.List)13 CyEventHelper (org.cytoscape.event.CyEventHelper)12 CyGroup (org.cytoscape.group.CyGroup)12 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)12