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