use of edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix in project clusterMaker2 by RBVI.
the class tSNE method getResults.
@Override
public <R> R getResults(Class<? extends R> type) {
CyMatrix results = runtsne.getResult();
if (type.equals(String.class)) {
results.setColumnLabel(0, "X");
results.setColumnLabel(1, "Y");
CyNetwork net = results.getNetwork();
for (int row = 0; row < results.nRows(); row++) {
CyNode node = results.getRowNode(row);
results.setRowLabel(row, ModelUtils.getName(net, node));
}
return (R) results.printMatrix();
} else if (type.equals(Map.class)) {
Map<CyNode, Point2D> resultsMap = new HashMap<>();
for (int row = 0; row < results.nRows(); row++) {
CyNode node = results.getRowNode(row);
resultsMap.put(node, new Point2D.Double(results.doubleValue(row, 0), results.doubleValue(row, 1)));
}
return (R) resultsMap;
}
return (R) results;
}
use of edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix in project clusterMaker2 by RBVI.
the class ScatterPlotDialog method copyLayoutToCytoscape.
private void copyLayoutToCytoscape() {
CyMatrix coordinates = scores[0];
CyNetworkView view = manager.getNetworkView(coordinates.getNetwork());
UndoSupport undo = manager.getService(UndoSupport.class);
ScatterPlotLayoutTask splt = new ScatterPlotLayoutTask(manager, title + " Layout", view, coordinates, undo);
splt.execute();
}
use of edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix 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.api.CyMatrix 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));
}
}
use of edu.ucsf.rbvi.clusterMaker2.internal.api.CyMatrix in project clusterMaker2 by RBVI.
the class CyColtMatrix method getDistanceMatrix.
public CyMatrix getDistanceMatrix(DistanceMetric metric) {
CyColtMatrix dist = new CyColtMatrix(network, nRows, nRows);
if (rowNodes != null) {
dist.rowNodes = Arrays.copyOf(rowNodes, nRows);
dist.columnNodes = Arrays.copyOf(rowNodes, nRows);
}
Matrix cMatrix = super.getDistanceMatrix(metric);
return dist.copy(cMatrix);
}
Aggregations