use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.
the class RootNetworkPanelModel method getSubNetworkCount.
@Override
public int getSubNetworkCount() {
int count = 0;
final CyNetworkManager netManager = serviceRegistrar.getService(CyNetworkManager.class);
// Count number of public subnetworks
for (CySubNetwork net : getNetwork().getSubNetworkList()) {
if (netManager.networkExists(net.getSUID()))
count++;
}
return count;
}
use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.
the class GenerateNetworkViewsTask method run.
@Override
public void run(final TaskMonitor taskMonitor) throws Exception {
final CyNetwork[] networks = viewReader.getNetworks();
if (networks == null || networks.length == 0)
return;
taskMonitor.setProgress(0.0);
final CyNetworkNaming networkNaming = serviceRegistrar.getService(CyNetworkNaming.class);
double numNets = (double) networks.length;
int i = 0;
results = new ArrayList<>();
largeNetworks = new ArrayList<>();
for (CyNetwork net : networks) {
// Use original name if exists
String networkName = net.getRow(net).get(CyNetwork.NAME, String.class);
if (networkName == null || networkName.trim().length() == 0)
networkName = (name != null) ? name : "? (Name is missing)";
net.getRow(net).set(CyNetwork.NAME, networkNaming.getSuggestedNetworkTitle(networkName));
serviceRegistrar.getService(CyNetworkManager.class).addNetwork(net, false);
final int numGraphObjects = net.getNodeCount() + net.getEdgeCount();
if (numGraphObjects < viewThreshold)
createNetworkView(net);
else
largeNetworks.add(net);
taskMonitor.setProgress((double) (++i) / numNets);
}
// If there is no name yet for the root network, set it the same as its base subnetwork
if (networks.length == 1) {
if (networks[0] instanceof CySubNetwork) {
CySubNetwork subnet = (CySubNetwork) networks[0];
final CyRootNetwork rootNet = subnet.getRootNetwork();
String rootNetName = rootNet.getRow(rootNet).get(CyNetwork.NAME, String.class);
if (rootNetName == null || rootNetName.trim().length() == 0) {
// The root network does not have a name yet, set it the same as the base subnetwork
rootNet.getRow(rootNet).set(CyNetwork.NAME, networks[0].getRow(networks[0]).get(CyNetwork.NAME, String.class));
}
}
}
// Make sure rootNetwork has a name
for (CyNetwork net : networks) {
if (net instanceof CySubNetwork) {
CySubNetwork subNet = (CySubNetwork) net;
CyRootNetwork rootNet = subNet.getRootNetwork();
String networkName = rootNet.getRow(rootNet).get(CyNetwork.NAME, String.class);
if (networkName == null || networkName.trim().length() == 0) {
networkName = name;
if (networkName == null)
networkName = "? (Name is missing)";
rootNet.getRow(rootNet).set(CyNetwork.NAME, networkNaming.getSuggestedNetworkTitle(networkName));
}
}
}
setCurrentNetworkAndViewTask(networks[0]);
if (!largeNetworks.isEmpty())
insertTasksAfterCurrentTask(new ConfirmCreateNetworkViewsTask(largeNetworks));
}
use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.
the class CloneNetworkTask method cloneGroups.
private void cloneGroups(final CyNetwork origNet, final CyNetwork newNet) {
// Get all of the groups in our original network
Set<CyGroup> origGroups = groupMgr.getGroupSet(origNet);
// edges
for (CyGroup origGroup : origGroups) {
if (origGroup.isCollapsed(origNet)) {
for (CyNode origNode : origGroup.getNodeList()) {
// add the node back into the network
((CySubNetwork) origNet).addNode(origNode);
cloneNode(origNet, newNet, origNode);
}
}
}
// Now, we can clone the group itself
for (CyGroup origGroup : origGroups) {
cloneGroup(origNet, newNet, origGroup);
}
}
use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.
the class GroupUtils method updateMetaEdgeInformation.
public static void updateMetaEdgeInformation(CyNetwork origNet, CyNetwork newNet, CyEdge origEdge, CyEdge newEdge) {
if (newEdge == null)
return;
CyRootNetwork newRoot = ((CySubNetwork) newNet).getRootNetwork();
CyRootNetwork origRoot = ((CySubNetwork) origNet).getRootNetwork();
CyTable newTable = newRoot.getTable(CyEdge.class, CyNetwork.HIDDEN_ATTRS);
if (newTable.getColumn(ISMETA_EDGE_ATTR) == null) {
newTable.createColumn(ISMETA_EDGE_ATTR, Boolean.class, false);
}
CyRow origRow = origRoot.getRow(origEdge, CyNetwork.HIDDEN_ATTRS);
if (origRow.isSet(ISMETA_EDGE_ATTR)) {
CyRow newRow = newTable.getRow(newEdge.getSUID());
Boolean isMeta = origRow.get(ISMETA_EDGE_ATTR, Boolean.class);
newRow.set(ISMETA_EDGE_ATTR, isMeta);
}
return;
}
use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.
the class CloneNetworkTask method cloneGroup.
private CyGroup cloneGroup(final CyNetwork origNet, final CyNetwork newNet, final CyGroup origGroup) {
List<CyNode> nodeList = new ArrayList<CyNode>();
List<CyEdge> edgeList = new ArrayList<CyEdge>();
// Check to see if the group node is already in the network
boolean groupNodeExists = origNet.containsNode(origGroup.getGroupNode());
boolean collapsed = origGroup.isCollapsed(origNet);
if (collapsed)
origGroup.expand(origNet);
else {
// If we're not collapsed, we need to clone the group node and it's edges
CyNode groupNode = origGroup.getGroupNode();
// If the node already exists, we shouldn't need to do anything
if (!groupNodeExists) {
((CySubNetwork) origNet).addNode(groupNode);
cloneNode(origNet, newNet, groupNode);
// Now remove it
((CySubNetwork) origNet).removeNodes(Collections.singletonList(groupNode));
// TODO: What about non-meta edges?
}
}
// Get the list of nodes for the group
for (CyNode node : origGroup.getNodeList()) {
nodeList.add(orig2NewNodeMap.get(node));
}
for (CyEdge iEdge : origGroup.getInternalEdgeList()) {
cloneEdge(origNet, newNet, iEdge);
}
for (CyEdge eEdge : origGroup.getExternalEdgeList()) {
cloneEdge(origNet, newNet, eEdge);
}
// Get the group node
CyNode newNode = orig2NewNodeMap.get(origGroup.getGroupNode());
// Copy our metaEdge information (if any), which is stored in the root network hidden table
cloneMetaEdgeInfo(origNet, newNet, origGroup);
// Create the group
CyGroup newGroup = groupFactory.createGroup(newNet, newNode, nodeList, null, true);
// We need to update all of our positions hints
cloneGroupTables(origNet, newNet, origGroup, newGroup);
if (!groupNodeExists) {
// Because we're providing a group node with a network pointer, the groups code
// is going to think we're coming from a session. We need to remove the group node
newNet.removeNodes(Collections.singletonList(newNode));
}
if (collapsed) {
// ...and collapse it...
origGroup.collapse(origNet);
newGroup.collapse(newNet);
}
return newGroup;
}
Aggregations