use of org.cytoscape.group.CyGroup in project cytoscape-impl by cytoscape.
the class GroupEdit method reGroup.
private CyGroup reGroup(CyGroup group) {
List<CyNetwork> netList = networkMap.get(group);
// network 0 is always the root network
CyNetwork firstNet = netList.get(1);
CyGroup newGroup = factory.createGroup(firstNet, nodeMap.get(group), edgesMap.get(group), true);
// It should be at least 2 (rootNetwork + initial network)
if (netList.size() > 2) {
for (int i = 2; i < netList.size(); i++) {
newGroup.addGroupToNetwork(netList.get(i));
}
}
for (CyNetwork net : collapseMap.get(group)) {
newGroup.collapse(net);
}
return newGroup;
}
use of org.cytoscape.group.CyGroup in project cytoscape-impl by cytoscape.
the class RemoveFromGroupTask method run.
@Override
public void run(TaskMonitor tm) throws Exception {
net = nodesAndEdges.getNetwork();
if (groupName == null) {
tm.showMessage(TaskMonitor.Level.ERROR, "Group must be specified");
return;
}
CyGroup grp = getGroup(groupName);
if (grp == null) {
tm.showMessage(TaskMonitor.Level.ERROR, "Can't find group '" + groupName + "' in network: " + net.toString());
return;
}
List<CyEdge> edgeList = nodesAndEdges.getEdgeList(false);
List<CyNode> nodeList = nodesAndEdges.getNodeList(false);
if (edgeList == null && nodeList == null) {
tm.showMessage(TaskMonitor.Level.ERROR, "Nothing to remove");
return;
}
int edges = 0;
if (edgeList != null)
edges = edgeList.size();
int nodes = 0;
if (nodeList != null)
nodes = nodeList.size();
tm.showMessage(TaskMonitor.Level.INFO, "Removing " + nodes + " nodes and " + edges + " edges from group " + getGroupDesc(grp));
if (edgeList != null && edgeList.size() > 0) {
grp.removeEdges(edgeList);
}
if (nodeList != null && nodeList.size() > 0) {
grp.removeNodes(nodeList);
}
tm.showMessage(TaskMonitor.Level.INFO, "Removed " + nodes + " nodes and " + edges + " edges from group " + getGroupDesc(grp));
}
use of org.cytoscape.group.CyGroup in project cytoscape-impl by cytoscape.
the class RenameGroupTask method run.
public void run(TaskMonitor tm) throws Exception {
if (network != null)
net = network;
if (groupName == null) {
tm.showMessage(TaskMonitor.Level.ERROR, "Group must be specified");
return;
}
if (newName == null) {
tm.showMessage(TaskMonitor.Level.ERROR, "New name must be specified");
return;
}
CyGroup grp = getGroup(groupName);
if (grp == null) {
tm.showMessage(TaskMonitor.Level.ERROR, "Can't find group '" + groupName + "' in network: " + net.toString());
return;
}
CyRow groupRow = ((CySubNetwork) net).getRootNetwork().getRow(grp.getGroupNode(), CyRootNetwork.SHARED_ATTRS);
String oldName = groupRow.get(CyRootNetwork.SHARED_NAME, String.class);
groupRow.set(CyRootNetwork.SHARED_NAME, newName);
tm.showMessage(TaskMonitor.Level.INFO, "Renamed group from " + oldName + " to " + newName);
}
use of org.cytoscape.group.CyGroup in project cytoscape-impl by cytoscape.
the class UnGroupNodesTask method run.
public void run(TaskMonitor tm) throws Exception {
tm.setProgress(0.0);
// Are we operating in a command-mode?
if (nodeTunable != null) {
net = nodeTunable.getNetwork();
groupSet = getGroups(net, nodeTunable.getNodeList());
}
GroupEdit edit = null;
if (undoSupport != null)
edit = new GroupEdit(net, groupMgr, factory, groupSet);
for (CyGroup group : groupSet) {
groupMgr.destroyGroup(group);
tm.setProgress(1.0d / (double) groupSet.size());
}
if (undoSupport != null)
undoSupport.postEdit(edit);
if (netView != null)
netView.updateView();
tm.showMessage(TaskMonitor.Level.INFO, "Ungrouped " + groupSet.size() + " groups");
tm.setProgress(1.0d);
}
use of org.cytoscape.group.CyGroup in project cytoscape-impl by cytoscape.
the class CyGroupImpl method addPartnerEdges.
// Find the edge in our partner that links to us
protected void addPartnerEdges(CyGroup metaPartner, CyNetwork net, Set<CyGroup> partnersSeen) {
Set<CyEdge> partnerEdges = metaPartner.getExternalEdgeList();
Set<CyEdge> newEdges = new HashSet<CyEdge>();
synchronized (lock) {
// XXX Performance hog XXX
for (CyEdge edge : partnerEdges) {
// System.out.println("Looking at partner edge: "+edge.toString());
CyNode source = edge.getSource();
CyNode target = edge.getTarget();
CyNode partner = null;
boolean directed = edge.isDirected();
if (getGroupNetwork().containsNode(target)) {
target = groupNode;
partner = source;
} else if (getGroupNetwork().containsNode(source)) {
source = groupNode;
partner = target;
} else {
continue;
}
if (source == target)
continue;
// Create a new edge
CyEdge newEdge = null;
if (!rootNetwork.containsEdge(source, target)) {
newEdge = rootNetwork.addEdge(source, target, directed);
newEdges.add(newEdge);
// System.out.println(" ... it points to us -- created new edge: "+newEdge.toString());
}
externalEdges.add(edge);
CyGroup partnerMeta = mgr.getGroup(partner, net);
if (partnerMeta != null && !partnersSeen.contains(partnerMeta)) {
// System.out.println("Adding partner edges for "+partnerMeta.toString());
partnersSeen.add(partnerMeta);
addPartnerEdges(partnerMeta, net, partnersSeen);
// System.out.println("Done adding partner edges for "+partnerMeta.toString());
}
if (newEdge != null)
addMetaEdge(edge, newEdge);
}
}
for (CyEdge edge : newEdges) {
((CyGroupImpl) metaPartner).addExternalEdge(edge);
}
}
Aggregations