use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-api by cytoscape.
the class AbstractCyNetworkReader method init.
private void init() {
name2RootMap = getRootNetworkMap();
nodeMap = new HashMap<>(10000);
// initialize the network Collection
final List<String> rootNames = new ArrayList<>();
rootNames.addAll(name2RootMap.keySet());
if (!rootNames.isEmpty()) {
sort(rootNames);
rootNames.add(0, CREATE_NEW_COLLECTION_STRING);
}
final ListSingleSelection<String> rootNetList = new ListSingleSelection<>(rootNames);
final CyNetwork net = cyApplicationManager != null ? cyApplicationManager.getCurrentNetwork() : null;
final CyRootNetwork rootNet = net != null ? cyRootNetworkManager.getRootNetwork(net) : null;
final String name = rootNet != null ? rootNet.getRow(rootNet).get(CyRootNetwork.NAME, String.class) : CREATE_NEW_COLLECTION_STRING;
if (rootNames.contains(name))
rootNetList.setSelectedValue(name);
else if (rootNames.contains(CREATE_NEW_COLLECTION_STRING))
rootNetList.setSelectedValue(CREATE_NEW_COLLECTION_STRING);
setRootNetworkList(rootNetList);
// initialize renderer list
final List<NetworkViewRenderer> renderers = new ArrayList<>();
NetworkViewRenderer defViewRenderer = null;
if (cyApplicationManager != null) {
final Set<NetworkViewRenderer> rendererSet = cyApplicationManager.getNetworkViewRendererSet();
// so the combo-box does not appear to the user, since there is nothing to select anyway.
if (rendererSet.size() > 1) {
renderers.addAll(rendererSet);
Collections.sort(renderers, new Comparator<NetworkViewRenderer>() {
@Override
public int compare(NetworkViewRenderer r1, NetworkViewRenderer r2) {
return r1.toString().compareToIgnoreCase(r2.toString());
}
});
}
defViewRenderer = cyApplicationManager.getDefaultNetworkViewRenderer();
}
rendererList = new ListSingleSelection<>(renderers);
if (defViewRenderer != null && renderers.contains(defViewRenderer))
rendererList.setSelectedValue(defViewRenderer);
}
use of org.cytoscape.model.subnetwork.CyRootNetwork in project clusterMaker2 by RBVI.
the class RankingPanel method createClusterImage.
/**
* Convert a network to an image. This is used by the MCODEResultsPanel.
*
* @param cluster Input network to convert to an image
* @param height Height that the resulting image should be
* @param width Width that the resulting image should be
* @param layouter Reference to the layout algorithm
* @param layoutNecessary Determinant of cluster size growth or shrinkage, the former requires layout
* @return The resulting image
*/
public Image createClusterImage(final NodeCluster cluster, final int height, final int width, SpringEmbeddedLayouter layouter, boolean layoutNecessary) {
// System.out.println("CCI: inside method");
final CyRootNetwork root = clusterManager.getService(CyRootNetworkManager.class).getRootNetwork(network);
// need to create a method get the subnetwork for a cluster
final CyNetwork net = cluster.getSubNetwork(network, root, SavePolicy.DO_NOT_SAVE);
// System.out.println("CCI: after getting root and network ");
// Progress reporters.
// There are three basic tasks, the progress of each is calculated and then combined
// using the respective weighting to get an overall progress global progress
// setting up the nodes and edges is deemed as 25% of the whole task
int weightSetupNodes = 20;
int weightSetupEdges = 5;
// layout it is 70%
double weightLayout = 75.0;
double goalTotal = weightSetupNodes + weightSetupEdges;
if (layoutNecessary) {
goalTotal += weightLayout;
}
// keeps track of progress as a percent of the totalGoal
double progress = 0;
final VisualStyle vs = getClusterStyle();
// System.out.println("CCI: after getClusterStyle");
final CyNetworkView clusterView = createNetworkView(net, vs);
// System.out.println("CCI: after createNetworkView");
clusterView.setVisualProperty(NETWORK_WIDTH, new Double(width));
clusterView.setVisualProperty(NETWORK_HEIGHT, new Double(height));
for (View<CyNode> nv : clusterView.getNodeViews()) {
if (interrupted) {
// problems the next time around
if (layouter != null)
layouter.resetDoLayout();
resetLoading();
return null;
}
// Node position
final double x;
final double y;
// first prevents the program from throwing a null pointer exception in the second condition)
if (cluster.getView() != null && cluster.getView().getNodeView(nv.getModel()) != null) {
// If it does, then we take the layout position that was already generated for it
x = cluster.getView().getNodeView(nv.getModel()).getVisualProperty(NODE_X_LOCATION);
y = cluster.getView().getNodeView(nv.getModel()).getVisualProperty(NODE_Y_LOCATION);
} else {
// Otherwise, randomize node positions before layout so that they don't all layout in a line
// (so they don't fall into a local minimum for the SpringEmbedder)
// If the SpringEmbedder implementation changes, this code may need to be removed
// size is small for many default drawn graphs, thus +100
x = (clusterView.getVisualProperty(NETWORK_WIDTH) + 100) * Math.random();
y = (clusterView.getVisualProperty(NETWORK_HEIGHT) + 100) * Math.random();
if (!layoutNecessary) {
goalTotal += weightLayout;
progress /= (goalTotal / (goalTotal - weightLayout));
layoutNecessary = true;
}
}
nv.setVisualProperty(NODE_X_LOCATION, x);
nv.setVisualProperty(NODE_Y_LOCATION, y);
// Might be specific to MCODE
/*
// Node shape
if (cluster.getSeedNode() == nv.getModel().getSUID()) {
nv.setLockedValue(NODE_SHAPE, NodeShapeVisualProperty.RECTANGLE);
} else {
nv.setLockedValue(NODE_SHAPE, NodeShapeVisualProperty.ELLIPSE);
}
*/
/*
// Update loader
if (loader != null) {
progress += 100.0 * (1.0 / (double) clusterView.getNodeViews().size()) *
((double) weightSetupNodes / (double) goalTotal);
loader.setProgress((int) progress, "Setup: nodes");
}
*/
}
if (clusterView.getEdgeViews() != null) {
for (int i = 0; i < clusterView.getEdgeViews().size(); i++) {
if (interrupted) {
// logger.error("Interrupted: Edge Setup");
if (layouter != null)
layouter.resetDoLayout();
resetLoading();
return null;
}
/*
if (loader != null) {
progress += 100.0 * (1.0 / (double) clusterView.getEdgeViews().size()) *
((double) weightSetupEdges / (double) goalTotal);
loader.setProgress((int) progress, "Setup: edges");
}
*/
}
}
if (layoutNecessary) {
if (layouter == null) {
layouter = new SpringEmbeddedLayouter();
}
layouter.setGraphView(clusterView);
// The doLayout method should return true if the process completes without interruption
if (!layouter.doLayout(weightLayout, goalTotal, progress)) {
// Otherwise, if layout is not completed, set the interruption to false, and return null, not an image
resetLoading();
return null;
}
}
final Image image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
final Graphics2D g = (Graphics2D) image.getGraphics();
SwingUtilities.invokeLater(new Runnable() {
// @Override
public void run() {
try {
final Dimension size = new Dimension(width, height);
JPanel panel = new JPanel();
panel.setPreferredSize(size);
panel.setSize(size);
panel.setMinimumSize(size);
panel.setMaximumSize(size);
panel.setBackground((Color) vs.getDefaultValue(NETWORK_BACKGROUND_PAINT));
JWindow window = new JWindow();
window.getContentPane().add(panel, BorderLayout.CENTER);
RenderingEngine<CyNetwork> re = renderingEngineFactory.createRenderingEngine(panel, clusterView);
vs.apply(clusterView);
clusterView.fitContent();
clusterView.updateView();
window.pack();
window.repaint();
re.createImage(width, height);
re.printCanvas(g);
g.dispose();
if (clusterView.getNodeViews().size() > 0) {
cluster.setView(clusterView);
}
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
});
layouter.resetDoLayout();
resetLoading();
return image;
}
use of org.cytoscape.model.subnetwork.CyRootNetwork in project clusterMaker2 by RBVI.
the class ResultsPanel method createClusterImage.
/**
* Convert a network to an image. This is used by the MCODEResultsPanel.
*
* @param cluster Input network to convert to an image
* @param height Height that the resulting image should be
* @param width Width that the resulting image should be
* @param layouter Reference to the layout algorithm
* @param layoutNecessary Determinant of cluster size growth or shrinkage, the former requires layout
* @return The resulting image
*/
public Image createClusterImage(final NodeCluster cluster, final int height, final int width, SpringEmbeddedLayouter layouter, boolean layoutNecessary) {
// System.out.println("CCI: inside method");
final CyRootNetwork root = clusterManager.getService(CyRootNetworkManager.class).getRootNetwork(network);
// need to create a method get the subnetwork for a cluster
final CyNetwork net = cluster.getSubNetwork(network, root, SavePolicy.DO_NOT_SAVE);
// System.out.println("CCI: after getting root and network ");
// Progress reporters.
// There are three basic tasks, the progress of each is calculated and then combined
// using the respective weighting to get an overall progress global progress
// setting up the nodes and edges is deemed as 25% of the whole task
int weightSetupNodes = 20;
int weightSetupEdges = 5;
// layout it is 70%
double weightLayout = 75.0;
double goalTotal = weightSetupNodes + weightSetupEdges;
if (layoutNecessary) {
goalTotal += weightLayout;
}
// keeps track of progress as a percent of the totalGoal
double progress = 0;
final VisualStyle vs = getClusterStyle();
// System.out.println("CCI: after getClusterStyle");
final CyNetworkView clusterView = createNetworkView(net, vs);
// System.out.println("CCI: after createNetworkView");
clusterView.setVisualProperty(NETWORK_WIDTH, new Double(width));
clusterView.setVisualProperty(NETWORK_HEIGHT, new Double(height));
for (View<CyNode> nv : clusterView.getNodeViews()) {
if (interrupted) {
// problems the next time around
if (layouter != null)
layouter.resetDoLayout();
resetLoading();
return null;
}
// Node position
final double x;
final double y;
// first prevents the program from throwing a null pointer exception in the second condition)
if (cluster.getView() != null && cluster.getView().getNodeView(nv.getModel()) != null) {
// If it does, then we take the layout position that was already generated for it
x = cluster.getView().getNodeView(nv.getModel()).getVisualProperty(NODE_X_LOCATION);
y = cluster.getView().getNodeView(nv.getModel()).getVisualProperty(NODE_Y_LOCATION);
} else {
// Otherwise, randomize node positions before layout so that they don't all layout in a line
// (so they don't fall into a local minimum for the SpringEmbedder)
// If the SpringEmbedder implementation changes, this code may need to be removed
// size is small for many default drawn graphs, thus +100
x = (clusterView.getVisualProperty(NETWORK_WIDTH) + 100) * Math.random();
y = (clusterView.getVisualProperty(NETWORK_HEIGHT) + 100) * Math.random();
if (!layoutNecessary) {
goalTotal += weightLayout;
progress /= (goalTotal / (goalTotal - weightLayout));
layoutNecessary = true;
}
}
nv.setVisualProperty(NODE_X_LOCATION, x);
nv.setVisualProperty(NODE_Y_LOCATION, y);
// Might be specific to MCODE
/*
// Node shape
if (cluster.getSeedNode() == nv.getModel().getSUID()) {
nv.setLockedValue(NODE_SHAPE, NodeShapeVisualProperty.RECTANGLE);
} else {
nv.setLockedValue(NODE_SHAPE, NodeShapeVisualProperty.ELLIPSE);
}
*/
/*
// Update loader
if (loader != null) {
progress += 100.0 * (1.0 / (double) clusterView.getNodeViews().size()) *
((double) weightSetupNodes / (double) goalTotal);
loader.setProgress((int) progress, "Setup: nodes");
}
*/
}
if (clusterView.getEdgeViews() != null) {
for (int i = 0; i < clusterView.getEdgeViews().size(); i++) {
if (interrupted) {
// logger.error("Interrupted: Edge Setup");
if (layouter != null)
layouter.resetDoLayout();
resetLoading();
return null;
}
/*
if (loader != null) {
progress += 100.0 * (1.0 / (double) clusterView.getEdgeViews().size()) *
((double) weightSetupEdges / (double) goalTotal);
loader.setProgress((int) progress, "Setup: edges");
}
*/
}
}
if (layoutNecessary) {
if (layouter == null) {
layouter = new SpringEmbeddedLayouter();
}
layouter.setGraphView(clusterView);
// The doLayout method should return true if the process completes without interruption
if (!layouter.doLayout(weightLayout, goalTotal, progress)) {
// Otherwise, if layout is not completed, set the interruption to false, and return null, not an image
resetLoading();
return null;
}
}
final Image image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
final Graphics2D g = (Graphics2D) image.getGraphics();
SwingUtilities.invokeLater(new Runnable() {
// @Override
public void run() {
try {
final Dimension size = new Dimension(width, height);
JPanel panel = new JPanel();
panel.setPreferredSize(size);
panel.setSize(size);
panel.setMinimumSize(size);
panel.setMaximumSize(size);
panel.setBackground((Color) vs.getDefaultValue(NETWORK_BACKGROUND_PAINT));
JWindow window = new JWindow();
window.getContentPane().add(panel, BorderLayout.CENTER);
RenderingEngine<CyNetwork> re = renderingEngineFactory.createRenderingEngine(panel, clusterView);
vs.apply(clusterView);
clusterView.fitContent();
clusterView.updateView();
window.pack();
window.repaint();
re.createImage(width, height);
re.printCanvas(g);
g.dispose();
if (clusterView.getNodeViews().size() > 0) {
cluster.setView(clusterView);
}
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
});
layouter.resetDoLayout();
resetLoading();
return image;
}
use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.
the class GroupUtils method updateMetaEdgeInformation.
public static void updateMetaEdgeInformation(CyNetwork origNet, CyNetwork newNet, CyEdge origEdge, CyEdge newEdge) {
if (newEdge == null)
return;
CyRootNetwork newRoot = ((CySubNetwork) newNet).getRootNetwork();
CyRootNetwork origRoot = ((CySubNetwork) origNet).getRootNetwork();
CyTable newTable = newRoot.getTable(CyEdge.class, CyNetwork.HIDDEN_ATTRS);
if (newTable.getColumn(ISMETA_EDGE_ATTR) == null) {
newTable.createColumn(ISMETA_EDGE_ATTR, Boolean.class, false);
}
CyRow origRow = origRoot.getRow(origEdge, CyNetwork.HIDDEN_ATTRS);
if (origRow.isSet(ISMETA_EDGE_ATTR)) {
CyRow newRow = newTable.getRow(newEdge.getSUID());
Boolean isMeta = origRow.get(ISMETA_EDGE_ATTR, Boolean.class);
newRow.set(ISMETA_EDGE_ATTR, isMeta);
}
return;
}
use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.
the class CloneNetworkTask method addColumns.
private void addColumns(final CyNetwork origNet, final CyNetwork newNet, final Class<? extends CyIdentifiable> tableType, final String namespace) {
final CyTable from = origNet.getTable(tableType, namespace);
final CyTable to = newNet.getTable(tableType, namespace);
final CyRootNetwork origRoot = rootNetMgr.getRootNetwork(origNet);
final CyRootNetwork newRoot = rootNetMgr.getRootNetwork(newNet);
final Map<String, CyTable> origRootTables = netTableMgr.getTables(origRoot, tableType);
for (final CyColumn col : from.getColumns()) {
final String name = col.getName();
if (to.getColumn(name) == null) {
final VirtualColumnInfo info = col.getVirtualColumnInfo();
if (info.isVirtual()) {
if (origRootTables.containsValue(info.getSourceTable())) {
// If the virtual column is from a root-network table, do NOT set this virtual column directly to
// the new table:
// Get the original column (not the virtual one!)
final CyColumn origCol = info.getSourceTable().getColumn(info.getSourceColumn());
// Copy the original column to the root-network's table first
String sourceNamespace = netTableMgr.getTableNamespace(info.getSourceTable());
final CyTable newRootTable = newRoot.getTable(tableType, sourceNamespace);
if (newRootTable.getColumn(origCol.getName()) == null)
copyColumn(origCol, newRootTable);
// Now we can add the new "root" column as a virtual one to the new network's table
to.addVirtualColumn(name, origCol.getName(), newRootTable, CyIdentifiable.SUID, col.isImmutable());
} else {
// Otherwise (e.g. virtual column from a global table) just add the virtual column directly
addVirtualColumn(col, to);
}
} else {
// Not a virtual column, so just copy it to the new network's table
copyColumn(col, to);
}
}
}
}
Aggregations