Search in sources :

Example 6 with NewNetworkView

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

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

the class MCODECluster method run.

public void run(TaskMonitor monitor) {
    this.monitor = monitor;
    monitor.setTitle("Performing " + getName());
    updateSettings();
    if (network == null)
        network = clusterManager.getNetwork();
    context.setNetwork(network);
    NodeCluster.init();
    if (currentParamsCopy.getScope().equals(MCODEParameterSet.SELECTION)) {
        List<CyNode> selectedNodes = CyTableUtil.getNodesInState(network, CyNetwork.SELECTED, true);
        currentParamsCopy.setSelectedNodes(selectedNodes);
    }
    MCODECurrentParameters.getInstance().setParams(currentParamsCopy, "MCODE Result", ModelUtils.getNetworkName(network));
    runMCODE = new RunMCODE(RESCORE, 1, network, monitor);
    List<NodeCluster> clusters = runMCODE.run(monitor);
    if (canceled) {
        monitor.showMessage(TaskMonitor.Level.INFO, "Canceled by user");
        return;
    }
    monitor.showMessage(TaskMonitor.Level.INFO, "Found " + clusters.size() + " clusters");
    if (clusters == null || clusters.size() == 0) {
        monitor.showMessage(TaskMonitor.Level.WARN, "Didn't find any clusters!");
        return;
    }
    // Now, sort our list of clusters by score
    clusters = NodeCluster.rankListByScore(clusters);
    List<Double> scoreList = NodeCluster.getScoreList(clusters);
    clusterAttributeName = context.getClusterAttribute();
    createGroups = context.advancedAttributes.createGroups;
    monitor.showMessage(TaskMonitor.Level.INFO, "Removing groups");
    // Remove any leftover groups from previous runs
    removeGroups(network, GROUP_ATTRIBUTE);
    monitor.setStatusMessage("Creating groups");
    List<List<CyNode>> nodeClusters = createGroups(network, clusters, GROUP_ATTRIBUTE);
    results = new AbstractClusterResults(network, clusters);
    monitor.setStatusMessage("Done.  MCODE results:\n" + results);
    if (context.vizProperties.showUI) {
        monitor.showMessage(TaskMonitor.Level.INFO, "Creating network");
        insertTasksAfterCurrentTask(new NewNetworkView(network, clusterManager, true, context.vizProperties.restoreEdges, !currentParamsCopy.getScope().equals(MCODEParameterSet.SELECTION)));
    }
}
Also used : NodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster) NewNetworkView(edu.ucsf.rbvi.clusterMaker2.internal.ui.NewNetworkView) CyNode(org.cytoscape.model.CyNode) ArrayList(java.util.ArrayList) List(java.util.List) AbstractClusterResults(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults)

Example 8 with NewNetworkView

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

the class GLayCluster method run.

public void run(TaskMonitor monitor) {
    this.monitor = monitor;
    monitor.setTitle("Performing community clustering (GLay)");
    createGroups = context.advancedAttributes.createGroups;
    clusterAttributeName = context.getClusterAttribute();
    if (network == null)
        network = clusterManager.getNetwork();
    // Make sure to update the context
    context.setNetwork(network);
    NodeCluster.init();
    GSimpleGraphData simpleGraph = new GSimpleGraphData(network, context.selectedOnly, context.undirectedEdges);
    fa = new FastGreedyAlgorithm();
    // fa.partition(simpleGraph);
    fa.execute(simpleGraph, monitor);
    NumberFormat nf = NumberFormat.getInstance();
    String modularityString = nf.format(fa.getModularity());
    List<NodeCluster> clusterList = new ArrayList<NodeCluster>();
    for (int cluster = 0; cluster < fa.getClusterNumber(); cluster++) {
        clusterList.add(new NodeCluster());
    }
    int[] membership = fa.getMembership();
    for (int index = 0; index < simpleGraph.graphIndices.length; index++) {
        int cluster = membership[index];
        clusterList.get(cluster).add(simpleGraph.graphIndices[index]);
    }
    monitor.showMessage(TaskMonitor.Level.INFO, "Found " + clusterList.size() + " clusters");
    // Remove any leftover groups from previous runs
    removeGroups(network, GROUP_ATTRIBUTE);
    monitor.showMessage(TaskMonitor.Level.INFO, "Creating groups");
    List<List<CyNode>> nodeClusters = createGroups(network, clusterList, GROUP_ATTRIBUTE);
    results = new AbstractClusterResults(network, clusterList);
    monitor.showMessage(TaskMonitor.Level.INFO, "Done.  Community Clustering results:\n" + results);
    if (context.vizProperties.showUI) {
        monitor.showMessage(TaskMonitor.Level.INFO, "Creating network");
        insertTasksAfterCurrentTask(new NewNetworkView(network, clusterManager, true, context.vizProperties.restoreEdges, !context.selectedOnly));
    }
}
Also used : NewNetworkView(edu.ucsf.rbvi.clusterMaker2.internal.ui.NewNetworkView) ArrayList(java.util.ArrayList) NodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster) ArrayList(java.util.ArrayList) List(java.util.List) AbstractClusterResults(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults) NumberFormat(java.text.NumberFormat)

Example 9 with NewNetworkView

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

the class ConnectedComponentsCluster method run.

public void run(TaskMonitor monitor) {
    monitor.setTitle("Performing ConnectedComponents 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;
    Map<Integer, List<CyNode>> components = MatrixUtils.findConnectedComponents(matrix);
    // Create the NodeClusters
    Map<Integer, NodeCluster> clusterMap = new HashMap<Integer, NodeCluster>();
    for (Integer cluster : components.keySet()) {
        clusterMap.put(cluster, new NodeCluster(components.get(cluster)));
    }
    // Now get the sorted cluster map
    int clusterNumber = 1;
    HashMap<NodeCluster, NodeCluster> cMap = new HashMap<NodeCluster, NodeCluster>();
    for (NodeCluster cluster : NodeCluster.sortMap(clusterMap)) {
        if (cMap.containsKey(cluster))
            continue;
        cMap.put(cluster, cluster);
        cluster.setClusterNumber(clusterNumber);
        clusterNumber++;
    }
    List<NodeCluster> clusters = new ArrayList<NodeCluster>(cMap.keySet());
    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, "ConnectedComponent 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) NewNetworkView(edu.ucsf.rbvi.clusterMaker2.internal.ui.NewNetworkView) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) NodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster) ArrayList(java.util.ArrayList) List(java.util.List) AbstractClusterResults(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults)

Example 10 with NewNetworkView

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

Aggregations

AbstractClusterResults (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults)11 NewNetworkView (edu.ucsf.rbvi.clusterMaker2.internal.ui.NewNetworkView)11 ArrayList (java.util.ArrayList)11 List (java.util.List)11 NodeCluster (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster)8 CyMatrix (edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix)6 FuzzyNodeCluster (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.FuzzyNodeCluster)3 HashMap (java.util.HashMap)2 CyNode (org.cytoscape.model.CyNode)2 CyTable (org.cytoscape.model.CyTable)2 ClusterResults (edu.ucsf.rbvi.clusterMaker2.internal.api.ClusterResults)1 KnnView (edu.ucsf.rbvi.clusterMaker2.internal.ui.KnnView)1 NumberFormat (java.text.NumberFormat)1