Search in sources :

Example 11 with AbstractClusterResults

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

the class PRWP method run.

@Override
public void run(TaskMonitor taskMonitor) {
    taskMonitor.setProgress(0.0);
    taskMonitor.setTitle("PRWP with Priors ranking of clusters");
    taskMonitor.showMessage(TaskMonitor.Level.INFO, "Fetching clusters...");
    taskMonitor.setProgress(0.1);
    List<NodeCluster> clusters = ClusterUtils.fetchClusters(network);
    taskMonitor.setProgress(0.5);
    initVariables();
    clusters.forEach(NodeCluster::initNodeScores);
    taskMonitor.showMessage(TaskMonitor.Level.INFO, "Setting node scores in clusters");
    addNodes();
    taskMonitor.setProgress(0.6);
    taskMonitor.showMessage(TaskMonitor.Level.INFO, "Setting edge scores in clusters");
    addEdges();
    taskMonitor.setProgress(0.7);
    taskMonitor.showMessage(TaskMonitor.Level.INFO, "Calculating PageRank scores");
    PageRankWithPriors<PRNode, PREdge> pageRank = performPageRank();
    taskMonitor.setProgress(0.8);
    taskMonitor.showMessage(TaskMonitor.Level.INFO, "Inserting scores into clusters");
    insertScores(clusters, pageRank);
    taskMonitor.setProgress(0.9);
    taskMonitor.showMessage(TaskMonitor.Level.INFO, "Insert cluster information in tables");
    ClusterUtils.insertResultsInColumns(network, clusters, SHORTNAME);
    results = new AbstractClusterResults(network, clusters);
    taskMonitor.setProgress(1.0);
    taskMonitor.showMessage(TaskMonitor.Level.INFO, "Done...");
}
Also used : NodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster) PREdge(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.ranking.units.PREdge) PRNode(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.ranking.units.PRNode) AbstractClusterResults(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults)

Example 12 with AbstractClusterResults

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

the class ResultsPanelTask method getClusters.

public List<NodeCluster> getClusters() {
    List<NodeCluster> clusters = new ArrayList<NodeCluster>();
    // List<List<CyNode>> clusterList = new ArrayList<List<CyNode>>();
    /*
		System.out.println(network.NAME);
		System.out.println(CyNetwork.LOCAL_ATTRS);
		System.out.println(ClusterManager.CLUSTER_ATTRIBUTE);
		*/
    clusterAttribute = network.getRow(network, CyNetwork.LOCAL_ATTRS).get(ClusterManager.CLUSTER_ATTRIBUTE, String.class);
    // Create a temporary cluster map
    Map<Integer, ArrayList<CyNode>> clusterMap = new HashMap<Integer, ArrayList<CyNode>>();
    for (CyNode node : (List<CyNode>) network.getNodeList()) {
        // For each node -- see if it's in a cluster.  If so, add it to our map
        if (ModelUtils.hasAttribute(network, node, clusterAttribute)) {
            Integer cluster = network.getRow(node).get(clusterAttribute, Integer.class);
            if (!clusterMap.containsKey(cluster))
                clusterMap.put(cluster, new ArrayList<CyNode>());
            clusterMap.get(cluster).add(node);
        }
    }
    // See if this algorithm provided it's own scores
    List<Double> scores = null;
    if (network.getDefaultNetworkTable().getColumn(clusterAttribute + "_Scores") != null) {
        scores = network.getRow(network, CyNetwork.LOCAL_ATTRS).getList(clusterAttribute + "_Scores", Double.class);
    }
    for (int clustNum : clusterMap.keySet()) {
        NodeCluster cluster = new NodeCluster(clusterMap.get(clustNum));
        cluster.setClusterNumber(clustNum);
        if (scores != null)
            cluster.setClusterScore(scores.get(clustNum - 1));
        clusters.add(cluster);
    }
    // calculating the scores for each cluster
    clusterResults = new AbstractClusterResults(network, clusters);
    List<Double> modularityList;
    if (scores == null) {
        modularityList = clusterResults.getModularityList();
    } else {
        modularityList = scores;
    }
    for (int i = 0; i < clusters.size(); i++) {
        clusters.get(i).setClusterScore(modularityList.get(i));
    }
    return clusters;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) NodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster) CyNode(org.cytoscape.model.CyNode) ArrayList(java.util.ArrayList) List(java.util.List) AbstractClusterResults(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults)

Example 13 with AbstractClusterResults

use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults 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 14 with AbstractClusterResults

use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults 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 15 with AbstractClusterResults

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

the class ConnectedComponentsCluster method run.

public void run(TaskMonitor monitor) {
    monitor.setTitle("Performing ConnectedComponents cluster");
    this.monitor = monitor;
    if (network == null)
        network = clusterManager.getNetwork();
    // Make sure to update the context
    context.setNetwork(network);
    NodeCluster.init();
    CyMatrix matrix = context.edgeAttributeHandler.getMatrix();
    if (matrix == null) {
        monitor.showMessage(TaskMonitor.Level.ERROR, "Can't get distance matrix: no attribute value?");
        return;
    }
    // Update our tunable results
    clusterAttributeName = context.getClusterAttribute();
    createGroups = context.advancedAttributes.createGroups;
    if (canceled)
        return;
    Map<Integer, List<CyNode>> components = MatrixUtils.findConnectedComponents(matrix);
    // Create the NodeClusters
    Map<Integer, NodeCluster> clusterMap = new HashMap<Integer, NodeCluster>();
    for (Integer cluster : components.keySet()) {
        clusterMap.put(cluster, new NodeCluster(components.get(cluster)));
    }
    // Now get the sorted cluster map
    int clusterNumber = 1;
    HashMap<NodeCluster, NodeCluster> cMap = new HashMap<NodeCluster, NodeCluster>();
    for (NodeCluster cluster : NodeCluster.sortMap(clusterMap)) {
        if (cMap.containsKey(cluster))
            continue;
        cMap.put(cluster, cluster);
        cluster.setClusterNumber(clusterNumber);
        clusterNumber++;
    }
    List<NodeCluster> clusters = new ArrayList<NodeCluster>(cMap.keySet());
    monitor.showMessage(TaskMonitor.Level.INFO, "Removing groups");
    // Remove any leftover groups from previous runs
    removeGroups(network, GROUP_ATTRIBUTE);
    monitor.showMessage(TaskMonitor.Level.INFO, "Creating groups");
    params = new ArrayList<String>();
    context.edgeAttributeHandler.setParams(params);
    List<List<CyNode>> nodeClusters = createGroups(network, clusters, GROUP_ATTRIBUTE);
    results = new AbstractClusterResults(network, clusters);
    monitor.showMessage(TaskMonitor.Level.INFO, "ConnectedComponent results:\n" + results);
    if (context.vizProperties.showUI) {
        monitor.showMessage(TaskMonitor.Level.INFO, "Creating network");
        insertTasksAfterCurrentTask(new NewNetworkView(network, clusterManager, true, context.vizProperties.restoreEdges, !context.edgeAttributeHandler.selectedOnly));
    }
}
Also used : CyMatrix(edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix) NewNetworkView(edu.ucsf.rbvi.clusterMaker2.internal.ui.NewNetworkView) HashMap(java.util.HashMap) 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)

Aggregations

AbstractClusterResults (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults)17 NodeCluster (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster)14 ArrayList (java.util.ArrayList)12 List (java.util.List)12 NewNetworkView (edu.ucsf.rbvi.clusterMaker2.internal.ui.NewNetworkView)11 CyMatrix (edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix)6 FuzzyNodeCluster (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.FuzzyNodeCluster)3 PREdge (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.ranking.units.PREdge)3 PRNode (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.ranking.units.PRNode)3 HashMap (java.util.HashMap)3 CyNode (org.cytoscape.model.CyNode)3 CyTable (org.cytoscape.model.CyTable)2 ClusterResults (edu.ucsf.rbvi.clusterMaker2.internal.api.ClusterResults)1 KnnView (edu.ucsf.rbvi.clusterMaker2.internal.ui.KnnView)1 NumberFormat (java.text.NumberFormat)1