Search in sources :

Example 11 with CyNetwork

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();
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode)

Example 12 with CyNetwork

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);
}
Also used : EMStyleOptions(org.baderlab.csplugins.enrichmentmap.style.EMStyleOptions) Task(org.cytoscape.work.Task) AbstractTask(org.cytoscape.work.AbstractTask) TaskIterator(org.cytoscape.work.TaskIterator) CyLayoutAlgorithm(org.cytoscape.view.layout.CyLayoutAlgorithm) CyNetwork(org.cytoscape.model.CyNetwork) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 13 with CyNetwork

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));
    }
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork)

Example 14 with CyNetwork

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.");
}
Also used : CyTable(org.cytoscape.model.CyTable) CyNetwork(org.cytoscape.model.CyNetwork) CyRow(org.cytoscape.model.CyRow)

Example 15 with CyNetwork

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;
    }
}
Also used : BasicVisualLexicon(org.cytoscape.view.presentation.property.BasicVisualLexicon) Logger(org.slf4j.Logger) CyNode(org.cytoscape.model.CyNode) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) UndoSupport(org.cytoscape.work.undo.UndoSupport) Collectors(java.util.stream.Collectors) View(org.cytoscape.view.model.View) ArrayList(java.util.ArrayList) List(java.util.List) CyNetwork(org.cytoscape.model.CyNetwork) CyNetworkView(org.cytoscape.view.model.CyNetworkView) TaskMonitor(org.cytoscape.work.TaskMonitor) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode)

Aggregations

CyNetwork (org.cytoscape.model.CyNetwork)48 Test (org.junit.Test)20 CyNode (org.cytoscape.model.CyNode)16 CyNetworkView (org.cytoscape.view.model.CyNetworkView)13 EnrichmentMap (org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap)11 CyEdge (org.cytoscape.model.CyEdge)9 ArrayList (java.util.ArrayList)8 List (java.util.List)6 CyNetworkManager (org.cytoscape.model.CyNetworkManager)6 CyRow (org.cytoscape.model.CyRow)6 BaseIntegrationTest (org.baderlab.csplugins.enrichmentmap.integration.BaseIntegrationTest)5 DataSetFiles (org.baderlab.csplugins.enrichmentmap.model.DataSetFiles)5 EMDataSet (org.baderlab.csplugins.enrichmentmap.model.EMDataSet)5 CyTable (org.cytoscape.model.CyTable)5 Map (java.util.Map)4 Set (java.util.Set)4 EMCreationParameters (org.baderlab.csplugins.enrichmentmap.model.EMCreationParameters)4 View (org.cytoscape.view.model.View)4 Inject (com.google.inject.Inject)3 Color (java.awt.Color)3