use of org.cytoscape.model.CyNetworkManager in project cytoscape-impl by cytoscape.
the class CyApplicationManagerImpl method internalSetCurrentNetwork.
private void internalSetCurrentNetwork(CyNetwork network, List<CyEvent<?>> eventsToFire) {
final CyNetworkManager networkManager = serviceRegistrar.getService(CyNetworkManager.class);
if (network != null && !networkManager.networkExists(network.getSUID()))
throw new IllegalArgumentException("Network is not registered in this ApplicationManager: " + network);
boolean changed = (network == null && currentNetwork != null) || (network != null && !network.equals(currentNetwork));
if (changed) {
currentNetwork = network;
if (network != null) {
// If the new current network is not selected, reset the selection and select the current one only
if (!getSelectedNetworks().contains(network))
internalSetSelectedNetworks(Collections.singletonList(network), eventsToFire);
}
eventsToFire.add(new SetCurrentNetworkEvent(this, currentNetwork));
}
}
use of org.cytoscape.model.CyNetworkManager 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.CyNetworkManager in project cytoscape-impl by cytoscape.
the class OpenSessionTask method run.
/**
* Clear current session and open the cys file.
*/
@Override
public void run(final TaskMonitor taskMonitor) throws Exception {
final CyNetworkManager netManager = serviceRegistrar.getService(CyNetworkManager.class);
final CyTableManager tableManager = serviceRegistrar.getService(CyTableManager.class);
if (netManager.getNetworkSet().isEmpty() && tableManager.getAllTables(false).isEmpty())
loadSession(this);
else
insertTasksAfterCurrentTask(new OpenSessionWithWarningTask());
}
use of org.cytoscape.model.CyNetworkManager in project cytoscape-impl by cytoscape.
the class DeleteNestedNetworkTaskFactory method isReady.
@Override
public boolean isReady(View<CyNode> nodeView, CyNetworkView networkView) {
if (!super.isReady(nodeView, networkView))
return false;
// Check if there is a network pointer and if it is registered.
// Nodes with unregistered network pointers should be ignored because they are probably being used as something
// else other than regular nested networks (e.g. groups).
final CyNode node = nodeView.getModel();
final CyNetwork np = node.getNetworkPointer();
final CyNetwork network = networkView.getModel();
final CyNetworkManager netMgr = serviceRegistrar.getService(CyNetworkManager.class);
final CyGroupManager grMgr = serviceRegistrar.getService(CyGroupManager.class);
return np != null && netMgr.networkExists(np.getSUID()) && !grMgr.isGroup(node, network);
}
use of org.cytoscape.model.CyNetworkManager in project PhenomeScape by soulj.
the class LoadNetworkTask method run.
@Override
public void run(TaskMonitor taskMonitor) throws Exception {
taskMonitor.setTitle("Loading " + species + " Network");
taskMonitor.setStatusMessage("Creating network");
CyNetworkFactory networkFactory = cyServiceRegistrar.getService(CyNetworkFactory.class);
CyNetwork network = networkFactory.createNetwork();
network.getRow(network).set(CyNetwork.NAME, NetworkUtils.getUniqueNetworkName(cyServiceRegistrar, species + "Network"));
network.getDefaultEdgeTable().createColumn("Confidence", Double.class, false);
Map<String, CyNode> nodeNameMap = new HashMap<String, CyNode>();
Scanner sc = new Scanner(input);
nodeNameMap = new HashMap<String, CyNode>();
while (sc.hasNextLine()) {
String line = sc.nextLine();
String[] nodes = line.split("\t");
CyNode node1 = null;
CyNode node2 = null;
if (nodeNameMap.containsKey(nodes[0])) {
node1 = nodeNameMap.get(nodes[0]);
} else {
node1 = network.addNode();
CyRow attributes = network.getRow(node1);
attributes.set("name", nodes[0]);
nodeNameMap.put(nodes[0], node1);
}
if (nodeNameMap.containsKey(nodes[1])) {
node2 = (CyNode) nodeNameMap.get(nodes[1]);
} else {
node2 = network.addNode();
CyRow attributes = network.getRow(node2);
attributes.set("name", nodes[1]);
nodeNameMap.put(nodes[1], node2);
}
CyEdge myEdge = network.addEdge(node1, node2, false);
network.getRow(myEdge).set("interaction", "ppi");
network.getRow(myEdge).set("Confidence", Double.parseDouble(nodes[2]));
network.getRow(myEdge).set("name", nodes[0] + " (ppi) " + nodes[1]);
}
sc.close();
CyNetworkManager networkManager = cyServiceRegistrar.getService(CyNetworkManager.class);
networkManager.addNetwork(network);
}
Aggregations