use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster in project clusterMaker2 by RBVI.
the class SCPSCluster method run.
public void run(TaskMonitor monitor) {
monitor.setTitle("Performing SCPS 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;
// Cluster the nodes
runSCPS = new RunSCPS(matrix, context.epsilon, context.clusters, context.iterations, monitor);
monitor.showMessage(TaskMonitor.Level.INFO, "Clustering...");
List<NodeCluster> clusterList = runSCPS.run(network, monitor);
// Canceled?
if (clusterList == 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 = createGroups(network, clusterList, GROUP_ATTRIBUTE);
results = new AbstractClusterResults(network, clusterList);
monitor.showMessage(TaskMonitor.Level.INFO, "Done. SCPS 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));
}
}
use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster in project clusterMaker2 by RBVI.
the class RunTransClust method getClusterMap.
private Map<Integer, NodeCluster> getClusterMap(String[] clusters, HashMap<String, CyNode> nodeHash) {
HashMap<Integer, NodeCluster> clusterMap = new HashMap<Integer, NodeCluster>();
for (int i = 0; i < clusters.length; i++) {
String[] elements = clusters[i].split(",");
NodeCluster nc = new NodeCluster();
for (int j = 0; j < elements.length; j++) {
if (nodeHash.containsKey(elements[j].trim())) {
nc.add(nodeHash.get(elements[j].trim()));
}
}
clusterCount++;
updateClusters(nc, clusterMap);
}
return clusterMap;
}
use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster in project clusterMaker2 by RBVI.
the class RunTransClust method run.
public List<NodeCluster> run(TaskMonitor monitor, CyNetwork network) {
DoubleMatrix2D matrix = this.distanceMatrix.getColtMatrix();
nodes = distanceMatrix.getRowNodes();
HashMap<String, CyNode> nodeHash = new HashMap<String, CyNode>();
for (CyNode node : nodes) {
nodeHash.put(ModelUtils.getNodeName(network, node), node);
}
HashMap<String, Integer> integers2proteins = new HashMap<String, Integer>();
HashMap<Integer, String> proteins2integers = new HashMap<Integer, String>();
int count = 0;
for (CyNode node : this.nodes) {
integers2proteins.put(ModelUtils.getNodeName(network, node), count);
proteins2integers.put(count, ModelUtils.getNodeName(network, node));
count++;
}
Edges es = new Edges(this.nodes.size() * this.nodes.size(), this.nodes.size());
count = 0;
for (int i = 0; i < this.nodes.size(); i++) {
CyNode cyNodeI = this.nodes.get(i);
es.startPositions[integers2proteins.get(cyNodeI.getSUID())] = count;
for (int j = 0; j < this.nodes.size(); j++) {
CyNode cyNodeJ = this.nodes.get(j);
es.sources[count] = i;
es.targets[count] = j;
Double val = distanceMatrix.getValue(i, j);
if (val != null) {
es.values[count] = val.floatValue();
count++;
}
}
es.endPositions[integers2proteins.get(cyNodeI.getSUID())] = count - 1;
}
Semaphore s = new Semaphore(1);
TaskConfig.mode = TaskConfig.COMPARISON_MODE;
TaskConfig.monitor = monitor;
IteratorThread it = new IteratorThread(es, integers2proteins, proteins2integers, s);
TaskConfig.minThreshold = threshold;
TaskConfig.maxThreshold = threshold;
try {
s.acquire();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
it.start();
monitor.showMessage(TaskMonitor.Level.INFO, "Executing TransClust Clustering...");
try {
s.acquire();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
monitor.showMessage(TaskMonitor.Level.INFO, "Assigning nodes to clusters");
String result = it.resultsStringBuffer.toString();
String[] clusters = result.split("\t")[2].split(";");
Map<Integer, NodeCluster> clusterMap = getClusterMap(clusters, nodeHash);
// Update node attributes in network to include clusters. Create cygroups from clustered nodes
monitor.showMessage(TaskMonitor.Level.INFO, "Created " + clusterMap.size() + " clusters");
if (clusterCount == 0) {
monitor.showMessage(TaskMonitor.Level.ERROR, "Created 0 clusters!!!!");
return null;
}
int clusterNumber = 1;
Map<NodeCluster, NodeCluster> cMap = new HashMap();
for (NodeCluster cluster : NodeCluster.sortMap(clusterMap)) {
if (cMap.containsKey(cluster))
continue;
cMap.put(cluster, cluster);
cluster.setClusterNumber(clusterNumber);
clusterNumber++;
}
Set<NodeCluster> clusters2 = cMap.keySet();
return new ArrayList<NodeCluster>(clusters2);
}
use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster in project clusterMaker2 by RBVI.
the class TransClustCluster method run.
/**
* Perform the actual clustering. For TransClust, there are really
* two steps:
* 1) Assign all of the connected components
* 2) Do the TransClust clustering.
*
* There is also an optional approach called evolutionary parameter
* tuning, which takes a lot longer and is probably less relevant for
* the Cytoscape integration.
*
* @param monitor the TaskMonitor to use
*/
public void run(TaskMonitor monitor) {
monitor.setTitle("Performing Transitivity clustering");
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;
}
updateSettings();
runTransClust = new RunTransClust(matrix, context.edgeAttributeHandler.edgeCutOff.getValue(), monitor);
if (canceled)
return;
monitor.showMessage(TaskMonitor.Level.INFO, "Clustering...");
createGroups = context.advancedAttributes.createGroups;
// Cluster the nodes
List<NodeCluster> clusters = runTransClust.run(monitor, network);
// 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 = createGroups(network, clusters, GROUP_ATTRIBUTE);
results = new AbstractClusterResults(network, clusters);
monitor.setStatusMessage("Done. TransClust 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));
}
}
use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster in project clusterMaker2 by RBVI.
the class RunSCPS method doKMeansClustering.
public void doKMeansClustering(DoubleMatrix2D uMat, DoubleMatrix2D sMat) {
int k = uMat.columns();
int[] clusterArray = new int[uMat.rows()];
// do kmeans clustering
KCluster.kmeans(k, rnumber, uMat, clusterArray);
// redistribute cluster results
clusterArray = redistributeMaxCluster(clusterArray, sMat, k);
for (int cluster_id = 0; cluster_id < k; cluster_id++) {
NodeCluster iCluster = new NodeCluster();
List<CyNode> node_list = new ArrayList<CyNode>();
for (int j = 0; j < clusterArray.length; j++) {
// node j in uMatrix belongs to cluster #cluster_id
if (clusterArray[j] == cluster_id)
node_list.add(this.nodes.get(getMap_old(j)));
}
iCluster = new NodeCluster(node_list);
iCluster.setClusterNumber(this.clusterCount);
this.clusterMap.put(new Integer(clusterCount), iCluster);
System.out.println("Clustercount " + this.clusterCount + " cluster_id " + cluster_id + " node_list_length " + node_list.size());
this.clusterCount++;
}
}
Aggregations