Search in sources :

Example 11 with Clusters

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

the class Splitter method run.

public void run(HashMap<Integer, String> proteins2integers, HashMap<String, Integer> integers2proteins) throws IOException {
    this.threshold = Config.threshold;
    if (Config.gui)
        Console.println("Start reading similarity file ... ");
    // else // System.out.println("Start reading similarity file ... ");
    Edges es = InOut.readSimilarityFile(Config.similarityFile, proteins2integers, integers2proteins);
    if (Config.gui)
        Console.println();
    if (Config.gui) {
        Console.println("Start splitting ...");
        Console.setBarValue(0);
        Console.setBarText("splitting into connected components");
    }
    // else // System.out.println("Start splitting ...");
    Vector<Vector<Integer>> clusters = splitIntoConnectedComponents(es, proteins2integers, threshold, false);
    if (Config.gui)
        Console.println();
    if (Config.gui) {
        Console.println("Writing costmatrices ...");
        Console.setBarValue(0);
        Console.restartBarTimer();
        Console.setBarText("writing costmatrices");
    }
    // else // System.out.println("Writing costmatrices ...");
    InOut.writeCostMatrices(es, clusters, proteins2integers, integers2proteins);
    if (Config.gui)
        Console.println();
// else // System.out.println();
}
Also used : Edges(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.costmatrixcreation.dataTypes.Edges) Vector(java.util.Vector)

Example 12 with Clusters

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

the class MCLCluster method run.

public void run(TaskMonitor monitor) {
    monitor.setTitle("Performing MCL cluster");
    this.monitor = monitor;
    if (network == null)
        network = clusterManager.getNetwork();
    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
    runMCL = new RunMCL(matrix, context.inflation_parameter, context.iterations, context.clusteringThresh, context.maxResidual, context.maxThreads, context.forceDecliningResidual, monitor);
    runMCL.setDebug(false);
    if (canceled)
        return;
    monitor.showMessage(TaskMonitor.Level.INFO, "Clustering...");
    // results = runMCL.run(monitor);
    List<NodeCluster> clusters = runMCL.run(network, monitor);
    // 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.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, !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 13 with Clusters

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

the class RunDBSCAN method cluster.

public int[] cluster(boolean transpose) {
    // Create the matrix
    matrix = CyMatrixFactory.makeSmallMatrix(network, weightAttributes, selectedOnly, ignoreMissing, transpose, false);
    monitor.showMessage(TaskMonitor.Level.INFO, "cluster matrix has " + matrix.nRows() + " rows");
    DistanceMetric metric = context.metric.getSelectedValue();
    if (monitor != null)
        monitor.setStatusMessage("Clustering...");
    int nelements = matrix.nRows();
    int ifound = 1;
    int currentC = -1;
    int[] clusters = new int[nelements];
    // calculate the distances and store in distance matrix
    // Do we want to normalize the matrix?
    // Matrix normMatrix = matrix.getDistanceMatrix(metric);
    // normMatrix.ops().normalize();
    // distanceMatrix = normMatrix.toArray();
    distanceMatrix = matrix.getDistanceMatrix(metric).toArray();
    unvisited = new ArrayList<Integer>();
    // Initializing all nodes as unvisited and clusters to -1
    for (int i = 0; i < nelements; i++) {
        unvisited.add(i);
        clusters[i] = -1;
    }
    while (unvisited.size() > 0) {
        int p = unvisited.get(0);
        unvisited.remove(0);
        ArrayList<Integer> neighborPts = regionQuery(p);
        if (neighborPts.size() < minPts) {
            clusters[p] = -1;
        } else {
            currentC += 1;
            expandCluster(p, neighborPts, currentC, clusters);
        // System.out.println("Node "+p+" has "+neighborPts.size()+" neighbors after expansion");
        }
    }
    nClusters = currentC + 1;
    // System.out.println("nClusters = "+nClusters);
    return clusters;
}
Also used : DistanceMetric(edu.ucsf.rbvi.clusterMaker2.internal.api.DistanceMetric)

Example 14 with Clusters

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

the class AutoSOMECluster method run.

public void run(TaskMonitor monitor) {
    this.monitor = monitor;
    monitor.setTitle("Performing " + getName());
    String networkID = ModelUtils.getNetworkName(network);
    // Update settings from our context
    settings = context.getSettings();
    // got back to parent to cluster again
    if (networkID.contains("--AutoSOME")) {
        String[] tokens = networkID.split("--AutoSOME");
        networkID = tokens[0];
        network = ModelUtils.getNetworkWithName(clusterManager, networkID);
    }
    List<String> dataAttributes = context.attributeList.getNodeAttributeList();
    // Cluster the nodes
    runAutoSOME = new RunAutoSOME(clusterManager, dataAttributes, network, settings, monitor);
    runAutoSOME.setIgnoreMissing(context.ignoreMissing);
    runAutoSOME.setSelectedOnly(context.selectedOnly);
    runAutoSOME.setDebug(debug);
    monitor.setStatusMessage("Running AutoSOME" + ((settings.distMatrix) ? " Fuzzy Clustering" : ""));
    nodeCluster = runAutoSOME.run(monitor);
    if (nodeCluster == null) {
        monitor.setStatusMessage("Clustering failed!");
        return;
    }
    if (nodeCluster.size() > 0)
        finishedClustering = true;
    monitor.setStatusMessage("Removing groups");
    // Remove any leftover groups from previous runs
    removeGroups(network, getShortName());
    monitor.setStatusMessage("Creating groups");
    if (settings.distMatrix)
        runAutoSOME.getEdges(context.maxEdges);
    attrList = runAutoSOME.attrList;
    attrOrderList = runAutoSOME.attrOrderList;
    nodeOrderList = runAutoSOME.nodeOrderList;
    ModelUtils.createAndSetLocal(network, network, ClusterManager.CLUSTER_NODE_ATTRIBUTE, attrList, List.class, String.class);
    ModelUtils.createAndSetLocal(network, network, ClusterManager.ARRAY_ORDER_ATTRIBUTE, attrOrderList, List.class, String.class);
    ModelUtils.createAndSetLocal(network, network, ClusterManager.NODE_ORDER_ATTRIBUTE, nodeOrderList, List.class, String.class);
    ModelUtils.createAndSetLocal(network, network, ClusterManager.CLUSTER_TYPE_ATTRIBUTE, getShortName(), String.class, null);
    List<List<CyNode>> nodeClusters;
    if (!settings.distMatrix) {
        nodeClusters = createGroups(network, nodeCluster, GROUP_ATTRIBUTE);
        results = new AbstractClusterResults(network, nodeCluster);
        monitor.setStatusMessage("Done.  AutoSOME results:\n" + results);
    } else {
        nodeClusters = new ArrayList<List<CyNode>>();
        /*
			for (NodeCluster cluster: clusters) {
				List<CyNode>nodeList = new ArrayList();

				for (CyNode node: cluster) {
					nodeList.add(node);
				}
				nodeClusters.add(nodeList);
			}
	   */
        monitor.setStatusMessage("Done.  AutoSOME results:\n" + nodeCluster.size() + " clusters found.");
    }
    if (context.showViz) {
        if (heatmap)
            insertTasksAfterCurrentTask(new KnnView(clusterManager));
        else
            insertTasksAfterCurrentTask(new NewNetworkView(network, clusterManager, true, false, !context.selectedOnly));
    }
}
Also used : NewNetworkView(edu.ucsf.rbvi.clusterMaker2.internal.ui.NewNetworkView) ArrayList(java.util.ArrayList) List(java.util.List) AbstractClusterResults(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults) KnnView(edu.ucsf.rbvi.clusterMaker2.internal.ui.KnnView)

Example 15 with Clusters

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

the class ClusterUtils method setEdgeScoresInCluster.

public static List<NodeCluster> setEdgeScoresInCluster(CyNetwork network, List<NodeCluster> clusters, List<String> edgeAttributes, String clusterColumnName, boolean multiplicative) {
    List<CyEdge> edges = network.getEdgeList();
    CyTable nodeTable = network.getDefaultNodeTable();
    CyTable edgeTable = network.getDefaultEdgeTable();
    for (String edgeAttr : edgeAttributes) {
        for (CyEdge edge : edges) {
            CyRow source = nodeTable.getRow(edge.getSource().getSUID());
            CyRow target = nodeTable.getRow(edge.getTarget().getSUID());
            CyRow edgeRow = edgeTable.getRow(edge.getSUID());
            int sourceClusterNumber = source.get(clusterColumnName, Integer.class, -1);
            int targetClusterNumber = target.get(clusterColumnName, Integer.class, -1);
            int sourceHighestClusterNumber = -1;
            int targetHighestClusterNumber = -1;
            for (NodeCluster cluster : clusters) {
                int clusterNumber = cluster.getClusterNumber();
                if (clusterNumber == sourceClusterNumber && (clusterNumber < sourceHighestClusterNumber || sourceHighestClusterNumber == -1)) {
                    if (multiplicative) {
                        setRankScoreMultiplicative(edgeAttr, edgeRow, cluster);
                    } else {
                        setRankScore(edgeAttr, edgeRow, cluster);
                    }
                    sourceHighestClusterNumber = clusterNumber;
                } else if (clusterNumber == targetClusterNumber && (clusterNumber < targetHighestClusterNumber || targetHighestClusterNumber == -1)) {
                    if (multiplicative) {
                        setRankScoreMultiplicative(edgeAttr, edgeRow, cluster);
                    } else {
                        setRankScore(edgeAttr, edgeRow, cluster);
                    }
                    targetHighestClusterNumber = clusterNumber;
                }
            }
        }
    }
    return clusters;
}
Also used : NodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster)

Aggregations

ArrayList (java.util.ArrayList)30 NodeCluster (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster)27 CyMatrix (edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix)22 Clusters (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.Clusters)21 AbstractClusterResults (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults)16 HashMap (java.util.HashMap)16 List (java.util.List)15 CyNode (org.cytoscape.model.CyNode)13 NewNetworkView (edu.ucsf.rbvi.clusterMaker2.internal.ui.NewNetworkView)10 Test (org.junit.Test)9 FuzzyNodeCluster (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.FuzzyNodeCluster)8 ConnectedComponent (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.datastructure.ConnectedComponent)6 Random (java.util.Random)5 Vector (java.util.Vector)5 Semaphore (java.util.concurrent.Semaphore)5 Edges (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.costmatrixcreation.dataTypes.Edges)3 ICCEdges (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.datastructure.ICCEdges)3 IParameters (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.layout.IParameters)3 ClusteringManager (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.taskmanaging.ClusteringManager)3 PREdge (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.ranking.units.PREdge)3