Search in sources :

Example 26 with CyGroup

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

the class AbstractNetworkClusterer method createFuzzyGroups.

protected List<List<CyNode>> createFuzzyGroups(CyNetwork network, List<FuzzyNodeCluster> 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>();
    for (FuzzyNodeCluster cluster : clusters) {
        int clusterNumber = cluster.getClusterNumber();
        String groupName = clusterAttributeName + "_" + clusterNumber;
        List<CyNode> nodeList = new ArrayList<CyNode>();
        for (CyNode node : cluster) {
            nodeList.add(node);
            // network.getRow(node).set(clusterAttributeName, clusterNumber);
            if (FuzzyNodeCluster.hasScore()) {
                ModelUtils.createAndSetLocal(network, node, clusterAttributeName + "_" + clusterNumber + "_Membership", cluster.getMembership(node), Double.class, null);
            // network.getRow(node).set(clusterAttributeName+"_Score", cluster.getClusterScore());
            }
        }
        if (createGroups) {
            CyGroup group = clusterManager.createGroup(network, clusterAttributeName + "_" + clusterNumber, nodeList, null, true);
            if (group != null)
                groupList.add(group.getGroupNode().getSUID());
        }
        clusterList.add(nodeList);
    }
    // Adding a column per node by the clusterAttributeName, which will store a list of all the clusters to which the node belongs
    List<CyNode> nodeList = network.getNodeList();
    for (int i = 0; i < nodeList.size(); i++) {
        CyNode node = nodeList.get(i);
        List<Integer> listOfClusters = new ArrayList<Integer>();
        for (FuzzyNodeCluster cluster : clusters) {
            if (cluster.getMembership(node) != null) {
                listOfClusters.add(cluster.getClusterNumber());
            }
        }
        ModelUtils.createAndSetLocal(network, node, clusterAttributeName, listOfClusters, List.class, Integer.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) ArrayList(java.util.ArrayList) List(java.util.List) CyNode(org.cytoscape.model.CyNode) FuzzyNodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.FuzzyNodeCluster)

Example 27 with CyGroup

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

the class ClusterManagerImpl method createGroup.

public CyGroup createGroup(CyNetwork network, String name, List<CyNode> nodeList, List<CyEdge> edgeList, boolean registerGroup) {
    CyGroup group = groupFactory.createGroup(network, nodeList, edgeList, registerGroup);
    if (group != null) {
        CyRootNetwork rootNetwork = ((CySubNetwork) network).getRootNetwork();
        // The name of the group node is the name of the group
        rootNetwork.getRow(group.getGroupNode()).set(CyNetwork.NAME, name);
        rootNetwork.getRow(group.getGroupNode(), CyRootNetwork.SHARED_ATTRS).set(CyRootNetwork.SHARED_NAME, name);
    }
    return group;
}
Also used : CyGroup(org.cytoscape.group.CyGroup) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Example 28 with CyGroup

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

the class BicFinder 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 29 with CyGroup

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

the class ChengChurch 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 30 with CyGroup

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

the class AbstractAttributeClusterer 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(CyNetwork net, CyMatrix matrix, int nClusters, int[] clusters, String algorithm) {
    if (matrix.isTransposed()) {
        return;
    }
    network = net;
    if (monitor != null)
        monitor.setStatusMessage("Creating groups");
    attrList = new ArrayList<String>(matrix.nRows());
    // Create the attribute list
    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) {
                // System.out.println("Setting cluster # for node "+matrix.getRowLabel(i)+"("+i+") to "+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) {
            // System.out.println("Creating group: Cluster_"+cluster+" with "+memberList.size()+" nodes");
            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)

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