Search in sources :

Example 21 with CyEdge

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

the class InDegreeTest method init.

@Before
public void init() {
    final CyNode node = mock(CyNode.class);
    when(node.getSUID()).thenReturn(101L);
    final List<CyEdge> edgeList = mock(List.class);
    when(edgeList.size()).thenReturn(3);
    final CyNetwork network = mock(CyNetwork.class);
    when(network.getAdjacentEdgeList(node, CyEdge.Type.INCOMING)).thenReturn(edgeList);
    when(network.getNode(101L)).thenReturn(node);
    Collection<CyNode> nodes = new ArrayList<CyNode>(1);
    nodes.add(node);
    applicationManager = mock(CyApplicationManager.class);
    when(applicationManager.getCurrentNetwork()).thenReturn(network);
    eventHelper = new DummyCyEventHelper();
    serviceRegistrar = mock(CyServiceRegistrar.class);
    when(serviceRegistrar.getService(CyApplicationManager.class)).thenReturn(applicationManager);
    when(serviceRegistrar.getService(CyEventHelper.class)).thenReturn(eventHelper);
}
Also used : CyApplicationManager(org.cytoscape.application.CyApplicationManager) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) DummyCyEventHelper(org.cytoscape.event.DummyCyEventHelper) CyEdge(org.cytoscape.model.CyEdge) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) Before(org.junit.Before)

Example 22 with CyEdge

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

the class SourceIDTest method init.

@Before
public void init() {
    final CyNode node = mock(CyNode.class);
    when(node.getSUID()).thenReturn(101L);
    final List<CyEdge> edgeList = mock(List.class);
    when(edgeList.size()).thenReturn(3);
    final CyNetwork network = mock(CyNetwork.class);
    final CyEdge edge = mock(CyEdge.class);
    when(edge.getSUID()).thenReturn(11L);
    when(edge.getSource()).thenReturn(node);
    Collection<CyEdge> edges = new ArrayList<CyEdge>(1);
    edges.add(edge);
    when(network.getEdge(11L)).thenReturn(edge);
    applicationManager = mock(CyApplicationManager.class);
    when(applicationManager.getCurrentNetwork()).thenReturn(network);
    eventHelper = new DummyCyEventHelper();
    serviceRegistrar = mock(CyServiceRegistrar.class);
    when(serviceRegistrar.getService(CyApplicationManager.class)).thenReturn(applicationManager);
    when(serviceRegistrar.getService(CyEventHelper.class)).thenReturn(eventHelper);
}
Also used : CyApplicationManager(org.cytoscape.application.CyApplicationManager) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) DummyCyEventHelper(org.cytoscape.event.DummyCyEventHelper) CyEdge(org.cytoscape.model.CyEdge) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) Before(org.junit.Before)

Example 23 with CyEdge

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

the class SIFNetworkReader method createEdge.

private void createEdge(final Interaction itr, final CySubNetwork subNetwork, final Map<Object, CyNode> nMap) {
    CyNode sourceNode = nMap.get(itr.getSource());
    if (sourceNode == null) {
        sourceNode = subNetwork.addNode();
        subNetwork.getRow(sourceNode).set(CyNetwork.NAME, itr.getSource());
        nMap.put(itr.getSource(), subNetwork.getRootNetwork().getNode(sourceNode.getSUID()));
    }
    for (final String target : itr.getTargets()) {
        CyNode targetNode = nMap.get(target);
        if (targetNode == null) {
            targetNode = subNetwork.addNode();
            subNetwork.getRow(targetNode).set(CyNetwork.NAME, target);
            nMap.put(target, subNetwork.getRootNetwork().getNode(targetNode.getSUID()));
        }
        // Add the sourceNode and targetNode to subNetwork
        if (!subNetwork.containsNode(sourceNode)) {
            subNetwork.addNode(sourceNode);
        }
        if (!subNetwork.containsNode(targetNode)) {
            subNetwork.addNode(targetNode);
        }
        final CyEdge edge = subNetwork.addEdge(sourceNode, targetNode, true);
        subNetwork.getRow(edge).set(CyNetwork.NAME, getEdgeName(itr, target));
        subNetwork.getRow(edge).set(CyEdge.INTERACTION, itr.getType());
    }
}
Also used : CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge)

Example 24 with CyEdge

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

the class HandleGraphDone method handle.

@Override
public ParseState handle(String tag, Attributes atts, ParseState current) throws SAXException {
    graphDone();
    // End of document?
    if (manager.graphDoneCount != manager.graphCount)
        return current;
    // Resolve any unresolved node and edge references
    Map<CyNetwork, Set<Long>> nodeMap = manager.getCache().getNodeLinks();
    for (Map.Entry<CyNetwork, Set<Long>> entry : nodeMap.entrySet()) {
        CyNetwork net = entry.getKey();
        Set<Long> ids = entry.getValue();
        if (net != null && ids != null && !ids.isEmpty()) {
            if (net instanceof CySubNetwork) {
                final CySubNetwork sn = (CySubNetwork) net;
                for (Long id : ids) {
                    CyNode n = manager.getCache().getNode(id);
                    if (n != null)
                        sn.addNode(n);
                    else
                        logger.error("Cannot find XLink node with id \"" + id + "\".");
                }
            } else {
                logger.error("Cannot add existing nodes \"" + ids.toArray() + "\" to a network which is not a CySubNetwork");
            }
        }
    }
    // TODO: refactor
    Map<CyNetwork, Set<Long>> edgeMap = manager.getCache().getEdgeLinks();
    for (Map.Entry<CyNetwork, Set<Long>> entry : edgeMap.entrySet()) {
        CyNetwork net = entry.getKey();
        Set<Long> ids = entry.getValue();
        if (net != null && ids != null && !ids.isEmpty()) {
            if (net instanceof CySubNetwork) {
                final CySubNetwork sn = (CySubNetwork) net;
                for (Long id : ids) {
                    final CyEdge e = manager.getCache().getEdge(id);
                    if (e != null)
                        sn.addEdge(e);
                    else
                        logger.error("Cannot find XLink edge with id \"" + id + "\".");
                }
            } else {
                logger.error("Cannot add existing edges \"" + ids.toArray() + "\" to a network which is not a CySubNetwork");
            }
        }
    }
    manager.getCache().deleteUnresolvedNodes();
    resolveEquations();
    resolveNetworkPointers();
    updateSUIDAttributes();
    // TODO: we should not create (and specially register) groups here!
    createGroups();
    return ParseState.NONE;
}
Also used : Set(java.util.Set) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) Map(java.util.Map) CyEdge(org.cytoscape.model.CyEdge) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork)

Example 25 with CyEdge

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

the class NewNetworkSelectedNodesOnlyTaskTest method testNewNetworkSelectedNodesOnlyTask.

@Test
public void testNewNetworkSelectedNodesOnlyTask() throws Exception {
    final UndoSupport undoSupport = mock(UndoSupport.class);
    netmgr.addNetwork(net);
    final CyNode node1 = net.addNode();
    final CyNode node2 = net.addNode();
    final CyNode node3 = net.addNode();
    final CyEdge edge1 = net.addEdge(node1, node2, true);
    // final CyEdge edge2 = net.addEdge(node2, node3, true);
    net.getRow(node1).set(CyNetwork.SELECTED, true);
    // net.getRow(node2).set(CyNetwork.SELECTED, true);
    net.getRow(edge1).set(CyNetwork.SELECTED, true);
    int numberOfNetsBeforeTask = netmgr.getNetworkSet().size();
    List<CyNetwork> netListbeforeTask = new ArrayList<CyNetwork>(netmgr.getNetworkSet());
    final NewNetworkSelectedNodesOnlyTask task = new NewNetworkSelectedNodesOnlyTask(undoSupport, net, cyroot, cnvf, netmgr, networkViewManager, cyNetworkNaming, vmm, appManager, eventHelper, groupMgr, renderingEngineManager, serviceRegistrar);
    assertNotNull("task is null!", task);
    task.setTaskIterator(new TaskIterator(task));
    task.run(mock(TaskMonitor.class));
    int numberOfNetsAfterTask = netmgr.getNetworkSet().size();
    assertEquals(1, numberOfNetsAfterTask - numberOfNetsBeforeTask);
    List<CyNetwork> networkList = new ArrayList<CyNetwork>(netmgr.getNetworkSet());
    networkList.removeAll(netListbeforeTask);
    assertEquals(1, networkList.get(0).getNodeList().size());
    assertEquals(0, networkList.get(0).getEdgeList().size());
}
Also used : TaskIterator(org.cytoscape.work.TaskIterator) TaskMonitor(org.cytoscape.work.TaskMonitor) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) UndoSupport(org.cytoscape.work.undo.UndoSupport) CyEdge(org.cytoscape.model.CyEdge) Test(org.junit.Test)

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