use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.Clusters in project clusterMaker2 by RBVI.
the class Fuzzifier method run.
/**
* The method run creates an instance of the RunFuzzifier and creates the fuzzy clusters
* by calling the fuzzifier algorithm.
* Also creates fuzzy groups and the Fuzzy Cluster Table
*
* @param Task Monitor
*/
public void run(TaskMonitor monitor) {
monitor.setTitle("Performing Fuzzifier clustering");
this.monitor = monitor;
if (network == null)
network = clusterManager.getNetwork();
super.network = network;
this.Clusters = getClusters();
this.cNumber = Clusters.size();
// Make sure to update the context
context.setNetwork(network);
Long networkID = network.getSUID();
CyTable nodeAttributes = network.getDefaultNodeTable();
CyMatrix distanceMatrix = context.edgeAttributeHandler.getMatrix();
if (distanceMatrix == null) {
monitor.showMessage(TaskMonitor.Level.ERROR, "Can't get distance matrix: no attribute value?");
return;
}
// Update our tunable results
clusterAttributeName = context.getClusterAttribute();
runFuzzifier = new RunFuzzifier(Clusters, distanceMatrix, cNumber, context.membershipThreshold.getValue(), context.maxThreads, monitor);
runFuzzifier.setDebug(debug);
if (canceled)
return;
monitor.showMessage(TaskMonitor.Level.INFO, "Clustering...");
List<FuzzyNodeCluster> FuzzyClusters = runFuzzifier.run(network, monitor);
// Canceled?
if (FuzzyClusters == 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, FuzzyClusters, GROUP_ATTRIBUTE);
results = new AbstractClusterResults(network, FuzzyClusters);
monitor.showMessage(TaskMonitor.Level.INFO, "Done. Fuzzifier 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));
} else {
monitor.showMessage(TaskMonitor.Level.INFO, "Done. Fizzifier results:\n" + results);
}
System.out.println("Creating fuzzy table");
createFuzzyTable(FuzzyClusters);
System.out.println("Done");
}
use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.Clusters in project clusterMaker2 by RBVI.
the class RunFuzzifier method run.
/**
* The method run has the actual implementation of the fuzzifier code
* @param monitor, Task monitor for the process
* @return List of FuzzyNodeCLusters
*/
public List<FuzzyNodeCluster> run(CyNetwork network, TaskMonitor monitor) {
Long networkID = network.getSUID();
long startTime = System.currentTimeMillis();
int nelements = distanceMatrix.nRows();
nodeList = distanceMatrix.getRowNodes();
// Matrix to store the temporary cluster membership values of elements
double[][] ClusterMemberships = new double[nelements][number_clusters];
// Initializing all membership values to 0
for (int i = 0; i < nelements; i++) {
for (int j = 0; j < number_clusters; j++) {
ClusterMemberships[i][j] = 0;
}
}
// This matrix will store the centroid data
CyMatrix cData = CyMatrixFactory.makeSmallMatrix(network, number_clusters, nelements);
getFuzzyCenters(cData);
for (CyNode node : nodeList) {
int nodeIndex = nodeList.indexOf(node);
double sumDistances = 0;
for (int i = 0; i < Clusters.size(); i++) {
sumDistances += cData.doubleValue(i, nodeIndex);
}
for (int i = 0; i < Clusters.size(); i++) {
ClusterMemberships[nodeIndex][i] = cData.doubleValue(i, nodeIndex) / sumDistances;
}
}
HashMap<CyNode, double[]> membershipMap = createMembershipMap(ClusterMemberships);
List<FuzzyNodeCluster> fuzzyClusters = new ArrayList<FuzzyNodeCluster>();
// Adding the nodes which have memberships greater than the threshold to fuzzy node clusters
List<CyNode> fuzzyNodeList;
for (int i = 0; i < number_clusters; i++) {
fuzzyNodeList = new ArrayList<CyNode>();
HashMap<CyNode, Double> clusterMembershipMap = new HashMap<CyNode, Double>();
for (CyNode node : nodeList) {
if (membershipMap.get(node)[i] > membershipThreshold) {
fuzzyNodeList.add(node);
clusterMembershipMap.put(node, membershipMap.get(node)[i]);
}
}
fuzzyClusters.add(new FuzzyNodeCluster(fuzzyNodeList, clusterMembershipMap));
}
return fuzzyClusters;
}
use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.attributeClusterers.Clusters 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.attributeClusterers.Clusters 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.attributeClusterers.Clusters 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));
}
}
Aggregations