Search in sources :

Example 56 with CyGroup

use of org.cytoscape.group.CyGroup in project cytoscape-impl by cytoscape.

the class GroupUtil method updateGroupNodes.

public void updateGroupNodes(final CyNetworkView view) {
    if (view == null)
        return;
    final CyNetwork network = view.getModel();
    final CyGroupManager groupMgr = serviceRegistrar.getService(CyGroupManager.class);
    final Set<CyGroup> groupSet = groupMgr.getGroupSet(network);
    for (CyGroup group : groupSet) {
        if (group.isCollapsed(network))
            updateGroupNodeLocation(view, group.getGroupNode());
    }
}
Also used : CyGroup(org.cytoscape.group.CyGroup) CyNetwork(org.cytoscape.model.CyNetwork) CyGroupManager(org.cytoscape.group.CyGroupManager)

Example 57 with CyGroup

use of org.cytoscape.group.CyGroup in project clusterMaker2 by RBVI.

the class ClusterManagerImpl method removeGroup.

public void removeGroup(CyNetwork network, Long suid) {
    // Make sure to get the node in the root network
    CyNode node = ((CySubNetwork) network).getRootNetwork().getNode(suid);
    if (node == null)
        return;
    CyGroup group = groupMgr.getGroup(node, network);
    if (group == null)
        return;
    // Remove the group from this network
    if (group.getNetworkSet() != null && group.getNetworkSet().size() > 1) {
        group.removeGroupFromNetwork(network);
        return;
    }
    groupMgr.destroyGroup(group);
}
Also used : CyGroup(org.cytoscape.group.CyGroup) CyNode(org.cytoscape.model.CyNode)

Example 58 with CyGroup

use of org.cytoscape.group.CyGroup in project clusterMaker2 by RBVI.

the class AbstractKClusterAlgorithm method createGroups.

/**
 * This protected method is called to create all of our groups (if desired).
 * It is used by all of the k-clustering algorithms.
 *
 * @param nClusters the number of clusters we created
 * @param cluster the list of values and the assigned clusters
 */
protected void createGroups(ClusterManager clusterManager, int nClusters, int[] clusters, String algorithm, boolean createGroups) {
    if (matrix.isTransposed()) {
        return;
    }
    // Create the attribute list
    attrList = new ArrayList<String>(matrix.nRows());
    for (int cluster = 0; cluster < nClusters; cluster++) {
        List<CyNode> memberList = new ArrayList<CyNode>();
        for (int i = 0; i < matrix.nRows(); i++) {
            if (clusters[i] == cluster) {
                attrList.add(matrix.getRowLabel(i) + "\t" + cluster);
                memberList.add(matrix.getRowNode(i));
                ModelUtils.createAndSetLocal(network, matrix.getRowNode(i), algorithm + " Cluster", cluster, Integer.class, null);
            }
        }
        if (createGroups) {
            CyGroup group = clusterManager.createGroup(network, "Cluster_" + cluster, memberList, null, true);
        }
    }
}
Also used : CyGroup(org.cytoscape.group.CyGroup) ArrayList(java.util.ArrayList) CyNode(org.cytoscape.model.CyNode)

Example 59 with CyGroup

use of org.cytoscape.group.CyGroup in project clusterMaker2 by RBVI.

the class BiMine method createBiclusterGroups.

protected void createBiclusterGroups(Map<Integer, List<Long>> clusterNodes) {
    // List of node lists
    List<List<CyNode>> clusterList = new ArrayList<List<CyNode>>();
    // keep track of the groups we create
    List<Long> groupList = new ArrayList<Long>();
    createGroups = context.createGroups;
    attrList = new ArrayList<String>();
    for (Integer bicluster : clusterNodes.keySet()) {
        String groupName = clusterAttributeName + "_" + bicluster;
        List<Long> suidList = clusterNodes.get(bicluster);
        List<CyNode> nodeList = new ArrayList<CyNode>();
        for (Long suid : suidList) {
            CyNode node = network.getNode(suid);
            attrList.add(network.getRow(node).get(CyNetwork.NAME, String.class) + "\t" + bicluster);
            nodeList.add(node);
        }
        if (createGroups) {
            CyGroup group = clusterManager.createGroup(network, groupName, nodeList, null, true);
            if (group != null)
                groupList.add(group.getGroupNode().getSUID());
        }
    }
    // Adding a column per node by the clusterAttributeName, which will store a list of all the clusters to which the node belongs
    ModelUtils.createAndSetLocal(network, network, GROUP_ATTRIBUTE, groupList, List.class, Long.class);
    ModelUtils.createAndSetLocal(network, network, ClusterManager.CLUSTER_TYPE_ATTRIBUTE, getShortName(), String.class, null);
    ModelUtils.createAndSetLocal(network, network, ClusterManager.CLUSTER_ATTRIBUTE, clusterAttributeName, String.class, null);
    if (params != null)
        ModelUtils.createAndSetLocal(network, network, ClusterManager.CLUSTER_PARAMS_ATTRIBUTE, params, List.class, String.class);
}
Also used : CyGroup(org.cytoscape.group.CyGroup) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CyNode(org.cytoscape.model.CyNode)

Example 60 with CyGroup

use of org.cytoscape.group.CyGroup in project clusterMaker2 by RBVI.

the class AbstractNetworkClusterer method createGroups.

protected List<List<CyNode>> createGroups(CyNetwork network, List<NodeCluster> clusters, String group_attr) {
    // List of node lists
    List<List<CyNode>> clusterList = new ArrayList<List<CyNode>>();
    // keep track of the groups we create
    List<Long> groupList = new ArrayList<Long>();
    List<Double> clusterScores = new ArrayList<Double>(clusters.size());
    // Initialize
    for (NodeCluster cluster : clusters) {
        clusterScores.add(null);
    }
    boolean haveScores = NodeCluster.getScoreList(clusters) != null;
    // Remove the old column, if it's there.  Some of the algorithms don't put
    // all nodes into clusters, so we might wind up with old data lingering
    ModelUtils.deleteColumnLocal(network, CyNode.class, clusterAttributeName);
    for (NodeCluster cluster : clusters) {
        int clusterNumber = cluster.getClusterNumber();
        if (cluster.hasScore()) {
            clusterScores.set(clusterNumber - 1, cluster.getClusterScore());
            haveScores = true;
        }
        String groupName = clusterAttributeName + "_" + clusterNumber;
        List<CyNode> nodeList = new ArrayList<CyNode>();
        for (CyNode node : cluster) {
            nodeList.add(node);
            ModelUtils.createAndSetLocal(network, node, clusterAttributeName, clusterNumber, Integer.class, null);
        }
        if (createGroups) {
            CyGroup group = clusterManager.createGroup(network, clusterAttributeName + "_" + clusterNumber, nodeList, null, true);
            if (group != null) {
                groupList.add(group.getGroupNode().getSUID());
                if (NodeCluster.hasScore()) {
                    ModelUtils.createAndSetLocal(network, group.getGroupNode(), clusterAttributeName + "_Score", cluster.getClusterScore(), Double.class, null);
                }
            }
        }
        clusterList.add(nodeList);
    }
    if (haveScores)
        ModelUtils.createAndSetLocal(network, network, clusterAttributeName + "_Scores", clusterScores, List.class, Double.class);
    ModelUtils.createAndSetLocal(network, network, group_attr, groupList, List.class, Long.class);
    ModelUtils.createAndSetLocal(network, network, ClusterManager.CLUSTER_TYPE_ATTRIBUTE, getShortName(), String.class, null);
    ModelUtils.createAndSetLocal(network, network, ClusterManager.CLUSTER_ATTRIBUTE, clusterAttributeName, String.class, null);
    if (params != null)
        ModelUtils.createAndSetLocal(network, network, ClusterManager.CLUSTER_PARAMS_ATTRIBUTE, params, List.class, String.class);
    return clusterList;
}
Also used : ArrayList(java.util.ArrayList) CyGroup(org.cytoscape.group.CyGroup) FuzzyNodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.FuzzyNodeCluster) NodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster) ArrayList(java.util.ArrayList) List(java.util.List) CyNode(org.cytoscape.model.CyNode)

Aggregations

CyGroup (org.cytoscape.group.CyGroup)60 CyNode (org.cytoscape.model.CyNode)33 CyNetwork (org.cytoscape.model.CyNetwork)26 ArrayList (java.util.ArrayList)22 CyEdge (org.cytoscape.model.CyEdge)12 CyNetworkView (org.cytoscape.view.model.CyNetworkView)10 HashSet (java.util.HashSet)8 CyRootNetwork (org.cytoscape.model.subnetwork.CyRootNetwork)7 CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)7 List (java.util.List)6 GroupViewType (org.cytoscape.group.CyGroupSettingsManager.GroupViewType)6 CyGroupManager (org.cytoscape.group.CyGroupManager)5 CyRow (org.cytoscape.model.CyRow)5 TaskIterator (org.cytoscape.work.TaskIterator)5 CyGroupImpl (org.cytoscape.group.internal.CyGroupImpl)4 Dimension (java.awt.Dimension)3 LinkedHashSet (java.util.LinkedHashSet)3 CyEventHelper (org.cytoscape.event.CyEventHelper)3 GroupCollapsedEvent (org.cytoscape.group.events.GroupCollapsedEvent)3 FuzzyNodeCluster (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.FuzzyNodeCluster)2