use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.
the class ReadDataManager method createRootNetwork.
protected CyRootNetwork createRootNetwork() {
if (this.rootNetwork != null)
return this.rootNetwork;
final CyNetworkFactory networkFactory = serviceRegistrar.getService(CyNetworkFactory.class);
final CyNetwork baseNet = networkFactory.createNetwork();
final CyRootNetworkManager rootNetworkManager = serviceRegistrar.getService(CyRootNetworkManager.class);
final CyRootNetwork rootNetwork = rootNetworkManager.getRootNetwork(baseNet);
return rootNetwork;
}
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;
}
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 SessionXGMMLNetworkWriterTest method testRootNetworkOnlySavedIfSessionSavePolicy.
@Test(expected = IllegalArgumentException.class)
public void testRootNetworkOnlySavedIfSessionSavePolicy() throws UnsupportedEncodingException {
CyRootNetwork newRoot = ((CySubNetwork) netFactory.createNetwork(SavePolicy.DO_NOT_SAVE)).getRootNetwork();
// Registering it doesn't make any difference
setRegistered(newRoot, true);
write(newRoot);
}
Aggregations