Search in sources :

Example 1 with NodeCluster

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

the class SCPSCluster method run.

public void run(TaskMonitor monitor) {
    monitor.setTitle("Performing SCPS 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;
    // Cluster the nodes
    runSCPS = new RunSCPS(matrix, context.epsilon, context.clusters, context.iterations, monitor);
    monitor.showMessage(TaskMonitor.Level.INFO, "Clustering...");
    List<NodeCluster> clusterList = runSCPS.run(network, monitor);
    // Canceled?
    if (clusterList == null)
        return;
    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, clusterList, GROUP_ATTRIBUTE);
    results = new AbstractClusterResults(network, clusterList);
    monitor.showMessage(TaskMonitor.Level.INFO, "Done.  SCPS 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) NodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster) NewNetworkView(edu.ucsf.rbvi.clusterMaker2.internal.ui.NewNetworkView) ArrayList(java.util.ArrayList) List(java.util.List) AbstractClusterResults(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults)

Example 2 with NodeCluster

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

the class RunTransClust method getClusterMap.

private Map<Integer, NodeCluster> getClusterMap(String[] clusters, HashMap<String, CyNode> nodeHash) {
    HashMap<Integer, NodeCluster> clusterMap = new HashMap<Integer, NodeCluster>();
    for (int i = 0; i < clusters.length; i++) {
        String[] elements = clusters[i].split(",");
        NodeCluster nc = new NodeCluster();
        for (int j = 0; j < elements.length; j++) {
            if (nodeHash.containsKey(elements[j].trim())) {
                nc.add(nodeHash.get(elements[j].trim()));
            }
        }
        clusterCount++;
        updateClusters(nc, clusterMap);
    }
    return clusterMap;
}
Also used : NodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster) HashMap(java.util.HashMap)

Example 3 with NodeCluster

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

the class RunTransClust method run.

public List<NodeCluster> run(TaskMonitor monitor, CyNetwork network) {
    DoubleMatrix2D matrix = this.distanceMatrix.getColtMatrix();
    nodes = distanceMatrix.getRowNodes();
    HashMap<String, CyNode> nodeHash = new HashMap<String, CyNode>();
    for (CyNode node : nodes) {
        nodeHash.put(ModelUtils.getNodeName(network, node), node);
    }
    HashMap<String, Integer> integers2proteins = new HashMap<String, Integer>();
    HashMap<Integer, String> proteins2integers = new HashMap<Integer, String>();
    int count = 0;
    for (CyNode node : this.nodes) {
        integers2proteins.put(ModelUtils.getNodeName(network, node), count);
        proteins2integers.put(count, ModelUtils.getNodeName(network, node));
        count++;
    }
    Edges es = new Edges(this.nodes.size() * this.nodes.size(), this.nodes.size());
    count = 0;
    for (int i = 0; i < this.nodes.size(); i++) {
        CyNode cyNodeI = this.nodes.get(i);
        es.startPositions[integers2proteins.get(cyNodeI.getSUID())] = count;
        for (int j = 0; j < this.nodes.size(); j++) {
            CyNode cyNodeJ = this.nodes.get(j);
            es.sources[count] = i;
            es.targets[count] = j;
            Double val = distanceMatrix.getValue(i, j);
            if (val != null) {
                es.values[count] = val.floatValue();
                count++;
            }
        }
        es.endPositions[integers2proteins.get(cyNodeI.getSUID())] = count - 1;
    }
    Semaphore s = new Semaphore(1);
    TaskConfig.mode = TaskConfig.COMPARISON_MODE;
    TaskConfig.monitor = monitor;
    IteratorThread it = new IteratorThread(es, integers2proteins, proteins2integers, s);
    TaskConfig.minThreshold = threshold;
    TaskConfig.maxThreshold = threshold;
    try {
        s.acquire();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    it.start();
    monitor.showMessage(TaskMonitor.Level.INFO, "Executing TransClust Clustering...");
    try {
        s.acquire();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    monitor.showMessage(TaskMonitor.Level.INFO, "Assigning nodes to clusters");
    String result = it.resultsStringBuffer.toString();
    String[] clusters = result.split("\t")[2].split(";");
    Map<Integer, NodeCluster> clusterMap = getClusterMap(clusters, nodeHash);
    // Update node attributes in network to include clusters. Create cygroups from clustered nodes
    monitor.showMessage(TaskMonitor.Level.INFO, "Created " + clusterMap.size() + " clusters");
    if (clusterCount == 0) {
        monitor.showMessage(TaskMonitor.Level.ERROR, "Created 0 clusters!!!!");
        return null;
    }
    int clusterNumber = 1;
    Map<NodeCluster, NodeCluster> cMap = new HashMap();
    for (NodeCluster cluster : NodeCluster.sortMap(clusterMap)) {
        if (cMap.containsKey(cluster))
            continue;
        cMap.put(cluster, cluster);
        cluster.setClusterNumber(clusterNumber);
        clusterNumber++;
    }
    Set<NodeCluster> clusters2 = cMap.keySet();
    return new ArrayList<NodeCluster>(clusters2);
}
Also used : HashMap(java.util.HashMap) IteratorThread(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.iterativeclustering.IteratorThread) ArrayList(java.util.ArrayList) Semaphore(java.util.concurrent.Semaphore) Edges(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.costmatrixcreation.dataTypes.Edges) NodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster) DoubleMatrix2D(cern.colt.matrix.tdouble.DoubleMatrix2D) CyNode(org.cytoscape.model.CyNode)

Example 4 with NodeCluster

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

the class TransClustCluster method run.

/**
 * Perform the actual clustering.  For TransClust, there are really
 * two steps:
 * 	1) Assign all of the connected components
 * 	2) Do the TransClust clustering.
 *
 * There is also an optional approach called evolutionary parameter
 * tuning, which takes a lot longer and is probably less relevant for
 * the Cytoscape integration.
 *
 * @param monitor the TaskMonitor to use
 */
public void run(TaskMonitor monitor) {
    monitor.setTitle("Performing Transitivity clustering");
    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;
    }
    updateSettings();
    runTransClust = new RunTransClust(matrix, context.edgeAttributeHandler.edgeCutOff.getValue(), monitor);
    if (canceled)
        return;
    monitor.showMessage(TaskMonitor.Level.INFO, "Clustering...");
    createGroups = context.advancedAttributes.createGroups;
    // Cluster the nodes
    List<NodeCluster> clusters = runTransClust.run(monitor, network);
    // Canceled?
    if (clusters == null)
        return;
    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.setStatusMessage("Done.  TransClust 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) NodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster) NewNetworkView(edu.ucsf.rbvi.clusterMaker2.internal.ui.NewNetworkView) ArrayList(java.util.ArrayList) List(java.util.List) AbstractClusterResults(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults)

Example 5 with NodeCluster

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

the class RunSCPS method doKMeansClustering.

public void doKMeansClustering(DoubleMatrix2D uMat, DoubleMatrix2D sMat) {
    int k = uMat.columns();
    int[] clusterArray = new int[uMat.rows()];
    // do kmeans clustering
    KCluster.kmeans(k, rnumber, uMat, clusterArray);
    // redistribute cluster results
    clusterArray = redistributeMaxCluster(clusterArray, sMat, k);
    for (int cluster_id = 0; cluster_id < k; cluster_id++) {
        NodeCluster iCluster = new NodeCluster();
        List<CyNode> node_list = new ArrayList<CyNode>();
        for (int j = 0; j < clusterArray.length; j++) {
            // node j in uMatrix belongs to cluster #cluster_id
            if (clusterArray[j] == cluster_id)
                node_list.add(this.nodes.get(getMap_old(j)));
        }
        iCluster = new NodeCluster(node_list);
        iCluster.setClusterNumber(this.clusterCount);
        this.clusterMap.put(new Integer(clusterCount), iCluster);
        System.out.println("Clustercount " + this.clusterCount + " cluster_id " + cluster_id + " node_list_length " + node_list.size());
        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) 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