Search in sources :

Example 31 with Clusters

use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.Clusters 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 32 with Clusters

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

the class ResultPanelPCA method valueChanged.

public void valueChanged(ListSelectionEvent e) {
    ListSelectionModel lsm = (ListSelectionModel) e.getSource();
    // Get the rows
    int[] rowIndices = table.getSelectedRows();
    Map<CyNode, CyNode> selectedMap = new HashMap<CyNode, CyNode>();
    double threshold = 0.02;
    // Get the clusters
    for (int index = 0; index < rowIndices.length; index++) {
        int row = rowIndices[index];
        CyMatrix matrix = components[row];
        for (int i = 0; i < matrix.nRows(); i++) {
            for (int j = 0; j < matrix.nColumns(); j++) {
                if (matrix.getValue(i, j) > threshold) {
                    CyNode node = matrix.getRowNode(i);
                    selectedMap.put(node, node);
                    break;
                }
            }
        }
    // System.out.println("PC is selected");
    }
    // Select the nodes
    for (CyNode node : network.getNodeList()) {
        if (selectedMap.containsKey(node))
            network.getRow(node).set(CyNetwork.SELECTED, true);
        else
            network.getRow(node).set(CyNetwork.SELECTED, false);
    }
    // I wish we didn't need to do this, but if we don't, the selection
    // doesn't update
    networkView.updateView();
}
Also used : CyMatrix(edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix) HashMap(java.util.HashMap) ListSelectionModel(javax.swing.ListSelectionModel) CyNode(org.cytoscape.model.CyNode) Point(java.awt.Point)

Example 33 with Clusters

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

the class BicFinder method run.

public void run(TaskMonitor monitor) {
    this.monitor = monitor;
    monitor.setTitle("Performing " + getName());
    List<String> nodeAttributeList = context.attributeList.getNodeAttributeList();
    String edgeAttribute = context.attributeList.getEdgeAttribute();
    clusterAttributeName = "BicFinder_Bicluster";
    if (network.getRow(network, CyNetwork.LOCAL_ATTRS).getTable().getColumn(ClusterManager.CLUSTER_ATTRIBUTE) == null) {
        network.getRow(network, CyNetwork.LOCAL_ATTRS).getTable().createColumn(ClusterManager.CLUSTER_ATTRIBUTE, String.class, false);
    }
    network.getRow(network, CyNetwork.LOCAL_ATTRS).set(ClusterManager.CLUSTER_ATTRIBUTE, clusterAttributeName);
    if (nodeAttributeList == null && edgeAttribute == null) {
        monitor.showMessage(TaskMonitor.Level.ERROR, "Must select either one edge column or two or more node columns");
        return;
    }
    if (nodeAttributeList != null && nodeAttributeList.size() > 0 && edgeAttribute != null) {
        monitor.showMessage(TaskMonitor.Level.ERROR, "Can't have both node and edge columns selected");
        return;
    }
    if (context.selectedOnly && CyTableUtil.getNodesInState(network, CyNetwork.SELECTED, true).size() < 3) {
        monitor.showMessage(TaskMonitor.Level.ERROR, "Must have at least three nodes to cluster");
        return;
    }
    createGroups = context.createGroups;
    if (nodeAttributeList != null && nodeAttributeList.size() > 0) {
        // To make debugging easier, sort the attribute list
        Collections.sort(nodeAttributeList);
    }
    // Get our attributes we're going to use for the cluster
    String[] attributeArray;
    if (nodeAttributeList != null && nodeAttributeList.size() > 0) {
        attributeArray = new String[nodeAttributeList.size()];
        int i = 0;
        for (String attr : nodeAttributeList) {
            attributeArray[i++] = "node." + attr;
        }
    } else {
        attributeArray = new String[1];
        attributeArray[0] = "edge." + edgeAttribute;
    }
    monitor.setStatusMessage("Initializing");
    resetAttributes(network, SHORTNAME);
    // Create a new clusterer
    RunBicFinder algorithm = new RunBicFinder(network, attributeArray, monitor, context);
    String resultsString = "BicFinder results:";
    // Cluster the nodes
    monitor.setStatusMessage("Clustering nodes");
    Integer[] rowOrder = algorithm.cluster(false);
    CyMatrix biclusterMatrix = algorithm.getBiclusterMatrix();
    int[] clusters = new int[biclusterMatrix.nRows()];
    createBiclusterGroups(algorithm.getClusterNodes());
    // createGroups(network,biclusterMatrix,1, clusters, "bicfinder");
    updateAttributes(network, SHORTNAME, rowOrder, attributeArray, getAttributeList(), algorithm.getBiclusterMatrix());
    createBiclusterTable(algorithm.getClusterNodes(), algorithm.getClusterAttrs());
    // System.out.println(resultsString);
    if (context.showUI) {
        insertTasksAfterCurrentTask(new BiclusterView(clusterManager));
    }
}
Also used : BiclusterView(edu.ucsf.rbvi.clusterMaker2.internal.ui.BiclusterView) CyMatrix(edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix)

Example 34 with Clusters

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

the class DBSCAN method run.

public void run(TaskMonitor monitor) {
    this.monitor = monitor;
    monitor.setTitle("Performing " + getName());
    List<String> nodeAttributeList = context.attributeList.getNodeAttributeList();
    String edgeAttribute = context.attributeList.getEdgeAttribute();
    if (nodeAttributeList == null && edgeAttribute == null) {
        monitor.showMessage(TaskMonitor.Level.ERROR, "Must select either one edge column or two or more node columns");
        return;
    }
    if (nodeAttributeList != null && nodeAttributeList.size() > 0 && edgeAttribute != null) {
        monitor.showMessage(TaskMonitor.Level.ERROR, "Can't have both node and edge columns selected");
        return;
    }
    if (context.selectedOnly && CyTableUtil.getNodesInState(network, CyNetwork.SELECTED, true).size() < 3) {
        monitor.showMessage(TaskMonitor.Level.ERROR, "Must have at least three nodes to cluster");
        return;
    }
    createGroups = context.createGroups;
    if (nodeAttributeList != null && nodeAttributeList.size() > 0) {
        // To make debugging easier, sort the attribute list
        Collections.sort(nodeAttributeList);
    }
    // Get our attributes we're going to use for the cluster
    String[] attributeArray;
    if (nodeAttributeList != null && nodeAttributeList.size() > 0) {
        attributeArray = new String[nodeAttributeList.size()];
        int i = 0;
        for (String attr : nodeAttributeList) {
            attributeArray[i++] = "node." + attr;
        }
    } else {
        attributeArray = new String[1];
        attributeArray[0] = "edge." + edgeAttribute;
    }
    monitor.setStatusMessage("Initializing");
    resetAttributes(network, SHORTNAME);
    distanceMetric = context.getDistanceMetric();
    // Create a new clusterer
    RunDBSCAN algorithm = new RunDBSCAN(network, attributeArray, distanceMetric, monitor, context);
    String resultsString = "DBSCAN results:";
    // Cluster the attributes, if requested
    if (context.clusterAttributes && attributeArray.length > 1) {
        monitor.setStatusMessage("Clustering attributes");
        int[] clusters = algorithm.cluster(true);
        if (!algorithm.getMatrix().isTransposed())
            createGroups(network, algorithm.getMatrix(), algorithm.getNClusters(), clusters, "dbscan");
        Integer[] rowOrder = MatrixUtils.indexSort(clusters, clusters.length);
        // Integer[] rowOrder = algorithm.cluster(context.kcluster.kNumber,1, true, "dbscan", context.kcluster);
        updateAttributes(network, SHORTNAME, rowOrder, attributeArray, getAttributeList(), algorithm.getMatrix());
    }
    // Cluster the nodes
    monitor.setStatusMessage("Clustering nodes");
    int[] clusters = algorithm.cluster(false);
    int nNodes = 0;
    for (int i = 0; i < clusters.length; i++) {
        if (clusters[i] >= 0)
            nNodes++;
    }
    monitor.setStatusMessage("Allocated " + nNodes + " nodes to " + algorithm.getNClusters() + " clusters");
    if (!algorithm.getMatrix().isTransposed()) {
        createGroups(network, algorithm.getMatrix(), algorithm.getNClusters(), clusters, "dbscan");
    }
    Integer[] rowOrder = MatrixUtils.indexSort(clusters, clusters.length);
    // In DBSCAN, not all nodes will be assigned to a cluster, so they will have a cluster # of -1.  Find
    // all of those and trim rowOrder accordingly.
    Integer[] newRowOrder = new Integer[nNodes];
    int newOrder = 0;
    for (int i = 0; i < rowOrder.length; i++) {
        int nodeIndex = rowOrder[i];
        if (clusters[nodeIndex] >= 0) {
            newRowOrder[newOrder] = nodeIndex;
            newOrder++;
        }
    }
    // Integer[] rowOrder = algorithm.cluster(context.kcluster.kNumber,1, false, "dbscan", context.kcluster);
    updateAttributes(network, SHORTNAME, newRowOrder, attributeArray, getAttributeList(), algorithm.getMatrix());
    // System.out.println(resultsString);
    if (context.showUI) {
        insertTasksAfterCurrentTask(new KnnView(clusterManager));
    }
}
Also used : KnnView(edu.ucsf.rbvi.clusterMaker2.internal.ui.KnnView)

Example 35 with Clusters

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

the class BiMine method run.

public void run(TaskMonitor monitor) {
    this.monitor = monitor;
    monitor.setTitle("Performing " + getName());
    List<String> nodeAttributeList = context.attributeList.getNodeAttributeList();
    String edgeAttribute = context.attributeList.getEdgeAttribute();
    clusterAttributeName = "BiMine_Bicluster";
    if (network.getRow(network, CyNetwork.LOCAL_ATTRS).getTable().getColumn(ClusterManager.CLUSTER_ATTRIBUTE) == null) {
        network.getRow(network, CyNetwork.LOCAL_ATTRS).getTable().createColumn(ClusterManager.CLUSTER_ATTRIBUTE, String.class, false);
    }
    network.getRow(network, CyNetwork.LOCAL_ATTRS).set(ClusterManager.CLUSTER_ATTRIBUTE, clusterAttributeName);
    if (nodeAttributeList == null && edgeAttribute == null) {
        monitor.showMessage(TaskMonitor.Level.ERROR, "Must select either one edge column or two or more node columns");
        return;
    }
    if (nodeAttributeList != null && nodeAttributeList.size() > 0 && edgeAttribute != null) {
        monitor.showMessage(TaskMonitor.Level.ERROR, "Can't have both node and edge columns selected");
        return;
    }
    if (context.selectedOnly && CyTableUtil.getNodesInState(network, CyNetwork.SELECTED, true).size() < 3) {
        monitor.showMessage(TaskMonitor.Level.ERROR, "Must have at least three nodes to cluster");
        return;
    }
    createGroups = context.createGroups;
    if (nodeAttributeList != null && nodeAttributeList.size() > 0) {
        // To make debugging easier, sort the attribute list
        Collections.sort(nodeAttributeList);
    }
    // Get our attributes we're going to use for the cluster
    String[] attributeArray;
    if (nodeAttributeList != null && nodeAttributeList.size() > 0) {
        attributeArray = new String[nodeAttributeList.size()];
        int i = 0;
        for (String attr : nodeAttributeList) {
            attributeArray[i++] = "node." + attr;
        }
    } else {
        attributeArray = new String[1];
        attributeArray[0] = "edge." + edgeAttribute;
    }
    monitor.setStatusMessage("Initializing");
    resetAttributes(network, SHORTNAME);
    // Create a new clusterer
    RunBiMine algorithm = new RunBiMine(network, attributeArray, monitor, context);
    String resultsString = "BiMine results:";
    // Cluster the nodes
    monitor.setStatusMessage("Clustering nodes");
    Integer[] rowOrder = algorithm.cluster(false);
    CyMatrix biclusterMatrix = algorithm.getBiclusterMatrix();
    int[] clusters = new int[biclusterMatrix.nRows()];
    createGroups(network, biclusterMatrix, 1, clusters, "bimine");
    updateAttributes(network, SHORTNAME, rowOrder, attributeArray, getAttributeList(), algorithm.getBiclusterMatrix());
    createBiclusterTable(algorithm.getClusterNodes(), algorithm.getClusterAttrs());
    // System.out.println(resultsString);
    if (context.showUI) {
        insertTasksAfterCurrentTask(new BiclusterView(clusterManager));
    }
}
Also used : BiclusterView(edu.ucsf.rbvi.clusterMaker2.internal.ui.BiclusterView) CyMatrix(edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix)

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