use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster in project clusterMaker2 by RBVI.
the class MCODEClusterObj method getNodeCluster.
public NodeCluster getNodeCluster() {
NodeCluster result = new NodeCluster();
List nodes = graph.getNodeList();
result.addAll(nodes);
result.setClusterScore(clusterScore);
return result;
}
use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster in project clusterMaker2 by RBVI.
the class AutoSOMECluster method run.
public void run(TaskMonitor monitor) {
this.monitor = monitor;
monitor.setTitle("Performing " + getName());
String networkID = ModelUtils.getNetworkName(network);
// Update settings from our context
settings = context.getSettings();
// got back to parent to cluster again
if (networkID.contains("--AutoSOME")) {
String[] tokens = networkID.split("--AutoSOME");
networkID = tokens[0];
network = ModelUtils.getNetworkWithName(clusterManager, networkID);
}
List<String> dataAttributes = context.attributeList.getNodeAttributeList();
// Cluster the nodes
runAutoSOME = new RunAutoSOME(clusterManager, dataAttributes, network, settings, monitor);
runAutoSOME.setIgnoreMissing(context.ignoreMissing);
runAutoSOME.setSelectedOnly(context.selectedOnly);
runAutoSOME.setDebug(debug);
monitor.setStatusMessage("Running AutoSOME" + ((settings.distMatrix) ? " Fuzzy Clustering" : ""));
nodeCluster = runAutoSOME.run(monitor);
if (nodeCluster == null) {
monitor.setStatusMessage("Clustering failed!");
return;
}
if (nodeCluster.size() > 0)
finishedClustering = true;
monitor.setStatusMessage("Removing groups");
// Remove any leftover groups from previous runs
removeGroups(network, getShortName());
monitor.setStatusMessage("Creating groups");
if (settings.distMatrix)
runAutoSOME.getEdges(context.maxEdges);
attrList = runAutoSOME.attrList;
attrOrderList = runAutoSOME.attrOrderList;
nodeOrderList = runAutoSOME.nodeOrderList;
ModelUtils.createAndSetLocal(network, network, ClusterManager.CLUSTER_NODE_ATTRIBUTE, attrList, List.class, String.class);
ModelUtils.createAndSetLocal(network, network, ClusterManager.ARRAY_ORDER_ATTRIBUTE, attrOrderList, List.class, String.class);
ModelUtils.createAndSetLocal(network, network, ClusterManager.NODE_ORDER_ATTRIBUTE, nodeOrderList, List.class, String.class);
ModelUtils.createAndSetLocal(network, network, ClusterManager.CLUSTER_TYPE_ATTRIBUTE, getShortName(), String.class, null);
List<List<CyNode>> nodeClusters;
if (!settings.distMatrix) {
nodeClusters = createGroups(network, nodeCluster, GROUP_ATTRIBUTE);
results = new AbstractClusterResults(network, nodeCluster);
monitor.setStatusMessage("Done. AutoSOME results:\n" + results);
} else {
nodeClusters = new ArrayList<List<CyNode>>();
/*
for (NodeCluster cluster: clusters) {
List<CyNode>nodeList = new ArrayList();
for (CyNode node: cluster) {
nodeList.add(node);
}
nodeClusters.add(nodeList);
}
*/
monitor.setStatusMessage("Done. AutoSOME results:\n" + nodeCluster.size() + " clusters found.");
}
if (context.showViz) {
if (heatmap)
insertTasksAfterCurrentTask(new KnnView(clusterManager));
else
insertTasksAfterCurrentTask(new NewNetworkView(network, clusterManager, true, false, !context.selectedOnly));
}
}
use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster in project clusterMaker2 by RBVI.
the class ClusterUtils method setEdgeScoresInCluster.
public static List<NodeCluster> setEdgeScoresInCluster(CyNetwork network, List<NodeCluster> clusters, List<String> edgeAttributes, String clusterColumnName, boolean multiplicative) {
List<CyEdge> edges = network.getEdgeList();
CyTable nodeTable = network.getDefaultNodeTable();
CyTable edgeTable = network.getDefaultEdgeTable();
for (String edgeAttr : edgeAttributes) {
for (CyEdge edge : edges) {
CyRow source = nodeTable.getRow(edge.getSource().getSUID());
CyRow target = nodeTable.getRow(edge.getTarget().getSUID());
CyRow edgeRow = edgeTable.getRow(edge.getSUID());
int sourceClusterNumber = source.get(clusterColumnName, Integer.class, -1);
int targetClusterNumber = target.get(clusterColumnName, Integer.class, -1);
int sourceHighestClusterNumber = -1;
int targetHighestClusterNumber = -1;
for (NodeCluster cluster : clusters) {
int clusterNumber = cluster.getClusterNumber();
if (clusterNumber == sourceClusterNumber && (clusterNumber < sourceHighestClusterNumber || sourceHighestClusterNumber == -1)) {
if (multiplicative) {
setRankScoreMultiplicative(edgeAttr, edgeRow, cluster);
} else {
setRankScore(edgeAttr, edgeRow, cluster);
}
sourceHighestClusterNumber = clusterNumber;
} else if (clusterNumber == targetClusterNumber && (clusterNumber < targetHighestClusterNumber || targetHighestClusterNumber == -1)) {
if (multiplicative) {
setRankScoreMultiplicative(edgeAttr, edgeRow, cluster);
} else {
setRankScore(edgeAttr, edgeRow, cluster);
}
targetHighestClusterNumber = clusterNumber;
}
}
}
}
return clusters;
}
use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster in project clusterMaker2 by RBVI.
the class ClusterUtils method fetchRankingResults.
public static List<NodeCluster> fetchRankingResults(CyNetwork network) {
List<NodeCluster> clusters = new ArrayList<>();
String clusterAttribute = getClusterAttribute(network);
String rankingAttribute = getRankingAttribute(network);
Map<Integer, ArrayList<CyNode>> clusterMap = new HashMap<>();
Map<Integer, Double> clusterScoreMap = new HashMap<>();
for (CyNode node : network.getNodeList()) {
if (ModelUtils.hasAttribute(network, node, clusterAttribute) && ModelUtils.hasAttribute(network, node, rankingAttribute)) {
Integer cluster = network.getRow(node).get(clusterAttribute, Integer.class);
Double clusterScore = network.getRow(node).get(rankingAttribute, Double.class, 0.0);
if (!clusterMap.containsKey(cluster)) {
clusterMap.put(cluster, new ArrayList<>());
clusterScoreMap.put(cluster, clusterScore);
}
clusterMap.get(cluster).add(node);
}
}
for (int clusterNum : clusterMap.keySet()) {
NodeCluster cluster = new NodeCluster(clusterMap.get(clusterNum));
cluster.setClusterNumber(clusterNum);
cluster.setRankScore(clusterScoreMap.get(clusterNum));
clusters.add(cluster);
}
ascendingSort(clusters);
return clusters;
}
use of edu.ucsf.rbvi.clusterMaker2.internal.algorithms.NodeCluster in project clusterMaker2 by RBVI.
the class BestNeighborFilter method doFilter.
/**
* Add any nodes that are above the neighbor threshold to
* our cluster
*/
public NodeCluster doFilter(List<CyNode> nodeList, Map<NodeCluster, List<CyNode>> addedNodeMap) {
Set<CyNode> clusterNodes = new HashSet<CyNode>(nodeList);
List<CyNode> newNodeList = new ArrayList<CyNode>();
newNodeList.addAll(nodeList);
List<CyNode> nodesToAdd = new ArrayList<CyNode>();
for (CyNode node : nodeList) {
for (CyNode neighbor : network.getNeighborList(node, CyEdge.Type.ANY)) {
if (clusterNodes.contains(neighbor))
continue;
double adjacency = getAdjacency(neighbor, clusterNodes);
if (adjacency > context.threshold) {
// Add this node to our list
nodesToAdd.add(neighbor);
}
}
}
newNodeList.addAll(nodesToAdd);
if (newNodeList.size() > 1) {
NodeCluster newNodeCluster = new NodeCluster(newNodeList);
if (nodesToAdd.size() > 0)
addedNodeMap.put(newNodeCluster, nodesToAdd);
return newNodeCluster;
}
return null;
}
Aggregations