Search in sources :

Example 21 with ClusterManager

use of edu.ucsf.rbvi.clusterMaker2.internal.api.ClusterManager in project clusterMaker2 by RBVI.

the class FCMCluster method run.

/**
 * The method run creates an instance of the RunFCM and creates the fuzzy clusters by applying the fuzzy c means algorithm.
 * Also creates fuzzy groups and the Fuzzy Cluster Table
 *
 * @param Task Monitor
 */
public void run(TaskMonitor taskmonitor) {
    this.monitor = taskmonitor;
    monitor.setTitle("Performing FCM cluster");
    if (network == null)
        network = clusterManager.getNetwork();
    // Make sure to update the context
    context.setNetwork(network);
    Long networkID = network.getSUID();
    CyTable netAttributes = network.getDefaultNetworkTable();
    CyTable nodeAttributes = network.getDefaultNodeTable();
    CyTable edgeAttributes = network.getDefaultEdgeTable();
    distanceMatrix = context.edgeAttributeHandler.getMatrix();
    if (distanceMatrix == null) {
        monitor.showMessage(TaskMonitor.Level.ERROR, "Can't get distance matrix: no attribute value?");
        return;
    }
    createGroups = context.advancedAttributes.createGroups;
    // Update our tunable results
    clusterAttributeName = "CnC_Bicluster";
    // distanceDataMatrix = new Matrix(network,0,0);
    // distanceDataMatrix.buildDistanceMatrix(distanceMatrix);
    distanceDataMatrix = distanceMatrix.copy();
    if (context.estimateClusterNumber && context.cNumber < 0) {
        // System.out.println("Estimated number of Clusters: "+ cEstimate);
        context.cNumber = cEstimate();
    }
    int[] mostRelevantCluster = new int[network.getNodeList().size()];
    FuzzyNodeCluster.fuzzyClusterCount = 0;
    runFCM = new RunFCM(distanceMatrix, context.iterations, context.cNumber, context.fIndex, context.beta, context.membershipThreshold.getValue(), context.maxThreads, this.monitor);
    runFCM.setDebug(debug);
    if (canceled)
        return;
    monitor.showMessage(TaskMonitor.Level.INFO, "Clustering...");
    List<FuzzyNodeCluster> clusters = runFCM.run(network, monitor, mostRelevantCluster);
    // 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 = createFuzzyGroups(network, clusters, GROUP_ATTRIBUTE);
    results = new AbstractClusterResults(network, clusters);
    monitor.showMessage(TaskMonitor.Level.INFO, "Done.  FCM results:\n" + results);
    if (context.vizProperties.showUI) {
        monitor.showMessage(TaskMonitor.Level.INFO, "Creating network");
        insertTasksAfterCurrentTask(new NewNetworkView(network, clusterManager, true, context.vizProperties.restoreEdges, !selectedOnly));
    } else {
        monitor.showMessage(TaskMonitor.Level.INFO, "Done.  FCM results:\n" + results);
    }
    createFuzzyTable(clusters);
}
Also used : CyTable(org.cytoscape.model.CyTable) NewNetworkView(edu.ucsf.rbvi.clusterMaker2.internal.ui.NewNetworkView) ArrayList(java.util.ArrayList) List(java.util.List) AbstractClusterResults(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults) FuzzyNodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.FuzzyNodeCluster)

Example 22 with ClusterManager

use of edu.ucsf.rbvi.clusterMaker2.internal.api.ClusterManager in project clusterMaker2 by RBVI.

the class AbstractNetworkFilter method run.

public void run(TaskMonitor monitor) {
    monitor.setTitle("Filtering using " + getName());
    this.monitor = monitor;
    if (network == null)
        network = clusterManager.getNetwork();
    clusterAttributeName = getClusterAttributeName();
    // get the cluster list
    List<NodeCluster> clusterList = AbstractNetworkClusterer.getNodeClusters(network, getClusterAttribute());
    List<NodeCluster> newClusterList = new ArrayList<NodeCluster>();
    Map<NodeCluster, List<CyNode>> addedNodeMap = new HashMap<NodeCluster, List<CyNode>>();
    // Iterate over clusters and build a new clusterList
    for (NodeCluster nodeList : clusterList) {
        NodeCluster newCluster = doFilter(nodeList, addedNodeMap);
        if (newCluster != null && newCluster.size() > 0)
            newClusterList.add(newCluster);
    }
    // Fixup our clusters
    if (addedNodeMap.size() > 0) {
        // until this stabelized...
        for (NodeCluster addedCluster : addedNodeMap.keySet()) {
            for (NodeCluster cluster : newClusterList) {
                if (cluster.equals(addedCluster))
                    continue;
                removeNodes(cluster, addedNodeMap.get(addedCluster));
            }
        }
    }
    monitor.showMessage(TaskMonitor.Level.INFO, "Removing groups");
    // Remove any leftover groups from previous runs
    removeGroups(network, groupAttribute);
    monitor.showMessage(TaskMonitor.Level.INFO, "Creating groups");
    List<List<CyNode>> nodeClusters = createGroups(network, newClusterList, groupAttribute);
    results = new AbstractClusterResults(network, clusterList);
    ClusterResults results2 = new AbstractClusterResults(network, newClusterList);
    monitor.showMessage(TaskMonitor.Level.INFO, "Done.  Results:\n\nBefore Filter:\n" + results + "\n\nAfter Filter:\n" + results2);
    if (showUI()) {
        monitor.showMessage(TaskMonitor.Level.INFO, "Creating network");
        insertTasksAfterCurrentTask(new NewNetworkView(network, clusterManager, true, restoreEdges(), false));
    }
}
Also used : FuzzyNodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.FuzzyNodeCluster) NodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster) NewNetworkView(edu.ucsf.rbvi.clusterMaker2.internal.ui.NewNetworkView) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CyNode(org.cytoscape.model.CyNode) AbstractClusterResults(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults) AbstractClusterResults(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults) ClusterResults(edu.ucsf.rbvi.clusterMaker2.internal.api.ClusterResults)

Aggregations

ArrayList (java.util.ArrayList)13 List (java.util.List)12 AbstractClusterResults (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults)11 CyMatrix (edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix)11 NewNetworkView (edu.ucsf.rbvi.clusterMaker2.internal.ui.NewNetworkView)11 NodeCluster (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster)8 KnnView (edu.ucsf.rbvi.clusterMaker2.internal.ui.KnnView)5 FuzzyNodeCluster (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.FuzzyNodeCluster)3 BiclusterView (edu.ucsf.rbvi.clusterMaker2.internal.ui.BiclusterView)3 CyNode (org.cytoscape.model.CyNode)3 HashMap (java.util.HashMap)2 AttributeClusterTaskFactory (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.AttributeClusterTaskFactory)1 ChengChurchTaskFactory (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.ChengChurch.ChengChurchTaskFactory)1 DBSCANTaskFactory (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.DBSCAN.DBSCANTaskFactory)1 AutoSOMETaskFactory (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.autosome.AutoSOMETaskFactory)1 FeatureVectorTaskFactory (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.featureVector.FeatureVectorTaskFactory)1 FFTTaskFactory (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.fft.FFTTaskFactory)1 HierarchicalTaskFactory (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.hierarchical.HierarchicalTaskFactory)1 HopachPAMTaskFactory (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.hopach.HopachPAMTaskFactory)1 KMeansTaskFactory (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.kmeans.KMeansTaskFactory)1