use of edu.ucsf.rbvi.clusterMaker2.internal.api.ClusterResults in project clusterMaker2 by RBVI.
the class ResultsPanelTask method getClusters.
public List<NodeCluster> getClusters() {
List<NodeCluster> clusters = new ArrayList<NodeCluster>();
// List<List<CyNode>> clusterList = new ArrayList<List<CyNode>>();
/*
System.out.println(network.NAME);
System.out.println(CyNetwork.LOCAL_ATTRS);
System.out.println(ClusterManager.CLUSTER_ATTRIBUTE);
*/
clusterAttribute = network.getRow(network, CyNetwork.LOCAL_ATTRS).get(ClusterManager.CLUSTER_ATTRIBUTE, String.class);
// Create a temporary cluster map
Map<Integer, ArrayList<CyNode>> clusterMap = new HashMap<Integer, ArrayList<CyNode>>();
for (CyNode node : (List<CyNode>) network.getNodeList()) {
// For each node -- see if it's in a cluster. If so, add it to our map
if (ModelUtils.hasAttribute(network, node, clusterAttribute)) {
Integer cluster = network.getRow(node).get(clusterAttribute, Integer.class);
if (!clusterMap.containsKey(cluster))
clusterMap.put(cluster, new ArrayList<CyNode>());
clusterMap.get(cluster).add(node);
}
}
// See if this algorithm provided it's own scores
List<Double> scores = null;
if (network.getDefaultNetworkTable().getColumn(clusterAttribute + "_Scores") != null) {
scores = network.getRow(network, CyNetwork.LOCAL_ATTRS).getList(clusterAttribute + "_Scores", Double.class);
}
for (int clustNum : clusterMap.keySet()) {
NodeCluster cluster = new NodeCluster(clusterMap.get(clustNum));
cluster.setClusterNumber(clustNum);
if (scores != null)
cluster.setClusterScore(scores.get(clustNum - 1));
clusters.add(cluster);
}
// calculating the scores for each cluster
clusterResults = new AbstractClusterResults(network, clusters);
List<Double> modularityList;
if (scores == null) {
modularityList = clusterResults.getModularityList();
} else {
modularityList = scores;
}
for (int i = 0; i < clusters.size(); i++) {
clusters.get(i).setClusterScore(modularityList.get(i));
}
return clusters;
}
use of edu.ucsf.rbvi.clusterMaker2.internal.api.ClusterResults in project clusterMaker2 by RBVI.
the class AbstractNetworkFilter method run.
public void run(TaskMonitor monitor) {
monitor.setTitle("Filtering using " + getName());
this.monitor = monitor;
if (network == null)
network = clusterManager.getNetwork();
clusterAttributeName = getClusterAttributeName();
// get the cluster list
List<NodeCluster> clusterList = AbstractNetworkClusterer.getNodeClusters(network, getClusterAttribute());
List<NodeCluster> newClusterList = new ArrayList<NodeCluster>();
Map<NodeCluster, List<CyNode>> addedNodeMap = new HashMap<NodeCluster, List<CyNode>>();
// Iterate over clusters and build a new clusterList
for (NodeCluster nodeList : clusterList) {
NodeCluster newCluster = doFilter(nodeList, addedNodeMap);
if (newCluster != null && newCluster.size() > 0)
newClusterList.add(newCluster);
}
// Fixup our clusters
if (addedNodeMap.size() > 0) {
// until this stabelized...
for (NodeCluster addedCluster : addedNodeMap.keySet()) {
for (NodeCluster cluster : newClusterList) {
if (cluster.equals(addedCluster))
continue;
removeNodes(cluster, addedNodeMap.get(addedCluster));
}
}
}
monitor.showMessage(TaskMonitor.Level.INFO, "Removing groups");
// Remove any leftover groups from previous runs
removeGroups(network, groupAttribute);
monitor.showMessage(TaskMonitor.Level.INFO, "Creating groups");
List<List<CyNode>> nodeClusters = createGroups(network, newClusterList, groupAttribute);
results = new AbstractClusterResults(network, clusterList);
ClusterResults results2 = new AbstractClusterResults(network, newClusterList);
monitor.showMessage(TaskMonitor.Level.INFO, "Done. Results:\n\nBefore Filter:\n" + results + "\n\nAfter Filter:\n" + results2);
if (showUI()) {
monitor.showMessage(TaskMonitor.Level.INFO, "Creating network");
insertTasksAfterCurrentTask(new NewNetworkView(network, clusterManager, true, restoreEdges(), false));
}
}
Aggregations