use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.
the class CyGroupImpl method destroyGroup.
/**
* Destroy this group. This will destroy the subnetwork, all metaEdges, and
* the group node (if we created it). This is meant to be called from the
* CyGroupManager, only.
*/
public void destroyGroup() {
final CySubNetwork groupNet = getGroupNetwork();
synchronized (lock) {
if (groupNet != null) {
for (CyNetwork net : networkSet) expand(net);
// Destroy the subNetwork
rootNetwork.removeSubNetwork(groupNet);
groupNode.setNetworkPointer(null);
}
// Release all of our external edges
externalEdges.clear();
if (groupNet != null) {
// Remove all of our metaEdges from the root network
rootNetwork.removeEdges(metaEdges.values());
metaEdges.clear();
// If our group node was not provided, destroy it if it doesn't have any member edges
if (!nodeProvided && rootNetwork.containsNode(groupNode) && memberEdges.size() == 0) {
for (CyNetwork net : networkSet) net.removeNodes(Collections.singletonList(groupNode));
rootNetwork.removeNodes(Collections.singletonList(groupNode));
}
}
networkSet.clear();
collapseSet.clear();
savedLocalValuesMap.clear();
savedHiddenValuesMap.clear();
}
cyEventHelper.flushPayloadEvents();
}
use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.
the class GroupViewCollapseHandler method addMemberEdges.
private void addMemberEdges(CyGroup group, CyNetwork network) {
CyRootNetwork rootNetwork = ((CySubNetwork) network).getRootNetwork();
CyNode groupNode = group.getGroupNode();
List<CyEdge> newEdges = new ArrayList<CyEdge>();
for (CyNode node : group.getNodeList()) {
if (!network.containsEdge(groupNode, node)) {
CyEdge edge = network.addEdge(groupNode, node, true);
CyRow edgeRow = network.getRow(edge);
CyRow edgeRootRow = rootNetwork.getRow(edge, CyRootNetwork.SHARED_ATTRS);
// Add a name
String name = getNodeName(groupNode, network) + " (member) " + getNodeName(node, network);
edgeRow.set(CyNetwork.NAME, name);
edgeRootRow.set(CyRootNetwork.SHARED_NAME, name);
// Set the interaction
edgeRow.set(CyEdge.INTERACTION, "member");
edgeRootRow.set(CyRootNetwork.SHARED_INTERACTION, "member");
newEdges.add(edge);
}
}
if (newEdges.size() > 0)
group.addEdges(newEdges);
}
use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.
the class GraphMLParser method createEdge.
private void createEdge(final Attributes atts) {
// Parse edge entry
final String currentEdgeSourceName = atts.getValue(SOURCE.getTag());
final String currentEdgeTargetName = atts.getValue(TARGET.getTag());
final CyNode sourceNode = (CyNode) nodeid2CyNodeMap.get(currentEdgeSourceName);
final CyNode targetNode = (CyNode) nodeid2CyNodeMap.get(currentEdgeTargetName);
if (networkStack.size() > 1) {
final CyNetwork rootNetwork = networkStack.get(0);
currentObject = rootNetwork.addEdge(sourceNode, targetNode, directed);
rootNetwork.getRow(currentObject).set(CyNetwork.NAME, currentEdgeSourceName + " (-) " + currentEdgeTargetName);
rootNetwork.getRow(currentObject).set(CyEdge.INTERACTION, "-");
for (CyNetwork network : networkStack) {
if (network != rootNetwork) {
((CySubNetwork) network).addEdge((CyEdge) currentObject);
}
}
} else {
try {
currentObject = currentNetwork.addEdge(sourceNode, targetNode, directed);
currentNetwork.getRow(currentObject).set(CyNetwork.NAME, currentEdgeSourceName + " (-) " + currentEdgeTargetName);
currentNetwork.getRow(currentObject).set(CyEdge.INTERACTION, "-");
} catch (Exception e) {
logger.warn("Edge entry ignored: " + currentEdgeSourceName + " (-) " + currentEdgeTargetName, e);
}
}
}
use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.
the class ImportTableDataTask method init.
private final void init() {
this.name2NetworkMap = new HashMap<>();
this.name2RootMap = new HashMap<>();
this.source2targetColumnMap = new HashMap<>();
this.mappedTables = new ArrayList<>();
final CyNetworkManager netMgr = serviceRegistrar.getService(CyNetworkManager.class);
if (netMgr.getNetworkSet().size() > 0) {
whereImportTable = new ListSingleSelection<>(NETWORK_COLLECTION, NETWORK_SELECTION, UNASSIGNED_TABLE);
whereImportTable.setSelectedValue(NETWORK_COLLECTION);
networksPresent = true;
} else {
whereImportTable = new ListSingleSelection<>(UNASSIGNED_TABLE);
whereImportTable.setSelectedValue(UNASSIGNED_TABLE);
}
if (byReader) {
if (reader != null && reader.getTables() != null)
newTableName = reader.getTables()[0].getTitle();
} else
newTableName = globalTable.getTitle();
if (networksPresent) {
final List<TableType> options = new ArrayList<>();
for (TableType type : TableType.values()) options.add(type);
dataTypeTargetForNetworkCollection = new ListSingleSelection<>(options);
dataTypeTargetForNetworkCollection.setSelectedValue(TableType.NODE_ATTR);
dataTypeTargetForNetworkList = new ListSingleSelection<>(options);
dataTypeTargetForNetworkList.setSelectedValue(TableType.NODE_ATTR);
for (CyNetwork net : netMgr.getNetworkSet()) {
final String netName = net.getRow(net).get(CyNetwork.NAME, String.class);
name2NetworkMap.put(netName, net);
}
final CyApplicationManager appMgr = serviceRegistrar.getService(CyApplicationManager.class);
final List<String> names = new ArrayList<>();
names.addAll(name2NetworkMap.keySet());
sort(names);
if (names.isEmpty()) {
targetNetworkList = new ListMultipleSelection<>(NO_NETWORKS);
} else {
targetNetworkList = new ListMultipleSelection<>(names);
final CyNetwork currNet = appMgr.getCurrentNetwork();
if (currNet != null) {
final String currName = currNet.getRow(currNet).get(CyNetwork.NAME, String.class);
if (currName != null && targetNetworkList.getPossibleValues().contains(currName))
targetNetworkList.setSelectedValues(Collections.singletonList(currName));
}
final List<CyNetwork> selectedNetworks = new ArrayList<>();
for (String netName : targetNetworkList.getSelectedValues()) {
if (name2NetworkMap.containsKey(netName))
selectedNetworks.add(name2NetworkMap.get(netName));
}
keyColumnForMappingNetworkList = getColumns(selectedNetworks, dataTypeTargetForNetworkList.getSelectedValue(), CyRootNetwork.DEFAULT_ATTRS);
}
final CyRootNetworkManager rootNetMgr = serviceRegistrar.getService(CyRootNetworkManager.class);
for (CyNetwork net : netMgr.getNetworkSet()) {
final CyRootNetwork rootNet = rootNetMgr.getRootNetwork(net);
if (!name2RootMap.containsValue(rootNet))
name2RootMap.put(rootNet.getRow(rootNet).get(CyRootNetwork.NAME, String.class), rootNet);
}
final List<String> rootNames = new ArrayList<>();
rootNames.addAll(name2RootMap.keySet());
sort(rootNames);
targetNetworkCollection = new ListSingleSelection<>(rootNames);
if (!rootNames.isEmpty()) {
targetNetworkCollection.setSelectedValue(rootNames.get(0));
final CyNetwork currNet = appMgr.getCurrentNetwork();
final CyRootNetwork currRootNet = currNet instanceof CySubNetwork ? rootNetMgr.getRootNetwork(currNet) : null;
if (currRootNet != null) {
final String currName = currRootNet.getRow(currRootNet).get(CyNetwork.NAME, String.class);
if (currName != null && targetNetworkCollection.getPossibleValues().contains(currName))
targetNetworkCollection.setSelectedValue(currName);
}
keyColumnForMapping = getColumns(Collections.singletonList(name2RootMap.get(targetNetworkCollection.getSelectedValue())), dataTypeTargetForNetworkCollection.getSelectedValue(), CyRootNetwork.SHARED_ATTRS);
}
}
}
use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.
the class ClipboardImpl method pasteNode.
// TODO: Need to figure out how to copy LOCAL_ATTRS, SHARED_ATTRS, and HIDDEN_ATTRS
// The latter is easy. The second two are both part of the DEFAULT_ATTRS, but it's
// not clear how to create a local attribute specifically....
private CyNode pasteNode(CyNetworkView sourceView, CyNetworkView targetView, CyNode node, Map<CyRow, CyRow> rowMap) {
CyNetwork sourceNetwork = sourceView.getModel();
CyRootNetwork sourceRoot = ((CySubNetwork) sourceNetwork).getRootNetwork();
CySubNetwork targetNetwork = (CySubNetwork) targetView.getModel();
CyRootNetwork targetRoot = targetNetwork.getRootNetwork();
CyNode newNode = null;
// 3) We're copying nodes to a new location in the same network
if (sourceRoot != targetRoot) {
// Case 1: Different roots
newNode = targetNetwork.addNode();
// Copy the attributes over
rowMap.put(oldSharedRowMap.get(node), targetNetwork.getRow(newNode, CyNetwork.DEFAULT_ATTRS));
rowMap.put(oldLocalRowMap.get(node), targetNetwork.getRow(newNode, CyNetwork.LOCAL_ATTRS));
rowMap.put(oldHiddenRowMap.get(node), targetNetwork.getRow(newNode, CyNetwork.HIDDEN_ATTRS));
} else if (!targetNetwork.containsNode(node)) {
// Case 2: different subnetwork, same root
targetNetwork.addNode(node);
newNode = node;
// rowMap.put(oldSharedRowMap.get(node), targetNetwork.getRow(newNode, CyNetwork.DEFAULT_ATTRS));
rowMap.put(oldLocalRowMap.get(node), targetNetwork.getRow(newNode, CyNetwork.LOCAL_ATTRS));
rowMap.put(oldHiddenRowMap.get(node), targetNetwork.getRow(newNode, CyNetwork.HIDDEN_ATTRS));
} else {
// Case 3: Copying the node to the same network
// newNode = targetNetwork.addNode();
// Copy in the hidden attributes
newNode = targetNetwork.addNode();
rowMap.put(oldHiddenRowMap.get(node), targetNetwork.getRow(newNode, CyNetwork.HIDDEN_ATTRS));
// Copy in the local attributes
rowMap.put(oldLocalRowMap.get(node), targetNetwork.getRow(newNode, CyNetwork.LOCAL_ATTRS));
// Copy in the default attributes
// rowMap.put(oldSharedRowMap.get(node), targetNetwork.getRow(newNode, CyNetwork.DEFAULT_ATTRS));
// targetNetwork.addNode(node);
}
return newNode;
}
Aggregations