use of org.cytoscape.model.CyEdge in project EnrichmentMapApp by BaderLab.
the class TestUtils method getSignatureEdges.
public static Map<String, CyEdge> getSignatureEdges(CyNetwork network, String prefix, String sigSetName) {
Map<String, CyEdge> edges = new HashMap<>();
for (CyEdge edge : network.getEdgeList()) {
CyRow row = network.getRow(edge);
String sigName = Columns.EDGE_SIG_DATASET.get(row, prefix);
if (sigName != null && sigName.equals(sigSetName)) {
edges.put(row.get(CyNetwork.NAME, String.class), edge);
}
}
return edges;
}
use of org.cytoscape.model.CyEdge in project cytoscape-impl by cytoscape.
the class CloneNetworkTask method cloneEdge.
private CyEdge cloneEdge(final CyNetwork origNet, final CyNetwork newNet, final CyEdge origEdge) {
if (orig2NewEdgeMap.containsKey(origEdge))
return orig2NewEdgeMap.get(origEdge);
final CyNode newSource = orig2NewNodeMap.get(origEdge.getSource());
final CyNode newTarget = orig2NewNodeMap.get(origEdge.getTarget());
final boolean newDirected = origEdge.isDirected();
final CyEdge newEdge = newNet.addEdge(newSource, newTarget, newDirected);
new2OrigEdgeMap.put(newEdge, origEdge);
orig2NewEdgeMap.put(origEdge, newEdge);
cloneRow(newNet, CyEdge.class, origNet.getRow(origEdge, CyNetwork.LOCAL_ATTRS), newNet.getRow(newEdge, CyNetwork.LOCAL_ATTRS));
cloneRow(newNet, CyEdge.class, origNet.getRow(origEdge, CyNetwork.HIDDEN_ATTRS), newNet.getRow(newEdge, CyNetwork.HIDDEN_ATTRS));
return newEdge;
}
use of org.cytoscape.model.CyEdge in project cytoscape-impl by cytoscape.
the class GroupUtils method addGroupToNetwork.
public static void addGroupToNetwork(CyGroup group, CyNetwork origNet, CyNetwork newNet) {
CyNetwork groupNetwork = group.getGroupNetwork();
Dimension d = getPosition(origNet, group, groupNetwork.getSUID(), CyNetwork.class);
updatePosition(newNet, group, groupNetwork.getSUID(), CyNetwork.class, d);
for (CyNode node : group.getNodeList()) {
Long nodeSUID = node.getSUID();
d = getPosition(origNet, group, nodeSUID, CyNode.class);
updatePosition(newNet, group, nodeSUID, CyNode.class, d);
// This helps out collapse
((CySubNetwork) newNet).addNode(node);
}
for (CyEdge edge : group.getInternalEdgeList()) {
// This helps out collapse
((CySubNetwork) newNet).addEdge(edge);
}
for (CyEdge edge : group.getExternalEdgeList()) {
// This helps out collapse
((CySubNetwork) newNet).addEdge(edge);
}
group.addGroupToNetwork(newNet);
group.collapse(newNet);
}
use of org.cytoscape.model.CyEdge in project cytoscape-impl by cytoscape.
the class AddEdgeTask method run.
@Override
public void run(final TaskMonitor taskMonitor) {
if (network == null) {
network = serviceRegistrar.getService(CyApplicationManager.class).getCurrentNetwork();
if (network == null) {
taskMonitor.showMessage(TaskMonitor.Level.ERROR, "Network must be specified for add command");
return;
}
}
if (sourceName == null) {
taskMonitor.showMessage(TaskMonitor.Level.ERROR, "Source node name must be specified for add command");
return;
}
if (targetName == null) {
taskMonitor.showMessage(TaskMonitor.Level.ERROR, "Target node name must be specified for add command");
return;
}
// Find the source and target nodes
CyNode source = null;
CyNode target = null;
for (CyNode node : network.getNodeList()) {
String nodeName = network.getRow(node).get(CyNetwork.NAME, String.class);
if (sourceName.equals(nodeName))
source = node;
else if (targetName.equals(nodeName))
target = node;
if (source != null && target != null)
break;
}
if (source == null) {
taskMonitor.showMessage(TaskMonitor.Level.ERROR, "Can't find source node named '" + sourceName + "'");
return;
}
if (target == null) {
taskMonitor.showMessage(TaskMonitor.Level.ERROR, "Can't find target node named '" + targetName + "'");
return;
}
newEdge = network.addEdge(source, target, isDirected);
if (name != null) {
network.getRow(newEdge).set(CyNetwork.NAME, name);
network.getRow(newEdge).set(CyRootNetwork.SHARED_NAME, name);
}
cyEventHelper.flushPayloadEvents();
if (networkViewManager.viewExists(network)) {
for (CyNetworkView view : networkViewManager.getNetworkViews(network)) {
View<CyEdge> edgeView = view.getEdgeView(newEdge);
VisualStyle style = visualMappingManager.getVisualStyle(view);
if (style != null) {
style.apply(network.getRow(newEdge), edgeView);
}
// Not sure why we need to refresh the view for edges and not nodes, but apparently we do
view.updateView();
}
}
cyEventHelper.flushPayloadEvents();
taskMonitor.showMessage(TaskMonitor.Level.INFO, "Added edge " + newEdge.toString() + " to network");
}
use of org.cytoscape.model.CyEdge in project cytoscape-impl by cytoscape.
the class AddTask method run.
@Override
public void run(final TaskMonitor taskMonitor) {
network = nodesAndEdges.getNetwork();
if (network == null) {
taskMonitor.showMessage(TaskMonitor.Level.ERROR, "Network must be specified for add command");
return;
}
nodeList = nodesAndEdges.getNodeList(false);
edgeList = nodesAndEdges.getEdgeList(false);
if ((nodeList == null || nodeList.size() == 0) && (edgeList == null || edgeList.size() == 0)) {
taskMonitor.showMessage(TaskMonitor.Level.WARN, "Nothing to add");
return;
}
int nodeCount = nodeList.size();
int edgeCount = 0;
for (CyNode node : nodeList) ((CySubNetwork) network).addNode(node);
// nodes and "all" edges
for (CyEdge edge : edgeList) {
if (network.containsNode(edge.getSource()) && network.containsNode(edge.getTarget())) {
((CySubNetwork) network).addEdge(edge);
edgeCount++;
}
}
eventHelper.flushPayloadEvents();
taskMonitor.showMessage(TaskMonitor.Level.INFO, "Added " + nodeCount + " nodes and " + edgeCount + " edges to network " + network.toString());
}
Aggregations