use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.
the class DestroyNetworkTask method destroyNetwork.
private void destroyNetwork(final CyNetwork net, CyNetworkManager netManager) {
CyRootNetwork rootNet = null;
CySubNetwork parentNet = null;
if (net instanceof CySubNetwork) {
rootNet = ((CySubNetwork) net).getRootNetwork();
final Long suid = DataUtils.getParentNetworkSUID((CySubNetwork) net);
if (suid != null && netManager.getNetwork(suid) instanceof CySubNetwork)
parentNet = (CySubNetwork) netManager.getNetwork(suid);
}
netManager.destroyNetwork(net);
if (net instanceof CySubNetwork)
updateParentNetworkData(net.getSUID(), rootNet, (parentNet != null ? parentNet.getSUID() : null));
}
use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.
the class AbstractSessionReader method cleanUp.
/**
* Use this methods to dispose temporary resources.
* This method must always be invoked, even if this task is cancelled.
*/
protected void cleanUp(TaskMonitor tm) {
try {
((ReusableInputStream) sourceInputStream).reallyClose();
} catch (Exception e) {
logger.error("Error closing source input stream.", e);
}
if (cancelled) {
// Destroy groups
final Set<CyGroup> groups = groupUtil.getGroups(cache.getNetworks());
groupUtil.destroyGroups(groups);
// Dispose CyNetworkViews and CyNetworks
for (final CyNetworkView view : networkViews) view.dispose();
final CyRootNetworkManager rootNetworkManager = serviceRegistrar.getService(CyRootNetworkManager.class);
final Set<CyRootNetwork> rootNetworks = new HashSet<>();
// such as group networks.
for (final CyNetwork net : cache.getNetworks()) {
net.dispose();
rootNetworks.add(rootNetworkManager.getRootNetwork(net));
}
for (final CyRootNetwork rootNet : rootNetworks) rootNet.dispose();
networkViews.clear();
networks.clear();
}
cache.dispose();
SessionUtil.setReadingSessionFile(false);
}
use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.
the class HandleGraph method handleCy2ModelAndView.
/**
* Handles XGMML from Cytoscape 2.x session files only.
* @param tag
* @param atts
* @param current
* @return
* @throws SAXException
*/
private ParseState handleCy2ModelAndView(String tag, Attributes atts, ParseState current) throws SAXException {
final CyRootNetwork parent = manager.getParentNetwork();
final CyNetwork currentNet;
if (manager.graphCount == 1) {
// Root (graph) element...
if (parent == null) {
// This is a regular top-level network...
final CyRootNetwork rootNet = manager.createRootNetwork();
currentNet = rootNet.getBaseNetwork();
} else {
// This is a 2.x "child-network"...
currentNet = parent.addSubNetwork();
}
} else {
// Nested graph tag...
final CyRootNetwork rootNet = manager.getRootNetwork();
currentNet = rootNet.addSubNetwork();
}
// This is the network ID in 2.x
final String id = getLabel(atts);
addCurrentNetwork(id, currentNet, atts, true);
return current;
}
use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.
the class HandleGraph method setNetworkName.
/**
* Should be used when handling 2.x format only or importing the network from a standalone XGMML file.
*/
protected void setNetworkName(CyNetwork net, Attributes atts) {
String name = getLabel(atts);
if (name == null || name.trim().isEmpty()) {
if (net instanceof CyRootNetwork) {
name = "Root-Network " + net.getSUID();
} else if (manager.graphCount == 1) {
name = "Network " + net.getSUID();
} else {
CyRootNetwork root = manager.getRootNetwork();
if (root != null) {
name = root.getBaseNetwork().getRow(root.getBaseNetwork()).get(CyNetwork.NAME, String.class);
if (name == null || name.trim().isEmpty())
name = root.getRow(root).get(CyNetwork.NAME, String.class);
}
}
if (name == null || name.trim().isEmpty())
name = "Network " + net.getSUID();
name += " - " + manager.graphCount;
}
if (net != null && name != null) {
CyRow netRow = net.getRow(net);
netRow.set(CyNetwork.NAME, name);
}
}
use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.
the class HandleNodeGraph method handle.
@Override
public ParseState handle(String tag, Attributes atts, ParseState current) throws SAXException {
manager.graphCount++;
final CyNode node = manager.getCurrentNode();
manager.getCompoundNodeStack().push(node);
final String href = atts.getValue(ReadDataManager.XLINK, "href");
Object netId = null;
CyNetwork network = null;
if (href != null) {
// The network has already been created
netId = AttributeValueUtil.getIdFromXLink(href);
if (netId == null)
logger.error("The node's network pointer will not be created: " + "the network ID cannot be parsed from the XLink reference.");
addCurrentNetwork(netId, network, atts, isRegistered(atts));
} else {
netId = getId(atts);
// Create network
final CyRootNetwork rootNet = manager.getRootNetwork();
network = rootNet.addSubNetwork();
netId = addCurrentNetwork(netId, network, atts, isRegistered(atts));
}
if (netId != null)
manager.getCache().addNetworkPointer(node, netId);
return current;
}
Aggregations