Search in sources :

Example 11 with CyEdge

use of org.cytoscape.model.CyEdge in project EnrichmentMapApp by BaderLab.

the class TestUtils method getSignatureEdges.

public static Map<String, CyEdge> getSignatureEdges(CyNetwork network, String prefix, String sigSetName) {
    Map<String, CyEdge> edges = new HashMap<>();
    for (CyEdge edge : network.getEdgeList()) {
        CyRow row = network.getRow(edge);
        String sigName = Columns.EDGE_SIG_DATASET.get(row, prefix);
        if (sigName != null && sigName.equals(sigSetName)) {
            edges.put(row.get(CyNetwork.NAME, String.class), edge);
        }
    }
    return edges;
}
Also used : HashMap(java.util.HashMap) CyRow(org.cytoscape.model.CyRow) CyEdge(org.cytoscape.model.CyEdge)

Example 12 with CyEdge

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

the class CloneNetworkTask method cloneEdge.

private CyEdge cloneEdge(final CyNetwork origNet, final CyNetwork newNet, final CyEdge origEdge) {
    if (orig2NewEdgeMap.containsKey(origEdge))
        return orig2NewEdgeMap.get(origEdge);
    final CyNode newSource = orig2NewNodeMap.get(origEdge.getSource());
    final CyNode newTarget = orig2NewNodeMap.get(origEdge.getTarget());
    final boolean newDirected = origEdge.isDirected();
    final CyEdge newEdge = newNet.addEdge(newSource, newTarget, newDirected);
    new2OrigEdgeMap.put(newEdge, origEdge);
    orig2NewEdgeMap.put(origEdge, newEdge);
    cloneRow(newNet, CyEdge.class, origNet.getRow(origEdge, CyNetwork.LOCAL_ATTRS), newNet.getRow(newEdge, CyNetwork.LOCAL_ATTRS));
    cloneRow(newNet, CyEdge.class, origNet.getRow(origEdge, CyNetwork.HIDDEN_ATTRS), newNet.getRow(newEdge, CyNetwork.HIDDEN_ATTRS));
    return newEdge;
}
Also used : CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge)

Example 13 with CyEdge

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

the class GroupUtils method addGroupToNetwork.

public static void addGroupToNetwork(CyGroup group, CyNetwork origNet, CyNetwork newNet) {
    CyNetwork groupNetwork = group.getGroupNetwork();
    Dimension d = getPosition(origNet, group, groupNetwork.getSUID(), CyNetwork.class);
    updatePosition(newNet, group, groupNetwork.getSUID(), CyNetwork.class, d);
    for (CyNode node : group.getNodeList()) {
        Long nodeSUID = node.getSUID();
        d = getPosition(origNet, group, nodeSUID, CyNode.class);
        updatePosition(newNet, group, nodeSUID, CyNode.class, d);
        // This helps out collapse
        ((CySubNetwork) newNet).addNode(node);
    }
    for (CyEdge edge : group.getInternalEdgeList()) {
        // This helps out collapse
        ((CySubNetwork) newNet).addEdge(edge);
    }
    for (CyEdge edge : group.getExternalEdgeList()) {
        // This helps out collapse
        ((CySubNetwork) newNet).addEdge(edge);
    }
    group.addGroupToNetwork(newNet);
    group.collapse(newNet);
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) Dimension(java.awt.Dimension) CyEdge(org.cytoscape.model.CyEdge) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork)

Example 14 with CyEdge

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

the class AddEdgeTask method run.

@Override
public void run(final TaskMonitor taskMonitor) {
    if (network == null) {
        network = serviceRegistrar.getService(CyApplicationManager.class).getCurrentNetwork();
        if (network == null) {
            taskMonitor.showMessage(TaskMonitor.Level.ERROR, "Network must be specified for add command");
            return;
        }
    }
    if (sourceName == null) {
        taskMonitor.showMessage(TaskMonitor.Level.ERROR, "Source node name must be specified for add command");
        return;
    }
    if (targetName == null) {
        taskMonitor.showMessage(TaskMonitor.Level.ERROR, "Target node name must be specified for add command");
        return;
    }
    // Find the source and target nodes
    CyNode source = null;
    CyNode target = null;
    for (CyNode node : network.getNodeList()) {
        String nodeName = network.getRow(node).get(CyNetwork.NAME, String.class);
        if (sourceName.equals(nodeName))
            source = node;
        else if (targetName.equals(nodeName))
            target = node;
        if (source != null && target != null)
            break;
    }
    if (source == null) {
        taskMonitor.showMessage(TaskMonitor.Level.ERROR, "Can't find source node named '" + sourceName + "'");
        return;
    }
    if (target == null) {
        taskMonitor.showMessage(TaskMonitor.Level.ERROR, "Can't find target node named '" + targetName + "'");
        return;
    }
    newEdge = network.addEdge(source, target, isDirected);
    if (name != null) {
        network.getRow(newEdge).set(CyNetwork.NAME, name);
        network.getRow(newEdge).set(CyRootNetwork.SHARED_NAME, name);
    }
    cyEventHelper.flushPayloadEvents();
    if (networkViewManager.viewExists(network)) {
        for (CyNetworkView view : networkViewManager.getNetworkViews(network)) {
            View<CyEdge> edgeView = view.getEdgeView(newEdge);
            VisualStyle style = visualMappingManager.getVisualStyle(view);
            if (style != null) {
                style.apply(network.getRow(newEdge), edgeView);
            }
            // Not sure why we need to refresh the view for edges and not nodes, but apparently we do
            view.updateView();
        }
    }
    cyEventHelper.flushPayloadEvents();
    taskMonitor.showMessage(TaskMonitor.Level.INFO, "Added edge " + newEdge.toString() + " to network");
}
Also used : CyNode(org.cytoscape.model.CyNode) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyEdge(org.cytoscape.model.CyEdge)

Example 15 with CyEdge

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

the class AddTask method run.

@Override
public void run(final TaskMonitor taskMonitor) {
    network = nodesAndEdges.getNetwork();
    if (network == null) {
        taskMonitor.showMessage(TaskMonitor.Level.ERROR, "Network must be specified for add command");
        return;
    }
    nodeList = nodesAndEdges.getNodeList(false);
    edgeList = nodesAndEdges.getEdgeList(false);
    if ((nodeList == null || nodeList.size() == 0) && (edgeList == null || edgeList.size() == 0)) {
        taskMonitor.showMessage(TaskMonitor.Level.WARN, "Nothing to add");
        return;
    }
    int nodeCount = nodeList.size();
    int edgeCount = 0;
    for (CyNode node : nodeList) ((CySubNetwork) network).addNode(node);
    // nodes and "all" edges
    for (CyEdge edge : edgeList) {
        if (network.containsNode(edge.getSource()) && network.containsNode(edge.getTarget())) {
            ((CySubNetwork) network).addEdge(edge);
            edgeCount++;
        }
    }
    eventHelper.flushPayloadEvents();
    taskMonitor.showMessage(TaskMonitor.Level.INFO, "Added " + nodeCount + " nodes and " + edgeCount + " edges to network " + network.toString());
}
Also used : CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork)

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