Search in sources :

Example 76 with CyEdge

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

the class InteractionTransformer method apply.

@Override
public void apply(CyNetwork network, CyIdentifiable element, TransformerSink<CyIdentifiable> sink) {
    if (action == Action.ADD)
        sink.collect(element);
    if (element instanceof CyEdge) {
        CyEdge edge = (CyEdge) element;
        Filter<CyNetwork, CyIdentifiable> memoizedFilter = super.getMemoizedFilter();
        if (selectSource) {
            CyNode source = edge.getSource();
            if (memoizedFilter.accepts(network, source)) {
                sink.collect(source);
            }
        }
        if (selectTarget) {
            CyNode target = edge.getTarget();
            if (memoizedFilter.accepts(network, target)) {
                sink.collect(target);
            }
        }
    }
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Example 77 with CyEdge

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

the class RowsSetViewUpdater method updateView.

private final void updateView(final RowsSetEvent e) {
    boolean refreshView = false;
    boolean refreshOtherViews = false;
    // Acquire services once to avoid performance overhead of repeated lookup
    final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
    final CyColumnIdentifierFactory columnIdentifierFactory = serviceRegistrar.getService(CyColumnIdentifierFactory.class);
    final CyNetworkViewManager networkViewManager = serviceRegistrar.getService(CyNetworkViewManager.class);
    final VisualMappingManager visualMappingManager = serviceRegistrar.getService(VisualMappingManager.class);
    final RenderingEngine<CyNetwork> renderer = applicationManager.getCurrentRenderingEngine();
    final CyNetwork network = applicationManager.getCurrentNetwork();
    if (network == null)
        return;
    // 1: Update current network view
    final Collection<CyNetworkView> views = networkViewManager.getNetworkViews(network);
    CyNetworkView networkView = null;
    if (views.isEmpty())
        return;
    else
        networkView = views.iterator().next();
    final VisualStyle vs = visualMappingManager.getVisualStyle(networkView);
    Map<CyRow, View<? extends CyIdentifiable>> rowViewMap = tracker.getRowViewMap(networkView);
    for (final RowSetRecord record : e.getPayloadCollection()) {
        final CyRow row = record.getRow();
        final String columnName = record.getColumn();
        final CyColumn column = row.getTable().getColumn(columnName);
        if (column == null)
            continue;
        final VirtualColumnInfo virtualColInfo = column.getVirtualColumnInfo();
        final boolean virtual = virtualColInfo.isVirtual();
        final View<? extends CyIdentifiable> v = rowViewMap.get(row);
        if (v == null)
            continue;
        if (v.getModel() instanceof CyNode) {
            final CyNode node = (CyNode) v.getModel();
            if (network.containsNode(node) && isStyleAffected(vs, columnName, renderer, columnIdentifierFactory)) {
                vs.apply(row, v);
                refreshView = false;
            }
        } else if (v.getModel() instanceof CyEdge) {
            final CyEdge edge = (CyEdge) v.getModel();
            if (network.containsEdge(edge) && isStyleAffected(vs, columnName, renderer, columnIdentifierFactory)) {
                vs.apply(row, v);
                refreshView = false;
            }
        }
        // If virtual, it may be used in other networks.
        if (refreshView && virtual)
            refreshOtherViews = true;
    // if (refreshView)
    // vs.apply(record.getRow(), (View<? extends CyIdentifiable>) v);
    }
    if (refreshView) {
        vs.apply(networkView);
        networkView.updateView();
        if (refreshOtherViews) {
            // Check other views. If update is required, set the flag.
            for (final CyNetworkView view : networkViewManager.getNetworkViewSet()) {
                if (view == networkView)
                    continue;
                final VisualStyle style = visualMappingManager.getVisualStyle(view);
                if (style == vs) {
                    // Same style is in use. Need to apply.
                    netViewMediator.setUpdateFlag(view);
                }
            }
        }
    }
}
Also used : RowSetRecord(org.cytoscape.model.events.RowSetRecord) CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) CyColumnIdentifierFactory(org.cytoscape.view.presentation.property.values.CyColumnIdentifierFactory) CyColumn(org.cytoscape.model.CyColumn) CyNetwork(org.cytoscape.model.CyNetwork) CyRow(org.cytoscape.model.CyRow) View(org.cytoscape.view.model.View) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyEdge(org.cytoscape.model.CyEdge) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyNode(org.cytoscape.model.CyNode) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) VirtualColumnInfo(org.cytoscape.model.VirtualColumnInfo) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Example 78 with CyEdge

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

the class GraphMLReaderTest method testReadAttrGraph.

@Test
public void testReadAttrGraph() throws Exception {
    File file = new File("src/test/resources/simpleWithAttributes.xml");
    InputStream stream = file.toURI().toURL().openStream();
    GraphMLReader reader = new GraphMLReader(stream, layouts, appManager, netFactory, networkManager, rootFactory);
    assertNotNull(reader);
    reader.run(tm);
    final CyNetwork[] networks = reader.getNetworks();
    assertNotNull(networks);
    assertEquals(1, networks.length);
    final CyNetwork net = networks[0];
    assertEquals(6, net.getNodeCount());
    assertEquals(7, net.getEdgeCount());
    // Check Network Attributes
    final String networkName = net.getDefaultNetworkTable().getRow(net.getSUID()).get(NAME, String.class);
    final Number networkNumber = net.getDefaultNetworkTable().getRow(net.getSUID()).get("number_test", Double.class);
    assertEquals("Small GraphML Network", networkName);
    assertEquals(100.123, networkNumber);
    final CyNode n1 = getNodeByName(net, "n0");
    assertNotNull(n1);
    final CyEdge e1 = getEdgeByName(net, "n0 (-) n1");
    assertNotNull(e1);
    final CyColumn colorCol = net.getDefaultNodeTable().getColumn("color");
    final CyColumn rankCol = net.getDefaultNodeTable().getColumn("rank");
    final CyColumn degreeCol = net.getDefaultNodeTable().getColumn("degree");
    final CyColumn scoreCol = net.getDefaultNodeTable().getColumn("score");
    final CyColumn taggedCol = net.getDefaultNodeTable().getColumn("tagged");
    final CyColumn weightCol = net.getDefaultEdgeTable().getColumn("weight");
    assertNotNull(colorCol);
    assertNotNull(rankCol);
    assertNotNull(degreeCol);
    assertNotNull(scoreCol);
    assertNotNull(taggedCol);
    assertNotNull(weightCol);
    assertEquals(String.class, colorCol.getType());
    assertEquals(Integer.class, rankCol.getType());
    assertEquals(Long.class, degreeCol.getType());
    // GraphML "float" is converted to Double by Cytoscape
    assertEquals(Double.class, scoreCol.getType());
    assertEquals(Boolean.class, taggedCol.getType());
    assertEquals(Double.class, weightCol.getType());
    assertEquals("green", net.getRow(n1).get("color", String.class));
    assertEquals(Integer.valueOf(3), net.getRow(n1).get("rank", Integer.class));
    assertEquals(Long.valueOf(2), net.getRow(n1).get("degree", Long.class));
    assertEquals(Double.valueOf(0.95d), net.getRow(n1).get("score", Double.class));
    assertEquals(Boolean.TRUE, net.getRow(n1).get("tagged", Boolean.class));
    assertEquals(Double.valueOf(1.0d), net.getRow(e1).get("weight", Double.class));
}
Also used : InputStream(java.io.InputStream) CyColumn(org.cytoscape.model.CyColumn) CyNetwork(org.cytoscape.model.CyNetwork) CyEdge(org.cytoscape.model.CyEdge) GraphMLReader(org.cytoscape.io.internal.read.graphml.GraphMLReader) CyNode(org.cytoscape.model.CyNode) File(java.io.File) Test(org.junit.Test)

Example 79 with CyEdge

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

the class CyGroupImpl method removeMemberEdges.

public void removeMemberEdges() {
    Set<CyEdge> edgesToRemove = new HashSet<>(memberEdges);
    for (CyNetwork network : networkSet) {
        network.removeEdges(edgesToRemove);
    }
    rootNetwork.removeEdges(edgesToRemove);
    memberEdges.clear();
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyEdge(org.cytoscape.model.CyEdge) HashSet(java.util.HashSet)

Example 80 with CyEdge

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

the class CyGroupImpl method removeNodes.

/**
 * @see org.cytoscape.group.CyGroup#removeNodes()
 */
@Override
public void removeNodes(List<CyNode> nodes) {
    synchronized (lock) {
        List<CyEdge> netEdges = new ArrayList<CyEdge>();
        for (CyNode node : nodes) {
            List<CyEdge> edges = rootNetwork.getAdjacentEdgeList(node, CyEdge.Type.ANY);
            for (CyEdge edge : edges) {
                if (externalEdges.contains(edge))
                    externalEdges.remove(edge);
                else if (memberEdges.contains(edge))
                    memberEdges.remove(edge);
                else {
                    netEdges.add(edge);
                }
            }
        }
        if (netEdges.size() > 0)
            getGroupNetwork().removeEdges(netEdges);
        getGroupNetwork().removeNodes(nodes);
        updateMetaEdges(false);
        for (CyNetwork net : networkSet) {
            updateCountAttributes(net);
        }
    }
    cyEventHelper.fireEvent(new GroupNodesRemovedEvent(CyGroupImpl.this, nodes));
}
Also used : GroupNodesRemovedEvent(org.cytoscape.group.events.GroupNodesRemovedEvent) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) 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