Example #1
0
  private void insertScores(List<NodeCluster> clusters, PageRank<PRNode, PREdge> pageRank) {
    for (PRNode node : graph.getVertices()) {
      node.setPRScore(pageRank.getVertexScore(node));

      for (NodeCluster cluster : clusters) {
        if (cluster.getNodeScores().containsKey(node.getCyNode().getSUID())) {
          cluster.addScoreToAvg(pageRank.getVertexScore(node));
        }
      }
    }
  }
  public void run(TaskMonitor monitor) {
    monitor.setTitle("Performing MCL cluster");
    this.monitor = monitor;
    if (network == null) network = clusterManager.getNetwork();

    context.setNetwork(network);

    NodeCluster.init();

    DistanceMatrix 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;

    // Cluster the nodes
    runMCL =
        new RunMCL(
            matrix,
            context.inflation_parameter,
            context.iterations,
            context.clusteringThresh,
            context.maxResidual,
            context.maxThreads,
            monitor);

    runMCL.setDebug(debug);

    if (canceled) return;

    monitor.showMessage(TaskMonitor.Level.INFO, "Clustering...");

    // results = runMCL.run(monitor);
    List<NodeCluster> clusters = runMCL.run(network, monitor);
    if (clusters == null) return; // Canceled?

    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, nodeClusters);

    monitor.showMessage(TaskMonitor.Level.INFO, "MCL results:\n" + results);

    if (context.vizProperties.showUI) {
      monitor.showMessage(TaskMonitor.Level.INFO, "Creating network");
      insertTasksAfterCurrentTask(
          new NewNetworkView(network, clusterManager, true, context.vizProperties.restoreEdges));
    }
  }