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);
}
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);
}
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());
}
}
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;
}
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());
}
Aggregations