use of org.cytoscape.model.subnetwork.CySubNetwork 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.CySubNetwork 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.subnetwork.CySubNetwork 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());
}
use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.
the class Cy2SessionReaderImpl method extractNetworksAndViews.
/**
* @param is
* @param entryName
* @param parent
* @param createView
* @return The top-level network that was extracted from the XGMML file.
* @throws Exception
*/
private CyNetwork extractNetworksAndViews(final InputStream is, final String entryName, final CyNetwork parent, final boolean createView) throws Exception {
CyNetwork topNetwork = null;
final CyNetworkReader reader = networkReaderMgr.getReader(is, entryName);
if (parent != null) {
if (reader instanceof SessionXGMMLNetworkReader) {
((SessionXGMMLNetworkReader) reader).setParent(parent);
} else {
logger.error("CyNetworkReader should be an instance of XGMMLNetworkReader. " + "Cannot extract network as sub-nertwork of: " + entryName);
}
}
reader.run(taskMonitor);
final CyNetwork[] netArray = reader.getNetworks();
if (netArray != null && netArray.length > 0) {
topNetwork = netArray[0];
for (int i = 0; i < netArray.length; i++) {
// Process each CyNetwork
final CyNetwork net = netArray[i];
final String netName = net.getRow(net).get(CyNetwork.NAME, String.class);
networkLookup.put(netName, net);
// Add parent network attribute to a column in the hidden table,
// to preserve the network hierarchy info from Cytoscape 2.x
final CyRow hRow = net.getRow(net, CyNetwork.HIDDEN_ATTRS);
final CyTable hTbl = hRow.getTable();
if (parent instanceof CySubNetwork) {
if (hTbl.getColumn(CY3_PARENT_NETWORK_COLUMN) == null)
hTbl.createColumn(CY3_PARENT_NETWORK_COLUMN, Long.class, false);
hRow.set(CY3_PARENT_NETWORK_COLUMN, parent.getSUID());
}
final CyTable tbl = net.getRow(net, CyNetwork.LOCAL_ATTRS).getTable();
// (e.g. the user imported a Cy3 XGMML that contains this attribute into Cy2)
if (tbl.getColumn(CY2_PARENT_NETWORK_COLUMN) != null && parent instanceof CySubNetwork == false)
tbl.deleteColumn(CY2_PARENT_NETWORK_COLUMN);
// Restore node/edge selection
List<Node> selNodes = nodeSelectionLookup.get(netName);
List<Edge> selEdges = edgeSelectionLookup.get(netName);
if (selNodes != null)
setBooleanNodeAttr(net, selNodes, SELECTED, DEFAULT_ATTRS);
if (selEdges != null)
setBooleanEdgeAttr(net, selEdges, SELECTED, DEFAULT_ATTRS);
networks.add(net);
if (!cancelled && i == 0 && createView) {
// Create a network view for the first network only,
// which is supposed to be the top-level one
final CyNetworkView view = reader.buildCyNetworkView(net);
networkViewLookup.put(netName, view);
networkViews.add(view);
cache.cache(netName, view);
}
}
}
return topNetwork;
}
use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.
the class HandleGraphDone method handle.
@Override
public ParseState handle(String tag, Attributes atts, ParseState current) throws SAXException {
graphDone();
// End of document?
if (manager.graphDoneCount != manager.graphCount)
return current;
// Resolve any unresolved node and edge references
Map<CyNetwork, Set<Long>> nodeMap = manager.getCache().getNodeLinks();
for (Map.Entry<CyNetwork, Set<Long>> entry : nodeMap.entrySet()) {
CyNetwork net = entry.getKey();
Set<Long> ids = entry.getValue();
if (net != null && ids != null && !ids.isEmpty()) {
if (net instanceof CySubNetwork) {
final CySubNetwork sn = (CySubNetwork) net;
for (Long id : ids) {
CyNode n = manager.getCache().getNode(id);
if (n != null)
sn.addNode(n);
else
logger.error("Cannot find XLink node with id \"" + id + "\".");
}
} else {
logger.error("Cannot add existing nodes \"" + ids.toArray() + "\" to a network which is not a CySubNetwork");
}
}
}
// TODO: refactor
Map<CyNetwork, Set<Long>> edgeMap = manager.getCache().getEdgeLinks();
for (Map.Entry<CyNetwork, Set<Long>> entry : edgeMap.entrySet()) {
CyNetwork net = entry.getKey();
Set<Long> ids = entry.getValue();
if (net != null && ids != null && !ids.isEmpty()) {
if (net instanceof CySubNetwork) {
final CySubNetwork sn = (CySubNetwork) net;
for (Long id : ids) {
final CyEdge e = manager.getCache().getEdge(id);
if (e != null)
sn.addEdge(e);
else
logger.error("Cannot find XLink edge with id \"" + id + "\".");
}
} else {
logger.error("Cannot add existing edges \"" + ids.toArray() + "\" to a network which is not a CySubNetwork");
}
}
}
manager.getCache().deleteUnresolvedNodes();
resolveEquations();
resolveNetworkPointers();
updateSUIDAttributes();
// TODO: we should not create (and specially register) groups here!
createGroups();
return ParseState.NONE;
}
Aggregations