Search in sources :

Example 31 with NodeCluster

use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster in project clusterMaker2 by RBVI.

the class MCODECluster method run.

public void run(TaskMonitor monitor) {
    this.monitor = monitor;
    monitor.setTitle("Performing " + getName());
    updateSettings();
    if (network == null)
        network = clusterManager.getNetwork();
    context.setNetwork(network);
    NodeCluster.init();
    if (currentParamsCopy.getScope().equals(MCODEParameterSet.SELECTION)) {
        List<CyNode> selectedNodes = CyTableUtil.getNodesInState(network, CyNetwork.SELECTED, true);
        currentParamsCopy.setSelectedNodes(selectedNodes);
    }
    MCODECurrentParameters.getInstance().setParams(currentParamsCopy, "MCODE Result", ModelUtils.getNetworkName(network));
    runMCODE = new RunMCODE(RESCORE, 1, network, monitor);
    List<NodeCluster> clusters = runMCODE.run(monitor);
    if (canceled) {
        monitor.showMessage(TaskMonitor.Level.INFO, "Canceled by user");
        return;
    }
    monitor.showMessage(TaskMonitor.Level.INFO, "Found " + clusters.size() + " clusters");
    if (clusters == null || clusters.size() == 0) {
        monitor.showMessage(TaskMonitor.Level.WARN, "Didn't find any clusters!");
        return;
    }
    // Now, sort our list of clusters by score
    clusters = NodeCluster.rankListByScore(clusters);
    List<Double> scoreList = NodeCluster.getScoreList(clusters);
    clusterAttributeName = context.getClusterAttribute();
    createGroups = context.advancedAttributes.createGroups;
    monitor.showMessage(TaskMonitor.Level.INFO, "Removing groups");
    // Remove any leftover groups from previous runs
    removeGroups(network, GROUP_ATTRIBUTE);
    monitor.setStatusMessage("Creating groups");
    List<List<CyNode>> nodeClusters = createGroups(network, clusters, GROUP_ATTRIBUTE);
    results = new AbstractClusterResults(network, clusters);
    monitor.setStatusMessage("Done.  MCODE results:\n" + results);
    if (context.vizProperties.showUI) {
        monitor.showMessage(TaskMonitor.Level.INFO, "Creating network");
        insertTasksAfterCurrentTask(new NewNetworkView(network, clusterManager, true, context.vizProperties.restoreEdges, !currentParamsCopy.getScope().equals(MCODEParameterSet.SELECTION)));
    }
}
Also used : NodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster) NewNetworkView(edu.ucsf.rbvi.clusterMaker2.internal.ui.NewNetworkView) CyNode(org.cytoscape.model.CyNode) ArrayList(java.util.ArrayList) List(java.util.List) AbstractClusterResults(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults)

Example 32 with NodeCluster

use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster in project clusterMaker2 by RBVI.

the class Fuzzifier method getClusters.

/**
 * The method creates a list of NodeCLusters from the cluster attributes of the network
 * This serves as the input for the fuzzifeir algorithm
 * @return A list of NodeClusters
 */
public List<NodeCluster> getClusters() {
    List<NodeCluster> nodeClusters = new ArrayList<NodeCluster>();
    HashMap<Integer, List<CyNode>> clusterMap = new HashMap<Integer, List<CyNode>>();
    if (network == null)
        return nodeClusters;
    List<CyNode> nodeList = network.getNodeList();
    clusterAttributeName = network.getRow(network).get("__clusterAttribute", String.class);
    // Save the seed cluster we used
    ModelUtils.createAndSetLocal(network, network, "__fuzzifierSeed", clusterAttributeName, String.class, null);
    for (CyNode node : nodeList) {
        // System.out.println("Node SUID:"+node.getSUID());
        if (ModelUtils.hasAttribute(network, node, clusterAttributeName)) {
            Integer cluster = network.getRow(node).get(clusterAttributeName, Integer.class);
            // System.out.println("Cluster for "+node.getSUID()+"--"+cluster);
            if (!clusterMap.containsKey(cluster))
                clusterMap.put(cluster, new ArrayList<CyNode>());
            clusterMap.get(cluster).add(node);
        }
    }
    for (int key : clusterMap.keySet()) {
        nodeClusters.add(new NodeCluster(clusterMap.get(key)));
    }
    // System.out.println("NodeCluster Size : " +nodeClusters.size());
    return nodeClusters;
}
Also used : FuzzyNodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.FuzzyNodeCluster) NodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CyNode(org.cytoscape.model.CyNode)

Example 33 with NodeCluster

use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster in project clusterMaker2 by RBVI.

the class RunFuzzifier method getFuzzyCenters.

/**
 * The method calculates the centers of fuzzy clusters
 *
 * @param cData matrix to store the data for cluster centers
 */
public void getFuzzyCenters(CyMatrix cData) {
    // To store the sum of memberships(raised to fuzziness index) corresponding to each cluster
    int nelements = distanceMatrix.nRows();
    for (NodeCluster cluster : Clusters) {
        int c = Clusters.indexOf(cluster);
        double numerator = 0;
        Double distance = 0.0;
        int i = 0;
        for (int e = 0; e < nelements; e++) {
            numerator = 0;
            for (CyNode node : cluster) {
                i = nodeList.indexOf(node);
                distance = distanceMatrix.doubleValue(i, e);
                numerator += distance;
            }
            cData.setValue(c, e, (numerator / cluster.size()));
        }
    }
}
Also used : FuzzyNodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.FuzzyNodeCluster) NodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster) CyNode(org.cytoscape.model.CyNode)

Example 34 with NodeCluster

use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster in project clusterMaker2 by RBVI.

the class GLayCluster method run.

public void run(TaskMonitor monitor) {
    this.monitor = monitor;
    monitor.setTitle("Performing community clustering (GLay)");
    createGroups = context.advancedAttributes.createGroups;
    clusterAttributeName = context.getClusterAttribute();
    if (network == null)
        network = clusterManager.getNetwork();
    // Make sure to update the context
    context.setNetwork(network);
    NodeCluster.init();
    GSimpleGraphData simpleGraph = new GSimpleGraphData(network, context.selectedOnly, context.undirectedEdges);
    fa = new FastGreedyAlgorithm();
    // fa.partition(simpleGraph);
    fa.execute(simpleGraph, monitor);
    NumberFormat nf = NumberFormat.getInstance();
    String modularityString = nf.format(fa.getModularity());
    List<NodeCluster> clusterList = new ArrayList<NodeCluster>();
    for (int cluster = 0; cluster < fa.getClusterNumber(); cluster++) {
        clusterList.add(new NodeCluster());
    }
    int[] membership = fa.getMembership();
    for (int index = 0; index < simpleGraph.graphIndices.length; index++) {
        int cluster = membership[index];
        clusterList.get(cluster).add(simpleGraph.graphIndices[index]);
    }
    monitor.showMessage(TaskMonitor.Level.INFO, "Found " + clusterList.size() + " clusters");
    // Remove any leftover groups from previous runs
    removeGroups(network, GROUP_ATTRIBUTE);
    monitor.showMessage(TaskMonitor.Level.INFO, "Creating groups");
    List<List<CyNode>> nodeClusters = createGroups(network, clusterList, GROUP_ATTRIBUTE);
    results = new AbstractClusterResults(network, clusterList);
    monitor.showMessage(TaskMonitor.Level.INFO, "Done.  Community Clustering results:\n" + results);
    if (context.vizProperties.showUI) {
        monitor.showMessage(TaskMonitor.Level.INFO, "Creating network");
        insertTasksAfterCurrentTask(new NewNetworkView(network, clusterManager, true, context.vizProperties.restoreEdges, !context.selectedOnly));
    }
}
Also used : NewNetworkView(edu.ucsf.rbvi.clusterMaker2.internal.ui.NewNetworkView) ArrayList(java.util.ArrayList) NodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster) ArrayList(java.util.ArrayList) List(java.util.List) AbstractClusterResults(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults) NumberFormat(java.text.NumberFormat)

Example 35 with NodeCluster

use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster in project clusterMaker2 by RBVI.

the class RunSCPS method doComponentClustering.

// Store all components length greater then 5 in clusters, if number components is greater then K
public void doComponentClustering() {
    // Connected Componets
    Map<Integer, List<CyNode>> cMap = MatrixUtils.findConnectedComponents(distanceMatrix);
    // Iterate through connected components
    int component_size_sum = 0;
    for (List<CyNode> component : cMap.values()) {
        if (component.size() > 5) {
            NodeCluster iCluster = new NodeCluster(component);
            iCluster.setClusterNumber(this.clusterCount);
            this.clusterMap.put(new Integer(clusterCount), iCluster);
            this.clusterCount++;
        }
    }
}
Also used : NodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster) DoubleArrayList(cern.colt.list.tdouble.DoubleArrayList) IntArrayList(cern.colt.list.tint.IntArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CyNode(org.cytoscape.model.CyNode)

Aggregations

NodeCluster (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster)39 ArrayList (java.util.ArrayList)25 CyNode (org.cytoscape.model.CyNode)18 HashMap (java.util.HashMap)17 AbstractClusterResults (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults)15 List (java.util.List)15 NewNetworkView (edu.ucsf.rbvi.clusterMaker2.internal.ui.NewNetworkView)9 CyMatrix (edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix)7 FuzzyNodeCluster (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.FuzzyNodeCluster)5 DoubleArrayList (cern.colt.list.tdouble.DoubleArrayList)3 IntArrayList (cern.colt.list.tint.IntArrayList)3 PREdge (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.ranking.units.PREdge)3 PRNode (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.ranking.units.PRNode)3 CyEdge (org.cytoscape.model.CyEdge)3 DoubleMatrix2D (cern.colt.matrix.tdouble.DoubleMatrix2D)2 HashSet (java.util.HashSet)2 Edges (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.costmatrixcreation.dataTypes.Edges)1 IteratorThread (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.iterativeclustering.IteratorThread)1 ClusterResults (edu.ucsf.rbvi.clusterMaker2.internal.api.ClusterResults)1 Matrix (edu.ucsf.rbvi.clusterMaker2.internal.api.Matrix)1