Search in sources :

Example 11 with NodeCluster

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

the class MCODEClusterObj method getNodeCluster.

public NodeCluster getNodeCluster() {
    NodeCluster result = new NodeCluster();
    List nodes = graph.getNodeList();
    result.addAll(nodes);
    result.setClusterScore(clusterScore);
    return result;
}
Also used : NodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster) List(java.util.List) ArrayList(java.util.ArrayList)

Example 12 with NodeCluster

use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster 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 13 with NodeCluster

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

Example 14 with NodeCluster

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

the class ClusterUtils method fetchRankingResults.

public static List<NodeCluster> fetchRankingResults(CyNetwork network) {
    List<NodeCluster> clusters = new ArrayList<>();
    String clusterAttribute = getClusterAttribute(network);
    String rankingAttribute = getRankingAttribute(network);
    Map<Integer, ArrayList<CyNode>> clusterMap = new HashMap<>();
    Map<Integer, Double> clusterScoreMap = new HashMap<>();
    for (CyNode node : network.getNodeList()) {
        if (ModelUtils.hasAttribute(network, node, clusterAttribute) && ModelUtils.hasAttribute(network, node, rankingAttribute)) {
            Integer cluster = network.getRow(node).get(clusterAttribute, Integer.class);
            Double clusterScore = network.getRow(node).get(rankingAttribute, Double.class, 0.0);
            if (!clusterMap.containsKey(cluster)) {
                clusterMap.put(cluster, new ArrayList<>());
                clusterScoreMap.put(cluster, clusterScore);
            }
            clusterMap.get(cluster).add(node);
        }
    }
    for (int clusterNum : clusterMap.keySet()) {
        NodeCluster cluster = new NodeCluster(clusterMap.get(clusterNum));
        cluster.setClusterNumber(clusterNum);
        cluster.setRankScore(clusterScoreMap.get(clusterNum));
        clusters.add(cluster);
    }
    ascendingSort(clusters);
    return clusters;
}
Also used : NodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 15 with NodeCluster

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

the class BestNeighborFilter method doFilter.

/**
 * Add any nodes that are above the neighbor threshold to
 * our cluster
 */
public NodeCluster doFilter(List<CyNode> nodeList, Map<NodeCluster, List<CyNode>> addedNodeMap) {
    Set<CyNode> clusterNodes = new HashSet<CyNode>(nodeList);
    List<CyNode> newNodeList = new ArrayList<CyNode>();
    newNodeList.addAll(nodeList);
    List<CyNode> nodesToAdd = new ArrayList<CyNode>();
    for (CyNode node : nodeList) {
        for (CyNode neighbor : network.getNeighborList(node, CyEdge.Type.ANY)) {
            if (clusterNodes.contains(neighbor))
                continue;
            double adjacency = getAdjacency(neighbor, clusterNodes);
            if (adjacency > context.threshold) {
                // Add this node to our list
                nodesToAdd.add(neighbor);
            }
        }
    }
    newNodeList.addAll(nodesToAdd);
    if (newNodeList.size() > 1) {
        NodeCluster newNodeCluster = new NodeCluster(newNodeList);
        if (nodesToAdd.size() > 0)
            addedNodeMap.put(newNodeCluster, nodesToAdd);
        return newNodeCluster;
    }
    return null;
}
Also used : NodeCluster(edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster) ArrayList(java.util.ArrayList) CyNode(org.cytoscape.model.CyNode) HashSet(java.util.HashSet)

Aggregations

NodeCluster (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster)39 ArrayList (java.util.ArrayList)25 CyNode (org.cytoscape.model.CyNode)18 HashMap (java.util.HashMap)17 AbstractClusterResults (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults)15 List (java.util.List)15 NewNetworkView (edu.ucsf.rbvi.clusterMaker2.internal.ui.NewNetworkView)9 CyMatrix (edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix)7 FuzzyNodeCluster (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.FuzzyNodeCluster)5 DoubleArrayList (cern.colt.list.tdouble.DoubleArrayList)3 IntArrayList (cern.colt.list.tint.IntArrayList)3 PREdge (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.ranking.units.PREdge)3 PRNode (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.ranking.units.PRNode)3 CyEdge (org.cytoscape.model.CyEdge)3 DoubleMatrix2D (cern.colt.matrix.tdouble.DoubleMatrix2D)2 HashSet (java.util.HashSet)2 Edges (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.costmatrixcreation.dataTypes.Edges)1 IteratorThread (edu.ucsf.rbvi.clusterMaker2.internal.algorithms.networkClusterers.TransClust.de.layclust.iterativeclustering.IteratorThread)1 ClusterResults (edu.ucsf.rbvi.clusterMaker2.internal.api.ClusterResults)1 Matrix (edu.ucsf.rbvi.clusterMaker2.internal.api.Matrix)1