use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults 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...");
}
use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults in project clusterMaker2 by RBVI.
the class ResultsPanelTask method getClusters.
public List<NodeCluster> getClusters() {
List<NodeCluster> clusters = new ArrayList<NodeCluster>();
// List<List<CyNode>> clusterList = new ArrayList<List<CyNode>>();
/*
System.out.println(network.NAME);
System.out.println(CyNetwork.LOCAL_ATTRS);
System.out.println(ClusterManager.CLUSTER_ATTRIBUTE);
*/
clusterAttribute = network.getRow(network, CyNetwork.LOCAL_ATTRS).get(ClusterManager.CLUSTER_ATTRIBUTE, String.class);
// Create a temporary cluster map
Map<Integer, ArrayList<CyNode>> clusterMap = new HashMap<Integer, ArrayList<CyNode>>();
for (CyNode node : (List<CyNode>) network.getNodeList()) {
// For each node -- see if it's in a cluster. If so, add it to our map
if (ModelUtils.hasAttribute(network, node, clusterAttribute)) {
Integer cluster = network.getRow(node).get(clusterAttribute, Integer.class);
if (!clusterMap.containsKey(cluster))
clusterMap.put(cluster, new ArrayList<CyNode>());
clusterMap.get(cluster).add(node);
}
}
// See if this algorithm provided it's own scores
List<Double> scores = null;
if (network.getDefaultNetworkTable().getColumn(clusterAttribute + "_Scores") != null) {
scores = network.getRow(network, CyNetwork.LOCAL_ATTRS).getList(clusterAttribute + "_Scores", Double.class);
}
for (int clustNum : clusterMap.keySet()) {
NodeCluster cluster = new NodeCluster(clusterMap.get(clustNum));
cluster.setClusterNumber(clustNum);
if (scores != null)
cluster.setClusterScore(scores.get(clustNum - 1));
clusters.add(cluster);
}
// calculating the scores for each cluster
clusterResults = new AbstractClusterResults(network, clusters);
List<Double> modularityList;
if (scores == null) {
modularityList = clusterResults.getModularityList();
} else {
modularityList = scores;
}
for (int i = 0; i < clusters.size(); i++) {
clusters.get(i).setClusterScore(modularityList.get(i));
}
return clusters;
}
use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults 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)));
}
}
use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults 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));
}
}
use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.AbstractClusterResults 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));
}
}
Aggregations