Search in sources :

Example 1 with KnnView

use of edu.ucsf.rbvi.clusterMaker2.internal.ui.KnnView 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 2 with KnnView

use of edu.ucsf.rbvi.clusterMaker2.internal.ui.KnnView in project clusterMaker2 by RBVI.

the class KMedoidCluster 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");
    // System.out.println("Initializing");
    resetAttributes(network, SHORTNAME);
    // Create a new clusterer
    RunKMedoidCluster algorithm = new RunKMedoidCluster(network, attributeArray, distanceMetric, monitor, context, this);
    // System.out.println("Algorithm defined");
    String resultsString = "K-Medoid results:";
    // Cluster the attributes, if requested
    if (context.clusterAttributes && attributeArray.length > 1) {
        monitor.setStatusMessage("Clustering attributes");
        // System.out.println("Clustering attributes");
        Integer[] rowOrder = algorithm.cluster(clusterManager, context.kcluster.kNumber, context.iterations, true, SHORTNAME, context.kcluster, false);
        attributeList = algorithm.getAttributeList();
        updateAttributes(network, SHORTNAME, rowOrder, attributeArray, attributeList, algorithm.getMatrix());
        attributeSilhouette = algorithm.getSilhouettes();
        attributeOrder = getOrder(rowOrder, algorithm.getMatrix());
    }
    // Cluster the nodes
    monitor.setStatusMessage("Clustering nodes");
    // System.out.println("Clustering nodes");
    Integer[] rowOrder = algorithm.cluster(clusterManager, context.kcluster.kNumber, context.iterations, false, SHORTNAME, context.kcluster, createGroups);
    nodeList = algorithm.getAttributeList();
    updateAttributes(network, SHORTNAME, rowOrder, attributeArray, algorithm.getAttributeList(), algorithm.getMatrix());
    nodeSilhouette = algorithm.getSilhouettes();
    nodeOrder = getOrder(rowOrder, algorithm.getMatrix());
    // System.out.println(resultsString);
    if (context.showUI) {
        insertTasksAfterCurrentTask(new KnnView(clusterManager));
    }
}
Also used : KnnView(edu.ucsf.rbvi.clusterMaker2.internal.ui.KnnView)

Example 3 with KnnView

use of edu.ucsf.rbvi.clusterMaker2.internal.ui.KnnView in project clusterMaker2 by RBVI.

the class FFT 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);
    // Create a new clusterer
    RunFFT algorithm = new RunFFT(network, attributeArray, distanceMetric, monitor, context, this);
    // System.out.println("Algorithm defined");
    String resultsString = "FFT results:";
    // Cluster the attributes, if requested
    if (context.clusterAttributes && attributeArray.length > 1) {
        monitor.setStatusMessage("Clustering attributes");
        Integer[] rowOrder = algorithm.cluster(clusterManager, context.kcluster.kNumber, 1, true, "fft", context.kcluster, false);
        updateAttributes(network, SHORTNAME, rowOrder, attributeArray, algorithm.getAttributeList(), algorithm.getMatrix());
    }
    // Cluster the nodes
    monitor.setStatusMessage("Clustering nodes");
    Integer[] rowOrder = algorithm.cluster(clusterManager, context.kcluster.kNumber, 1, false, "fft", context.kcluster, createGroups);
    updateAttributes(network, SHORTNAME, rowOrder, attributeArray, algorithm.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 4 with KnnView

use of edu.ucsf.rbvi.clusterMaker2.internal.ui.KnnView in project clusterMaker2 by RBVI.

the class KMeansCluster 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");
    // System.out.println("Initializing");
    resetAttributes(network, SHORTNAME);
    // Create a new clusterer
    RunKCluster algorithm = new RunKCluster(network, attributeArray, distanceMetric, monitor, context, this);
    // System.out.println("Algorithm defined");
    String resultsString = "K-Means results:";
    // Cluster the attributes, if requested
    if (context.clusterAttributes && attributeArray.length > 1) {
        monitor.setStatusMessage("Clustering attributes");
        // System.out.println("Clustering attributes: k="+context.kcluster.kNumber);
        Integer[] rowOrder = algorithm.cluster(clusterManager, context.kcluster.kNumber, context.iterations, true, "kmeans", context.kcluster, false);
        attributeList = algorithm.getAttributeList();
        updateAttributes(network, SHORTNAME, rowOrder, attributeArray, attributeList, algorithm.getMatrix());
        attributeSilhouette = algorithm.getSilhouettes();
        attributeOrder = getOrder(rowOrder, algorithm.getMatrix());
    }
    // Cluster the nodes
    monitor.setStatusMessage("Clustering nodes");
    Integer[] rowOrder = algorithm.cluster(clusterManager, context.kcluster.kNumber, context.iterations, false, "kmeans", context.kcluster, createGroups);
    nodeList = algorithm.getAttributeList();
    updateAttributes(network, SHORTNAME, rowOrder, attributeArray, nodeList, algorithm.getMatrix());
    nodeSilhouette = algorithm.getSilhouettes();
    nodeOrder = getOrder(rowOrder, algorithm.getMatrix());
    // System.out.println(resultsString);
    if (context.showUI) {
        insertTasksAfterCurrentTask(new KnnView(clusterManager));
    }
}
Also used : KnnView(edu.ucsf.rbvi.clusterMaker2.internal.ui.KnnView)

Example 5 with KnnView

use of edu.ucsf.rbvi.clusterMaker2.internal.ui.KnnView 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)

Aggregations

KnnView (edu.ucsf.rbvi.clusterMaker2.internal.ui.KnnView)5 AbstractClusterResults (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults)1 NewNetworkView (edu.ucsf.rbvi.clusterMaker2.internal.ui.NewNetworkView)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1