use of org.cytoscape.model.CyNetwork in project EnrichmentMapApp by BaderLab.
the class CreateEMNetworkTask method createEMNetwork.
private long createEMNetwork() {
// Create the CyNetwork
CyNetwork network = networkFactory.createNetwork();
network.getRow(network).set(CyNetwork.NAME, networkNaming.getSuggestedNetworkTitle(LegacySupport.EM_NAME));
map.setNetworkID(network.getSUID());
createNodeColumns(network);
createEdgeColumns(network);
Map<String, CyNode> nodes = createNodes(network);
createEdges(network, nodes);
networkManager.addNetwork(network);
emManager.registerEnrichmentMap(map);
return network.getSUID();
}
use of org.cytoscape.model.CyNetwork in project EnrichmentMapApp by BaderLab.
the class CreateEMViewTask method visualizeMap.
private void visualizeMap() {
CyNetwork network = networkManager.getNetwork(map.getNetworkID());
CyNetworkView view = networkViewFactory.createNetworkView(network);
networkViewManager.addNetworkView(view);
//apply force directed layout
CyLayoutAlgorithm layout = layoutManager.getLayout("force-directed");
if (layout == null)
layout = layoutManager.getDefaultLayout();
Task styleTask = applyStyleTaskFactory.create(new EMStyleOptions(view, map), null, false);
TaskIterator layoutTasks = layout.createTaskIterator(view, layout.createLayoutContext(), CyLayoutAlgorithm.ALL_NODE_VIEWS, null);
TaskIterator moreTasks = new TaskIterator();
moreTasks.append(styleTask);
moreTasks.append(layoutTasks);
insertTasksAfterCurrentTask(moreTasks);
}
use of org.cytoscape.model.CyNetwork in project cytoscape-api by cytoscape.
the class ActionEnableSupport method enableForSingleNetwork.
private void enableForSingleNetwork() {
final CyNetwork n = applicationManager.getCurrentNetwork();
if (n == null) {
setEnabled(false);
} else {
final List<CyNetwork> networks = applicationManager.getSelectedNetworks();
setEnabled(networks.size() == 1 && networks.contains(n));
}
}
use of org.cytoscape.model.CyNetwork in project cytoscape-api by cytoscape.
the class AbstractLayoutTask method run.
/**
* {@inheritDoc}
*/
@Override
public final void run(final TaskMonitor taskMonitor) {
taskMonitor.setTitle(displayName);
final long start = System.currentTimeMillis();
logger.debug("Layout Start: Algorithm = " + displayName);
// do some sanity checking
if (networkView == null)
return;
final CyNetwork network = networkView.getModel();
if (nodesToLayOut.size() == 0 && networkView.getNodeViews().size() == 0)
return;
if (undo != null)
undo.postEdit(new LayoutEdit(displayName, networkView));
LayoutPoint centroid = null;
if (recenter)
centroid = computeCentroid();
// this is overridden by children and does the actual layout
doLayout(taskMonitor);
if (centroid != null) {
LayoutPoint newCentroid = computeCentroid();
translateNodes(new LayoutPoint(centroid.getX() - newCentroid.getX(), centroid.getY() - newCentroid.getY()));
}
// update the __layoutAlgorithm attribute
final CyRow networkAttributes = network.getRow(network, CyNetwork.HIDDEN_ATTRS);
final CyTable netAttrsTable = networkAttributes.getTable();
lock.lock();
try {
if (netAttrsTable.getColumn(LAYOUT_ALGORITHM) == null)
netAttrsTable.createColumn(LAYOUT_ALGORITHM, String.class, true);
networkAttributes.set(LAYOUT_ALGORITHM, displayName);
} finally {
lock.unlock();
}
networkView.fitContent();
logger.debug("Layout finished in " + (System.currentTimeMillis() - start) + " msec.");
}
use of org.cytoscape.model.CyNetwork in project cytoscape-api by cytoscape.
the class AbstractPartitionLayoutTask method doLayout.
/**
* AbstractGraphPartitionLayout implements the doLayout method
* of AbstractBasicLayout in which it calls the layoutParition
* method on each LayoutPartition object created for the network.
* @param taskMonitor the TaskMonitor provided by the run() method
* of the Task.
*/
@Override
public void doLayout(final TaskMonitor taskMonitor) {
final CyNetwork network = networkView.getModel();
if (edgeWeighter != null)
edgeWeighter.reset();
this.taskMonitor = taskMonitor;
long visibleNodeCount = networkView.getNodeViews().stream().filter(view -> view.getVisualProperty(BasicVisualLexicon.NODE_VISIBLE)).count();
boolean useAllNodes = nodesToLayOut.size() == visibleNodeCount;
// to lay out selected nodes, partitioning becomes a very bad idea!
if (singlePartition || !useAllNodes) {
// We still use the partition abstraction, even if we're
// not partitioning. This makes the code further down
// much cleaner
LayoutPartition partition = new LayoutPartition(networkView, nodesToLayOut, edgeWeighter);
partitionList = new ArrayList<LayoutPartition>(1);
partitionList.add(partition);
} else {
Set<CyNode> nodes = nodesToLayOut.stream().map(nv -> nv.getModel()).collect(Collectors.toSet());
partitionList = PartitionUtil.partition(networkView, nodes, edgeWeighter);
}
total_nodes = network.getNodeCount();
current_start = 0;
// Set up offsets -- we start with the overall min and max
double xStart = (partitionList.get(0)).getMinX();
double yStart = (partitionList.get(0)).getMinY();
for (LayoutPartition part : partitionList) {
xStart = Math.min(xStart, part.getMinX());
yStart = Math.min(yStart, part.getMinY());
}
double next_x_start = xStart;
double next_y_start = yStart;
double current_max_y = 0;
double max_dimensions = Math.sqrt((double) network.getNodeCount());
// give each node room
max_dimensions *= incr;
max_dimensions += xStart;
for (LayoutPartition partition : partitionList) {
if (cancelled)
break;
// get the partition
current_size = (double) partition.size();
// System.out.println("Partition #"+partition.getPartitionNumber()+" has "+current_size+" nodes");
setTaskStatus(1);
// Partitions Requiring Layout
if (partition.nodeCount() > 1) {
try {
layoutPartition(partition);
} catch (Throwable _e) {
_e.printStackTrace();
return;
}
if (useAllNodes && !singlePartition) {
// System.out.println("Offsetting partition #"+partition.getPartitionNumber()+" to "+next_x_start+", "+next_y_start);
// OFFSET
partition.offset(next_x_start, next_y_start);
}
// single nodes
} else if (partition.nodeCount() == 1) {
// Reset our bounds
partition.resetNodes();
// Single node -- get it
LayoutNode node = (LayoutNode) partition.getNodeList().get(0);
node.setLocation(next_x_start, next_y_start);
partition.moveNodeToLocation(node);
} else {
continue;
}
double last_max_x = partition.getMaxX();
double last_max_y = partition.getMaxY();
if (last_max_y > current_max_y) {
current_max_y = last_max_y;
}
if (last_max_x > max_dimensions) {
next_x_start = xStart;
next_y_start = current_max_y;
next_y_start += incr;
} else {
next_x_start = last_max_x;
next_x_start += incr;
}
setTaskStatus(100);
current_start += current_size;
}
}
Aggregations