use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster 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.NodeCluster in project clusterMaker2 by RBVI.
the class Fuzzifier method getClusters.
/**
* The method creates a list of NodeCLusters from the cluster attributes of the network
* This serves as the input for the fuzzifeir algorithm
* @return A list of NodeClusters
*/
public List<NodeCluster> getClusters() {
List<NodeCluster> nodeClusters = new ArrayList<NodeCluster>();
HashMap<Integer, List<CyNode>> clusterMap = new HashMap<Integer, List<CyNode>>();
if (network == null)
return nodeClusters;
List<CyNode> nodeList = network.getNodeList();
clusterAttributeName = network.getRow(network).get("__clusterAttribute", String.class);
// Save the seed cluster we used
ModelUtils.createAndSetLocal(network, network, "__fuzzifierSeed", clusterAttributeName, String.class, null);
for (CyNode node : nodeList) {
// System.out.println("Node SUID:"+node.getSUID());
if (ModelUtils.hasAttribute(network, node, clusterAttributeName)) {
Integer cluster = network.getRow(node).get(clusterAttributeName, Integer.class);
// System.out.println("Cluster for "+node.getSUID()+"--"+cluster);
if (!clusterMap.containsKey(cluster))
clusterMap.put(cluster, new ArrayList<CyNode>());
clusterMap.get(cluster).add(node);
}
}
for (int key : clusterMap.keySet()) {
nodeClusters.add(new NodeCluster(clusterMap.get(key)));
}
// System.out.println("NodeCluster Size : " +nodeClusters.size());
return nodeClusters;
}
use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster in project clusterMaker2 by RBVI.
the class RunFuzzifier method getFuzzyCenters.
/**
* The method calculates the centers of fuzzy clusters
*
* @param cData matrix to store the data for cluster centers
*/
public void getFuzzyCenters(CyMatrix cData) {
// To store the sum of memberships(raised to fuzziness index) corresponding to each cluster
int nelements = distanceMatrix.nRows();
for (NodeCluster cluster : Clusters) {
int c = Clusters.indexOf(cluster);
double numerator = 0;
Double distance = 0.0;
int i = 0;
for (int e = 0; e < nelements; e++) {
numerator = 0;
for (CyNode node : cluster) {
i = nodeList.indexOf(node);
distance = distanceMatrix.doubleValue(i, e);
numerator += distance;
}
cData.setValue(c, e, (numerator / cluster.size()));
}
}
}
use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster 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.NodeCluster in project clusterMaker2 by RBVI.
the class RunSCPS method doComponentClustering.
// Store all components length greater then 5 in clusters, if number components is greater then K
public void doComponentClustering() {
// Connected Componets
Map<Integer, List<CyNode>> cMap = MatrixUtils.findConnectedComponents(distanceMatrix);
// Iterate through connected components
int component_size_sum = 0;
for (List<CyNode> component : cMap.values()) {
if (component.size() > 5) {
NodeCluster iCluster = new NodeCluster(component);
iCluster.setClusterNumber(this.clusterCount);
this.clusterMap.put(new Integer(clusterCount), iCluster);
this.clusterCount++;
}
}
}
Aggregations