use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.
the class NetworkMainPanel method removeNetwork.
/**
* Remove a network from the panel.
*/
protected void removeNetwork(final CySubNetwork network) {
nameTables.values().removeAll(Collections.singletonList(network));
nodeEdgeTables.values().removeAll(Collections.singletonList(network));
invokeOnEDT(() -> {
final CyRootNetwork rootNet = network.getRootNetwork();
final RootNetworkPanel item = getRootNetworkPanel(rootNet);
if (item != null) {
item.removeItem(network);
if (item.isEmpty()) {
getRootNetworkListPanel().removeItem(rootNet);
nameTables.values().removeAll(Collections.singletonList(rootNet));
nodeEdgeTables.values().removeAll(Collections.singletonList(rootNet));
}
updateNetworkHeader();
}
});
}
use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.
the class NetworkMediator method handleEvent.
@Override
public void handleEvent(final NetworkAboutToBeDestroyedEvent e) {
if (e.getNetwork() instanceof CySubNetwork) {
CySubNetwork network = (CySubNetwork) e.getNetwork();
networkMainPanel.removeNetwork(network);
networkMainPanel.updateNodeEdgeCount();
CyRootNetwork rootNetwork = network.getRootNetwork();
if (rootNetwork.getSubNetworkList().size() == 1 && rootNetwork.equals(networkMainPanel.getCurrentNetwork())) {
networkMainPanel.setCurrentNetwork(null);
}
}
}
use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.
the class GenerateNetworkViewsTask method run.
@Override
public void run(final TaskMonitor taskMonitor) throws Exception {
final CyNetwork[] networks = viewReader.getNetworks();
if (networks == null || networks.length == 0)
return;
taskMonitor.setProgress(0.0);
final CyNetworkNaming networkNaming = serviceRegistrar.getService(CyNetworkNaming.class);
double numNets = (double) networks.length;
int i = 0;
results = new ArrayList<>();
largeNetworks = new ArrayList<>();
for (CyNetwork net : networks) {
// Use original name if exists
String networkName = net.getRow(net).get(CyNetwork.NAME, String.class);
if (networkName == null || networkName.trim().length() == 0)
networkName = (name != null) ? name : "? (Name is missing)";
net.getRow(net).set(CyNetwork.NAME, networkNaming.getSuggestedNetworkTitle(networkName));
serviceRegistrar.getService(CyNetworkManager.class).addNetwork(net, false);
final int numGraphObjects = net.getNodeCount() + net.getEdgeCount();
if (numGraphObjects < viewThreshold)
createNetworkView(net);
else
largeNetworks.add(net);
taskMonitor.setProgress((double) (++i) / numNets);
}
// If there is no name yet for the root network, set it the same as its base subnetwork
if (networks.length == 1) {
if (networks[0] instanceof CySubNetwork) {
CySubNetwork subnet = (CySubNetwork) networks[0];
final CyRootNetwork rootNet = subnet.getRootNetwork();
String rootNetName = rootNet.getRow(rootNet).get(CyNetwork.NAME, String.class);
if (rootNetName == null || rootNetName.trim().length() == 0) {
// The root network does not have a name yet, set it the same as the base subnetwork
rootNet.getRow(rootNet).set(CyNetwork.NAME, networks[0].getRow(networks[0]).get(CyNetwork.NAME, String.class));
}
}
}
// Make sure rootNetwork has a name
for (CyNetwork net : networks) {
if (net instanceof CySubNetwork) {
CySubNetwork subNet = (CySubNetwork) net;
CyRootNetwork rootNet = subNet.getRootNetwork();
String networkName = rootNet.getRow(rootNet).get(CyNetwork.NAME, String.class);
if (networkName == null || networkName.trim().length() == 0) {
networkName = name;
if (networkName == null)
networkName = "? (Name is missing)";
rootNet.getRow(rootNet).set(CyNetwork.NAME, networkNaming.getSuggestedNetworkTitle(networkName));
}
}
}
setCurrentNetworkAndViewTask(networks[0]);
if (!largeNetworks.isEmpty())
insertTasksAfterCurrentTask(new ConfirmCreateNetworkViewsTask(largeNetworks));
}
use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.
the class MergeTablesTask method initTunable.
private final void initTunable(final CyTableManager tabelMgr, final CyNetworkManager networkManager) {
final List<CyTable> listOfTables = new ArrayList<>();
final List<Object> listOfUTables = new ArrayList<>();
for (CyTable tempTable : tabelMgr.getGlobalTables()) {
if (tempTable.isPublic()) {
listOfTables.add(tempTable);
listOfUTables.add(tempTable);
}
}
final Set<CyNetwork> networkSet = networkManager.getNetworkSet();
if (!networkSet.isEmpty()) {
whereMergeTable = new ListSingleSelection<>(NETWORK_COLLECTION, NETWORK_SELECTION, UNASSIGNED_TABLE);
whereMergeTable.setSelectedValue(NETWORK_COLLECTION);
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 : networkSet) {
String netName = net.getRow(net).get(CyNetwork.NAME, String.class);
name2NetworkMap.put(netName, net);
}
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);
for (CyNetwork net : networkSet) {
final CyRootNetwork rootNet = rootNetworkManager.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));
targetKeyNetworkCollection = getKeyColumnList(name2RootMap.get(targetNetworkCollection.getSelectedValue()), dataTypeTargetForNetworkCollection.getSelectedValue(), CyRootNetwork.SHARED_ATTRS);
}
for (CyNetwork network : networkSet) {
listOfTables.add(network.getDefaultNodeTable());
listOfTables.add(network.getDefaultEdgeTable());
}
} else {
whereMergeTable = new ListSingleSelection<>(UNASSIGNED_TABLE);
whereMergeTable.setSelectedValue(UNASSIGNED_TABLE);
}
sourceTable = new ListSingleSelection<>(listOfTables);
if (!isTableGlobal(sourceTable.getSelectedValue())) {
mergeType = new ListSingleSelection<>(COPY_COLUMNS);
} else {
mergeType = new ListSingleSelection<>(COPY_COLUMNS, LINK_COLUMNS);
mergeType.setSelectedValue(COPY_COLUMNS);
}
sourceMergeColumns = getColumnList(sourceTable.getSelectedValue());
sourceMergeKey = getKeyColumnList(sourceTable.getSelectedValue());
if (listOfUTables.size() > 1) {
if (listOfUTables.contains(sourceTable.getSelectedValue()))
listOfUTables.remove(sourceTable.getSelectedValue());
unassignedTable = new ListSingleSelection<>(listOfUTables);
targetMergeKey = getKeyColumnList((CyTable) unassignedTable.getSelectedValue());
} else {
listOfUTables.clear();
listOfUTables.add(NO_TABLES);
targetMergeKey = new ListSingleSelection<>(NO_TABLES);
unassignedTable = new ListSingleSelection<>(listOfUTables);
}
}
use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.
the class GMLNetworkReader method run.
@Override
public void run(TaskMonitor taskMonitor) throws Exception {
taskMonitor.setProgress(0.0);
try {
keyVals = (new GMLParser(inputStream)).parseList();
} catch (Exception io) {
io.printStackTrace();
throw new RuntimeException(io.getMessage());
} finally {
if (inputStream != null) {
try {
inputStream.close();
inputStream = null;
} catch (Exception e) {
logger.warn("Cannot close GML input stream", e);
}
}
}
taskMonitor.setProgress(0.05);
initializeStructures();
taskMonitor.setProgress(0.1);
// read the GML file
readGML(keyVals, taskMonitor);
taskMonitor.setProgress(0.3);
final CyRootNetwork rootNetwork = getRootNetwork();
if (rootNetwork != null) {
this.network = rootNetwork.addSubNetwork();
} else {
// Need to create new network with new root.
this.network = (CySubNetwork) cyNetworkFactory.createNetwork();
}
createGraph(taskMonitor);
taskMonitor.setProgress(0.8);
this.networks = new CyNetwork[] { network };
taskMonitor.setProgress(1.0);
}
Aggregations