Search in sources :

Example 41 with CyEdge

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

the class SelectAdjacentEdgesTask method run.

@Override
public void run(final TaskMonitor tm) {
    tm.setTitle("Select Adjacent Edges");
    tm.setProgress(0.0);
    final Collection<CyNetworkView> views = networkViewManager.getNetworkViews(network);
    CyNetworkView view = null;
    if (views.size() != 0)
        view = views.iterator().next();
    undoSupport.postEdit(new SelectionEdit(eventHelper, "Select Adjacent Edges", network, view, SelectionEdit.SelectionFilter.EDGES_ONLY));
    tm.setStatusMessage("Selecting Edges...");
    tm.setProgress(0.2);
    final Set<CyEdge> edgeSet = new HashSet<>();
    // Get the list of selected nodes
    for (CyNode node : CyTableUtil.getNodesInState(network, CyNetwork.SELECTED, true)) {
        // Get the list of edges connected to this node
        edgeSet.addAll(network.getAdjacentEdgeList(node, CyEdge.Type.ANY));
    }
    tm.setProgress(0.3);
    selectUtils.setSelectedEdges(network, edgeSet, true);
    tm.setStatusMessage("Updating View...");
    tm.setProgress(0.9);
    updateView();
    tm.setProgress(1.0);
}
Also used : CyNode(org.cytoscape.model.CyNode) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyEdge(org.cytoscape.model.CyEdge) HashSet(java.util.HashSet)

Example 42 with CyEdge

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

the class HideFromSelectionTask method run.

@Override
public void run(final TaskMonitor tm) {
    tm.setProgress(0.0);
    final CyNetwork network = view.getModel();
    final List<CyIdentifiable> elements = new ArrayList<>();
    List<CyNode> nodes = null;
    List<CyEdge> edges = null;
    if (hideNodes) {
        nodes = CyTableUtil.getNodesInState(network, CyNetwork.SELECTED, selectionValue);
        elements.addAll(nodes);
    }
    tm.setProgress(0.1);
    if (hideEdges) {
        edges = CyTableUtil.getEdgesInState(network, CyNetwork.SELECTED, selectionValue);
        elements.addAll(edges);
    }
    final UndoSupport undoSupport = serviceRegistrar.getService(UndoSupport.class);
    final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
    final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
    undoSupport.postEdit(new HideEdit(description, view, elements, false, eventHelper, vmMgr));
    tm.setProgress(0.4);
    if (nodes != null)
        HideUtils.setVisibleNodes(nodes, false, view);
    tm.setProgress(0.6);
    if (edges != null)
        HideUtils.setVisibleEdges(edges, false, view);
    tm.setProgress(0.8);
    VisualStyle style = vmMgr.getVisualStyle(view);
    for (CyIdentifiable e : elements) {
        View<? extends CyIdentifiable> ev = null;
        if (e instanceof CyNode)
            ev = view.getNodeView((CyNode) e);
        else if (e instanceof CyEdge)
            ev = view.getEdgeView((CyEdge) e);
        if (ev != null)
            style.apply(network.getRow(e), ev);
    }
    view.updateView();
    tm.setProgress(1.0);
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyEdge(org.cytoscape.model.CyEdge) UndoSupport(org.cytoscape.work.undo.UndoSupport) CyNode(org.cytoscape.model.CyNode) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Example 43 with CyEdge

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

the class RenameEdgeTask method run.

@Override
public void run(final TaskMonitor taskMonitor) {
    if (network == null) {
        taskMonitor.showMessage(TaskMonitor.Level.ERROR, "Network must be specified");
        return;
    }
    if (edge == null) {
        taskMonitor.showMessage(TaskMonitor.Level.ERROR, "Edge name or suid must be specified");
        return;
    }
    if (newName == null) {
        taskMonitor.showMessage(TaskMonitor.Level.ERROR, "New name must be specified");
        return;
    }
    CyEdge renamedEdge = getEdge(network, edge);
    network.getRow(renamedEdge).set(CyNetwork.NAME, newName);
    taskMonitor.showMessage(TaskMonitor.Level.INFO, "Edge " + renamedEdge + " renamed to " + newName);
}
Also used : CyEdge(org.cytoscape.model.CyEdge)

Example 44 with CyEdge

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

the class LayoutEdgeTest method testLayoutEdgeConstructor2.

@Test
public void testLayoutEdgeConstructor2() {
    CyNetworkFactory nFactory = support.getNetworkFactory();
    CyNetwork newNetwork = nFactory.createNetwork();
    CyNode s = newNetwork.addNode();
    CyNode t = newNetwork.addNode();
    CyEdge e = newNetwork.addEdge(s, t, true);
    final CyNetworkViewFactory viewFactory = support.getNetworkViewFactory();
    CyNetworkView newView = viewFactory.createNetworkView(newNetwork);
    final View<CyNode> sourceView = newView.getNodeView(s);
    final View<CyNode> targetView = newView.getNodeView(t);
    assertNotNull(sourceView);
    assertNotNull(targetView);
    CyRow sRow = newNetwork.getRow(s);
    CyRow tRow = newNetwork.getRow(t);
    final LayoutNode layoutNodeS = new LayoutNode(sourceView, 0, sRow);
    final LayoutNode layoutNodeT = new LayoutNode(targetView, 1, tRow);
    final LayoutEdge layoutEdge2 = new LayoutEdge(e, layoutNodeS, layoutNodeT, newNetwork.getRow(e));
    assertNotNull(layoutEdge2);
}
Also used : CyNetworkViewFactory(org.cytoscape.view.model.CyNetworkViewFactory) CyNetwork(org.cytoscape.model.CyNetwork) CyNetworkFactory(org.cytoscape.model.CyNetworkFactory) CyNode(org.cytoscape.model.CyNode) CyRow(org.cytoscape.model.CyRow) CyEdge(org.cytoscape.model.CyEdge) CyNetworkView(org.cytoscape.view.model.CyNetworkView) Test(org.junit.Test)

Example 45 with CyEdge

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

the class NetworkLineParser method parseEntry.

public void parseEntry(final String[] parts) {
    final CyNode source = createNode(parts, mapping.getSourceIndex());
    final CyNode target = createNode(parts, mapping.getTargetIndex());
    final SourceColumnSemantic[] types = mapping.getTypes();
    final List<Integer> srcAttrIdxs = new ArrayList<>();
    final List<Integer> tgtAttrIdxs = new ArrayList<>();
    final List<Integer> edgeAttrIdxs = new ArrayList<>();
    for (int i = 0; i < types.length; i++) {
        if (types[i] == SourceColumnSemantic.SOURCE_ATTR)
            srcAttrIdxs.add(i);
        else if (types[i] == SourceColumnSemantic.TARGET_ATTR)
            tgtAttrIdxs.add(i);
        else if (types[i] == SourceColumnSemantic.EDGE_ATTR || types[i] == SourceColumnSemantic.ATTR)
            edgeAttrIdxs.add(i);
    }
    if (source != null)
        addAttributes(source, parts, srcAttrIdxs);
    if (target != null)
        addAttributes(target, parts, tgtAttrIdxs);
    // Single column nodes list.  Just add nodes.
    if (source == null || target == null)
        return;
    final String interaction;
    if ((mapping.getInteractionIndex() == -1) || (mapping.getInteractionIndex() > (parts.length - 1)) || (parts[mapping.getInteractionIndex()] == null)) {
        interaction = mapping.getDefaultInteraction();
    } else {
        interaction = parts[mapping.getInteractionIndex()];
    }
    final CyEdge edge = network.addEdge(source, target, true);
    network.getRow(edge).set(CyEdge.INTERACTION, interaction);
    String edgeName = network.getRow(source).get(CyNetwork.NAME, String.class) + " (" + interaction + ") " + network.getRow(target).get(CyNetwork.NAME, String.class);
    network.getRow(edge).set(CyNetwork.NAME, edgeName);
    edgeList.add(edge.getSUID());
    if (edge != null)
        addAttributes(edge, parts, edgeAttrIdxs);
}
Also used : SourceColumnSemantic(org.cytoscape.tableimport.internal.util.SourceColumnSemantic) ArrayList(java.util.ArrayList) CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge)

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