Search in sources :

Example 81 with CyEdge

use of org.cytoscape.model.CyEdge in project cytoscape-impl by cytoscape.

the class CyGroupImpl method createMetaEdge.

private CyEdge createMetaEdge(CyEdge edge, CyNode node, CyNode groupNode) {
    CyEdge metaEdge = null;
    CyNode source = null;
    CyNode target = null;
    if (isIncoming(edge)) {
        if (rootNetwork.containsEdge(node, groupNode)) {
            return rootNetwork.getConnectingEdgeList(node, groupNode, CyEdge.Type.ANY).get(0);
        }
        metaEdge = rootNetwork.addEdge(node, groupNode, edge.isDirected());
        source = node;
        target = groupNode;
    } else {
        if (rootNetwork.containsEdge(groupNode, node)) {
            return rootNetwork.getConnectingEdgeList(groupNode, node, CyEdge.Type.ANY).get(0);
        }
        metaEdge = rootNetwork.addEdge(groupNode, node, edge.isDirected());
        source = groupNode;
        target = node;
    }
    nameMetaEdge(metaEdge, source, target);
    createIfNecessary(metaEdge, CyNetwork.HIDDEN_ATTRS, ISMETA_EDGE_ATTR, Boolean.class);
    rootNetwork.getRow(metaEdge, CyNetwork.HIDDEN_ATTRS).set(ISMETA_EDGE_ATTR, Boolean.TRUE);
    // System.out.println("Created metaEdge: "+metaEdge+" edge count = "+rootNetwork.getEdgeCount());
    return metaEdge;
}
Also used : CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge)

Example 82 with CyEdge

use of org.cytoscape.model.CyEdge in project cytoscape-impl by cytoscape.

the class CyGroupImpl method addPartnerEdges.

// Find the edge in our partner that links to us
protected void addPartnerEdges(CyGroup metaPartner, CyNetwork net, Set<CyGroup> partnersSeen) {
    Set<CyEdge> partnerEdges = metaPartner.getExternalEdgeList();
    Set<CyEdge> newEdges = new HashSet<CyEdge>();
    synchronized (lock) {
        // XXX Performance hog XXX
        for (CyEdge edge : partnerEdges) {
            // System.out.println("Looking at partner edge: "+edge.toString());
            CyNode source = edge.getSource();
            CyNode target = edge.getTarget();
            CyNode partner = null;
            boolean directed = edge.isDirected();
            if (getGroupNetwork().containsNode(target)) {
                target = groupNode;
                partner = source;
            } else if (getGroupNetwork().containsNode(source)) {
                source = groupNode;
                partner = target;
            } else {
                continue;
            }
            if (source == target)
                continue;
            // Create a new edge
            CyEdge newEdge = null;
            if (!rootNetwork.containsEdge(source, target)) {
                newEdge = rootNetwork.addEdge(source, target, directed);
                newEdges.add(newEdge);
            // System.out.println("   ... it points to us -- created new edge: "+newEdge.toString());
            }
            externalEdges.add(edge);
            CyGroup partnerMeta = mgr.getGroup(partner, net);
            if (partnerMeta != null && !partnersSeen.contains(partnerMeta)) {
                // System.out.println("Adding partner edges for "+partnerMeta.toString());
                partnersSeen.add(partnerMeta);
                addPartnerEdges(partnerMeta, net, partnersSeen);
            // System.out.println("Done adding partner edges for "+partnerMeta.toString());
            }
            if (newEdge != null)
                addMetaEdge(edge, newEdge);
        }
    }
    for (CyEdge edge : newEdges) {
        ((CyGroupImpl) metaPartner).addExternalEdge(edge);
    }
}
Also used : CyGroup(org.cytoscape.group.CyGroup) CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge) HashSet(java.util.HashSet)

Example 83 with CyEdge

use of org.cytoscape.model.CyEdge in project cytoscape-impl by cytoscape.

the class CyGroupImpl method addNodes.

/**
 * @see org.cytoscape.group.CyGroup#addNodes()
 */
@Override
public void addNodes(List<CyNode> nodes) {
    synchronized (lock) {
        // printGroup();
        for (CyNode n : nodes) {
            if (!rootNetwork.containsNode(n))
                throwIllegalArgumentException("Can only add a node in the same network tree");
            addNode(n);
            List<CyEdge> adjacentEdges = new ArrayList<CyEdge>(rootNetwork.getAdjacentEdgeList(n, CyEdge.Type.ANY));
            for (CyEdge edge : adjacentEdges) {
                // System.out.println("Looking at edge: "+edge);
                final CyNode source = edge.getSource();
                final CyNode target = edge.getTarget();
                if (metaEdges.containsValue(edge)) {
                    rootNetwork.removeEdges(Collections.singletonList(edge));
                    continue;
                }
                if (getGroupNetwork().containsNode(source) && getGroupNetwork().containsNode(target)) {
                    addInternalEdge(edge);
                    if (externalEdges.contains(edge)) {
                        // This was an external edge, now it's internal
                        externalEdges.remove(edge);
                    }
                } else if (groupNode != null && (source.equals(groupNode) || target.equals(groupNode)) && !isMeta(edge)) {
                    // System.out.println("Adding "+edge+" as member edge");
                    addMemberEdge(edge);
                } else {
                    addExternalEdge(edge);
                }
            }
        }
        updateMetaEdges(false);
        for (CyNetwork net : networkSet) {
            updateCountAttributes(net);
        }
    // System.out.println("Added nodes: "+nodes+" to group "+this.toString());
    // printGroup();
    }
    cyEventHelper.flushPayloadEvents();
    cyEventHelper.fireEvent(new GroupNodesAddedEvent(CyGroupImpl.this, nodes));
}
Also used : ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) GroupNodesAddedEvent(org.cytoscape.group.events.GroupNodesAddedEvent) CyEdge(org.cytoscape.model.CyEdge)

Example 84 with CyEdge

use of org.cytoscape.model.CyEdge in project cytoscape-impl by cytoscape.

the class CyGroupImpl method updateMetaEdges.

/**
 * This method is the central method for the creation and maintenance of a
 * meta-node.  Essentially, it is responsible for creating all of the meta-edges
 * that connect this meta-node to external nodes.
 *
 * Basic approach:
 *  for each external edge:
 *	add a meta-edge to the parter
 *	if the partner is a group and the group is in our network:
 *	  add ourselves to the group's outer edges list (recursively)
 *	  add ourselves to the partner's meta edge list
 *	if the partner is in a group:
 *	  add ourselves to the group's meta edge list
 */
private void updateMetaEdges(boolean ignoreMetaEdges) {
    synchronized (lock) {
        metaEdges = new HashMap<CyEdge, CyEdge>();
        Set<CyGroup> partnersSeen = new HashSet<CyGroup>();
        // System.out.println("Updating metaEdges: ignoreMetaEdges = "+ignoreMetaEdges);
        // long simpleMeta = 0L;
        // long recursiveMeta1 = 0L;
        // long recursiveMeta2 = 0L;
        // System.out.println(this.toString()+" updating meta edges");
        // We need to use a list iterator because we might need to add new
        // edges to our outer edge list and we want to add them to the
        // iterator to re-examine them
        ListIterator<CyEdge> iterator = (new ArrayList<CyEdge>(externalEdges)).listIterator();
        while (iterator.hasNext()) {
            // long timeStamp = System.currentTimeMillis();
            CyEdge edge = iterator.next();
            CyNode node = getPartner(edge);
            if (ignoreMetaEdges && isMeta(edge)) {
                this.addMetaEdge(edge, edge);
                continue;
            }
            // If the edge is already on our group node, don't create a metaedge for it
            if (edge.getSource() == groupNode || edge.getTarget() == groupNode)
                continue;
            // but there you have it...
            if (rootNetwork.containsEdge(edge.getSource(), groupNode) && metaAlreadyExists(edge.getSource(), groupNode)) {
                this.addMetaEdge(edge, getMetaEdge(edge.getSource(), groupNode));
                continue;
            }
            if (rootNetwork.containsEdge(groupNode, edge.getTarget()) && metaAlreadyExists(groupNode, edge.getTarget())) {
                this.addMetaEdge(edge, getMetaEdge(groupNode, edge.getTarget()));
                continue;
            }
            // Create the meta-edge to the external node, but maintain the directionality
            // of the original edge
            CyEdge metaEdge = createMetaEdge(edge, node, groupNode);
            if (metaEdge == null)
                continue;
            // System.out.println("MetaEdge: "+metaEdge);
            this.addMetaEdge(edge, metaEdge);
            for (CyNetwork net : networkSet) {
                // timeStamp = System.currentTimeMillis();
                if (net.equals(rootNetwork))
                    continue;
                // Is the partner a group?
                CyGroup metaPartner = mgr.getGroup(node, net);
                if (metaPartner != null && !partnersSeen.contains(metaPartner)) {
                    // Recursively add links to the appropriate children
                    // System.out.println("Adding partner edges for "+metaPartner);
                    addPartnerEdges(metaPartner, net, partnersSeen);
                    ((CyGroupImpl) metaPartner).addMetaEdge(edge, metaEdge);
                }
            // recursiveMeta1 += System.currentTimeMillis()-timeStamp;
            // timeStamp = System.currentTimeMillis();
            /*
					// Now, handle the case where the partner is a member of one or more groups
					List<CyGroup> nodeGroups = mgr.getGroupsForNode(node);
					if (nodeGroups != null && nodeGroups.size() > 0) {
						// TODO: Should we skip this and handle this at collapse/expand time?
						addPartnerMetaEdges(net, edge, nodeGroups, metaEdge);
					}
					*/
            // recursiveMeta2 += System.currentTimeMillis()-timeStamp;
            }
        }
    // System.out.println("Simple Meta processing took: "+simpleMeta+"ms");
    // System.out.println("Recursive (partner edge) processing took: "+recursiveMeta1+"ms");
    // System.out.println("Recursive (partner meta edge) processing took: "+recursiveMeta2+"ms");
    }
}
Also used : CyGroup(org.cytoscape.group.CyGroup) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge) HashSet(java.util.HashSet)

Example 85 with CyEdge

use of org.cytoscape.model.CyEdge in project cytoscape-impl by cytoscape.

the class ViewUtils method applyStyle.

public static void applyStyle(final Collection<? extends CyIdentifiable> elements, final Collection<CyNetworkView> networkViews, final VisualMappingManager cyStyleManager) {
    if (elements == null || networkViews == null)
        return;
    for (CyNetworkView netView : networkViews) {
        final CyNetwork net = netView.getModel();
        final VisualStyle style = cyStyleManager.getVisualStyle(netView);
        for (CyIdentifiable entry : elements) {
            View<? extends CyIdentifiable> view = null;
            if (entry instanceof CyNode)
                view = netView.getNodeView((CyNode) entry);
            else if (entry instanceof CyEdge)
                view = netView.getEdgeView((CyEdge) entry);
            if (view != null)
                style.apply(net.getRow(entry), view);
        }
    }
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyEdge(org.cytoscape.model.CyEdge) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Aggregations

CyEdge (org.cytoscape.model.CyEdge)302 CyNode (org.cytoscape.model.CyNode)231 CyNetwork (org.cytoscape.model.CyNetwork)103 ArrayList (java.util.ArrayList)77 Test (org.junit.Test)71 CyNetworkView (org.cytoscape.view.model.CyNetworkView)55 HashSet (java.util.HashSet)42 CyRow (org.cytoscape.model.CyRow)41 CyIdentifiable (org.cytoscape.model.CyIdentifiable)29 HashMap (java.util.HashMap)26 CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)25 CyTable (org.cytoscape.model.CyTable)21 DummyCyEdge (org.cytoscape.model.DummyCyEdge)21 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)18 DummyCyNode (org.cytoscape.model.DummyCyNode)17 View (org.cytoscape.view.model.View)16 List (java.util.List)13 CyEventHelper (org.cytoscape.event.CyEventHelper)12 CyGroup (org.cytoscape.group.CyGroup)12 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)12