use of edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix 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.api.CyMatrix in project clusterMaker2 by RBVI.
the class RunSCPS method getSMat.
// Get Connected Components, cluster all components <= |5|, and connect the remaining components with random lowscoring edges
public DoubleMatrix2D getSMat(CyMatrix distanceMatrix) {
// Matrix prior to filtration modification
DoubleMatrix2D unfiltered_mat = distanceMatrix.getColtMatrix();
// Size of newly created Umat after filtering of small components
int sMat_rows = 0;
HashMap<Integer, List<CyNode>> filtered_cmap = new HashMap<Integer, List<CyNode>>();
// Connected Componets
Map<Integer, List<CyNode>> cMap = MatrixUtils.findConnectedComponents(distanceMatrix);
IntArrayList rowList = new IntArrayList();
IntArrayList columnList = new IntArrayList();
DoubleArrayList valueList = new DoubleArrayList();
// Iterate through connected components
int component_size_sum = 0;
for (List<CyNode> component : cMap.values()) {
numComponents += 1;
// Size <= 5. Automatically create cluster and increment clusterCount.
if (component.size() <= 5) {
NodeCluster iCluster = new NodeCluster(component);
iCluster.setClusterNumber(this.clusterCount);
// iCluster.add(component,this.clusterCount);
this.clusterMap.put(new Integer(clusterCount), iCluster);
this.clusterCount++;
} else {
// iterate through components and assign them index mappings in new uMatrix
component_size_sum += component.size();
System.out.println("Normal Component size " + component.size() + " Total Sum " + component_size_sum);
for (int i = 0; i < component.size(); i++) {
CyNode n = component.get(i);
int node_id = this.nodes.indexOf(n);
// set mapping of new matrix index to old index
setMap(node_id, sMat_rows);
sMat_rows++;
}
}
}
DoubleMatrix2D sMat = DoubleFactory2D.sparse.make(sMat_rows, sMat_rows);
// set diagnols of sMat to one
for (int i = 0; i < sMat_rows; i++) sMat.set(i, i, 1);
// iterate through nonzero edges. If both nodes in new index map, transfer the edge to new matrix
unfiltered_mat.getNonZeros(rowList, columnList, valueList);
for (int i = 0; i < rowList.size(); i++) {
int row_id = rowList.get(i);
int column_id = columnList.get(i);
int new_row_id = getMap_new(row_id);
int new_column_id = getMap_new(column_id);
double value = valueList.get(i);
// Set symmetrically the values in new matrix
if (new_row_id > -1 && new_column_id > -1) {
sMat.set(new_row_id, new_column_id, value);
sMat.set(new_column_id, new_row_id, value);
}
}
return sMat;
}
use of edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix in project clusterMaker2 by RBVI.
the class APCluster method run.
public void run(TaskMonitor monitor) {
monitor.setTitle("Performing AP 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
runAP = new RunAP(matrix, context.lambda, context.preference, context.rNumber, monitor, debug);
if (canceled)
return;
monitor.showMessage(TaskMonitor.Level.INFO, "Clustering...");
List<NodeCluster> clusters = runAP.run(network, monitor);
// 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);
setParams(params);
List<List<CyNode>> nodeClusters = createGroups(network, clusters, GROUP_ATTRIBUTE);
results = new AbstractClusterResults(network, clusters);
monitor.showMessage(TaskMonitor.Level.INFO, "Done. AP 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.api.CyMatrix in project clusterMaker2 by RBVI.
the class MCLCluster method run.
public void run(TaskMonitor monitor) {
monitor.setTitle("Performing MCL cluster");
this.monitor = monitor;
if (network == null)
network = clusterManager.getNetwork();
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
runMCL = new RunMCL(matrix, context.inflation_parameter, context.iterations, context.clusteringThresh, context.maxResidual, context.maxThreads, context.forceDecliningResidual, monitor);
runMCL.setDebug(false);
if (canceled)
return;
monitor.showMessage(TaskMonitor.Level.INFO, "Clustering...");
// results = runMCL.run(monitor);
List<NodeCluster> clusters = runMCL.run(network, monitor);
// 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.showMessage(TaskMonitor.Level.INFO, "MCL 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.api.CyMatrix in project clusterMaker2 by RBVI.
the class RunBiMine method getASR.
private double getASR(BETNode<Integer> node) {
List<Integer> genes = node.getGenes();
List<Integer> conditions = node.getConditions();
// Matrix data = new Matrix(network,genes.size(),conditions.size());
CyMatrix data = CyMatrixFactory.makeSmallMatrix(network, genes.size(), conditions.size());
for (int i = 0; i < genes.size(); i++) {
for (int j = 0; j < conditions.size(); j++) {
data.setValue(i, j, matrix.getValue(genes.get(i), conditions.get(j)));
// data_t.setValue(j, i, matrix.getValue(genes.get(i), conditions.get(j)));
}
}
double asr = 0.0;
double asr_g = 0.0;
double asr_c = 0.0;
for (int i = 0; i < genes.size(); i++) {
for (int j = i + 1; j < genes.size(); j++) {
// asr_g += geneRho[genes.get(i)][genes.get(j)];
asr_g += getSpearmansRho(data, i, j);
}
}
asr_g /= genes.size() * (genes.size() - 1);
/*
for(int i = 0; i < conditions.size(); i++){
for(int j = i+1; j < conditions.size(); j++){
//asr_c += conditionRho[conditions.get(i)][conditions.get(j)];
asr_c += getSpearmansRho(data_t,i,j);
}
}
asr_c /= conditions.size()*(conditions.size()-1);
*/
// asr = 2*Math.max(asr_g, asr_c);
asr = 2 * asr_g;
return asr;
}
Aggregations