use of edu.ucsf.rbvi.clusterMaker2.internal.api.ClusterManager in project clusterMaker2 by RBVI.
the class CyActivator method start.
public void start(BundleContext bc) {
// See if we have a graphics console or not
boolean haveGUI = true;
CySwingApplication swingAppRef = getService(bc, CySwingApplication.class);
if (swingAppRef == null) {
// if haveGUI is false, we don't want to provide any hooks to the treeview
haveGUI = false;
}
CyApplicationManager appRef = getService(bc, CyApplicationManager.class);
CyServiceRegistrar serviceRegistrar = getService(bc, CyServiceRegistrar.class);
CyGroupManager groupManager = getService(bc, CyGroupManager.class);
CyGroupFactory groupFactory = getService(bc, CyGroupFactory.class);
CyTableFactory tableFactory = getService(bc, CyTableFactory.class);
CyTableManager tableManager = getService(bc, CyTableManager.class);
// Create our context object. This will probably keep track of all of the
// registered clustering algorithms, settings, etc.
ClusterManagerImpl clusterManager = new ClusterManagerImpl(appRef, serviceRegistrar, groupFactory, groupManager, tableFactory, tableManager);
registerServiceListener(bc, clusterManager, "addClusterAlgorithm", "removeClusterAlgorithm", ClusterTaskFactory.class);
registerServiceListener(bc, clusterManager, "addClusterVisualizer", "removeClusterVisualizer", ClusterVizFactory.class);
registerServiceListener(bc, clusterManager, "addRankingAlgorithm", "removeRankingAlgorithm", RankFactory.class);
// Register each of our algorithms
// Attribute clusterers
registerService(bc, new AttributeClusterTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new AutoSOMETaskFactory(clusterManager, true), ClusterTaskFactory.class, new Properties());
registerService(bc, new FeatureVectorTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new HierarchicalTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new KMeansTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new KMedoidTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new HopachPAMTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new PAMTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
// FIXME: FFT is seriously broken!
registerService(bc, new FFTTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new DBSCANTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
/*
* Hold off on these until we get improve the performance sufficiently
* to allow them to be useful
*/
// registerService(bc, new BicFinderTaskFactory(clusterManager),
// ClusterTaskFactory.class, new Properties());
// registerService(bc, new BiMineTaskFactory(clusterManager),
// ClusterTaskFactory.class, new Properties());
registerService(bc, new ChengChurchTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
// Network clusterers
registerService(bc, new NetworkClusterTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new APClusterTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new AutoSOMETaskFactory(clusterManager, false), ClusterTaskFactory.class, new Properties());
registerService(bc, new FuzzifierTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new GLayClusterTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new ConnectedComponentsTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new FCMClusterTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new MCLClusterTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new MCODEClusterTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new SCPSClusterTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new TransClustClusterTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
// Cluster ranking
registerService(bc, new MAATaskFactory(clusterManager), RankFactory.class, new Properties());
registerService(bc, new MAMTaskFactory(clusterManager), RankFactory.class, new Properties());
registerService(bc, new PRWPTaskFactory(clusterManager), RankFactory.class, new Properties());
registerService(bc, new PRTaskFactory(clusterManager), RankFactory.class, new Properties());
registerService(bc, new HITSTaskFactory(clusterManager), RankFactory.class, new Properties());
// Filters
registerService(bc, new FilterTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new BestNeighborFilterTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new CuttingEdgeFilterTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new DensityFilterTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new HairCutFilterTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
// registerService(bc, new UITaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
// Visualizations
registerService(bc, new NewNetworkViewFactory(clusterManager, false), ClusterVizFactory.class, new Properties());
registerService(bc, new NewNetworkViewFactory(clusterManager, true), ClusterVizFactory.class, new Properties());
registerService(bc, new HeatMapViewTaskFactory(clusterManager), ClusterVizFactory.class, new Properties());
registerService(bc, new KnnViewTaskFactory(clusterManager), ClusterVizFactory.class, new Properties());
registerService(bc, new BiclusterViewTaskFactory(clusterManager), ClusterVizFactory.class, new Properties());
registerService(bc, new TreeViewTaskFactory(clusterManager), ClusterVizFactory.class, new Properties());
registerService(bc, new CreateResultsPanelTaskFactory(clusterManager, true), ClusterVizFactory.class, new Properties());
registerService(bc, new CreateRankingPanelTaskFactory(clusterManager, true), ClusterVizFactory.class, new Properties());
registerService(bc, new DestroyResultsPanelTaskFactory(clusterManager, true), ClusterVizFactory.class, new Properties());
registerService(bc, new DestroyRankingPanelTaskFactory(clusterManager, true), ClusterVizFactory.class, new Properties());
// Dimensionality Reduction
// registerService(bc, new PCAMenuTaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new PCATaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new PCoATaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
registerService(bc, new tSNETaskFactory(clusterManager), ClusterTaskFactory.class, new Properties());
{
// Link Network Selections
LinkSelectionTaskFactory linkTaskFactory = new LinkSelectionTaskFactory(clusterManager);
Properties linkSelectionProps = new Properties();
linkSelectionProps.setProperty(INSERT_SEPARATOR_BEFORE, "true");
linkSelectionProps.setProperty(PREFERRED_MENU, "Apps.clusterMaker Visualizations");
linkSelectionProps.setProperty(TITLE, "Link selection across networks");
linkSelectionProps.setProperty(COMMAND, "linkSelection");
linkSelectionProps.setProperty(COMMAND_NAMESPACE, "clusterviz");
linkSelectionProps.setProperty(ENABLE_FOR, "networkAndView");
linkSelectionProps.setProperty(IN_MENU_BAR, "true");
linkSelectionProps.setProperty(MENU_GRAVITY, "100.0");
registerService(bc, linkTaskFactory, NetworkTaskFactory.class, linkSelectionProps);
}
{
// UnLink Network Selections
UnlinkSelectionTaskFactory unlinkTaskFactory = new UnlinkSelectionTaskFactory(clusterManager);
Properties unlinkSelectionProps = new Properties();
unlinkSelectionProps.setProperty(PREFERRED_MENU, "Apps.clusterMaker Visualizations");
unlinkSelectionProps.setProperty(TITLE, "Unlink selection across networks");
unlinkSelectionProps.setProperty(COMMAND, "unlinkSelection");
unlinkSelectionProps.setProperty(COMMAND_NAMESPACE, "clusterviz");
unlinkSelectionProps.setProperty(ENABLE_FOR, "networkAndView");
unlinkSelectionProps.setProperty(IN_MENU_BAR, "true");
unlinkSelectionProps.setProperty(MENU_GRAVITY, "100.0");
registerService(bc, unlinkTaskFactory, NetworkTaskFactory.class, unlinkSelectionProps);
}
// Commands
// These task factories provide useful commands that only make sense in the context of REST or
// the command interface
{
TaskFactory commandTaskFactory = new CommandTaskFactory(clusterManager, "hascluster");
Properties props = new Properties();
props.setProperty(COMMAND_NAMESPACE, "cluster");
props.setProperty(COMMAND, CommandTaskFactory.HASCLUSTER);
props.setProperty(COMMAND_DESCRIPTION, "Test to see if this network has a cluster of the requested type");
registerService(bc, commandTaskFactory, TaskFactory.class, props);
}
{
TaskFactory commandTaskFactory = new CommandTaskFactory(clusterManager, "getnetworkcluster");
Properties props = new Properties();
props.setProperty(COMMAND_NAMESPACE, "cluster");
props.setProperty(COMMAND, CommandTaskFactory.GETNETWORKCLUSTER);
props.setProperty(COMMAND_DESCRIPTION, "Get a cluster network cluster result");
registerService(bc, commandTaskFactory, TaskFactory.class, props);
}
{
TaskFactory commandTaskFactory = new CommandTaskFactory(clusterManager, "getcluster");
Properties props = new Properties();
props.setProperty(COMMAND_NAMESPACE, "cluster");
props.setProperty(COMMAND, CommandTaskFactory.GETCLUSTER);
props.setProperty(COMMAND_DESCRIPTION, "Get an attribute cluster result");
registerService(bc, commandTaskFactory, TaskFactory.class, props);
}
}
use of edu.ucsf.rbvi.clusterMaker2.internal.api.ClusterManager 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.api.ClusterManager in project clusterMaker2 by RBVI.
the class KMedoidCluster method run.
public void run(TaskMonitor monitor) {
this.monitor = monitor;
monitor.setTitle("Performing " + getName());
List<String> nodeAttributeList = context.attributeList.getNodeAttributeList();
String edgeAttribute = context.attributeList.getEdgeAttribute();
if (nodeAttributeList == null && edgeAttribute == null) {
monitor.showMessage(TaskMonitor.Level.ERROR, "Must select either one edge column or two or more node columns");
return;
}
if (nodeAttributeList != null && nodeAttributeList.size() > 0 && edgeAttribute != null) {
monitor.showMessage(TaskMonitor.Level.ERROR, "Can't have both node and edge columns selected");
return;
}
if (context.selectedOnly && CyTableUtil.getNodesInState(network, CyNetwork.SELECTED, true).size() < 3) {
monitor.showMessage(TaskMonitor.Level.ERROR, "Must have at least three nodes to cluster");
return;
}
createGroups = context.createGroups;
if (nodeAttributeList != null && nodeAttributeList.size() > 0) {
// To make debugging easier, sort the attribute list
Collections.sort(nodeAttributeList);
}
// Get our attributes we're going to use for the cluster
String[] attributeArray;
if (nodeAttributeList != null && nodeAttributeList.size() > 0) {
attributeArray = new String[nodeAttributeList.size()];
int i = 0;
for (String attr : nodeAttributeList) {
attributeArray[i++] = "node." + attr;
}
} else {
attributeArray = new String[1];
attributeArray[0] = "edge." + edgeAttribute;
}
monitor.setStatusMessage("Initializing");
// System.out.println("Initializing");
resetAttributes(network, SHORTNAME);
// Create a new clusterer
RunKMedoidCluster algorithm = new RunKMedoidCluster(network, attributeArray, distanceMetric, monitor, context, this);
// System.out.println("Algorithm defined");
String resultsString = "K-Medoid results:";
// Cluster the attributes, if requested
if (context.clusterAttributes && attributeArray.length > 1) {
monitor.setStatusMessage("Clustering attributes");
// System.out.println("Clustering attributes");
Integer[] rowOrder = algorithm.cluster(clusterManager, context.kcluster.kNumber, context.iterations, true, SHORTNAME, context.kcluster, false);
attributeList = algorithm.getAttributeList();
updateAttributes(network, SHORTNAME, rowOrder, attributeArray, attributeList, algorithm.getMatrix());
attributeSilhouette = algorithm.getSilhouettes();
attributeOrder = getOrder(rowOrder, algorithm.getMatrix());
}
// Cluster the nodes
monitor.setStatusMessage("Clustering nodes");
// System.out.println("Clustering nodes");
Integer[] rowOrder = algorithm.cluster(clusterManager, context.kcluster.kNumber, context.iterations, false, SHORTNAME, context.kcluster, createGroups);
nodeList = algorithm.getAttributeList();
updateAttributes(network, SHORTNAME, rowOrder, attributeArray, algorithm.getAttributeList(), algorithm.getMatrix());
nodeSilhouette = algorithm.getSilhouettes();
nodeOrder = getOrder(rowOrder, algorithm.getMatrix());
// System.out.println(resultsString);
if (context.showUI) {
insertTasksAfterCurrentTask(new KnnView(clusterManager));
}
}
use of edu.ucsf.rbvi.clusterMaker2.internal.api.ClusterManager in project clusterMaker2 by RBVI.
the class HierarchicalCluster method run.
public void run(TaskMonitor monitor) {
this.monitor = monitor;
monitor.setTitle("Performing " + getName());
List<String> nodeAttributeList = context.attributeList.getNodeAttributeList();
String edgeAttribute = context.attributeList.getEdgeAttribute();
if (nodeAttributeList == null && edgeAttribute == null) {
monitor.showMessage(TaskMonitor.Level.ERROR, "Must select either one edge column or two or more node columns");
return;
}
if (nodeAttributeList != null && nodeAttributeList.size() > 0 && edgeAttribute != null) {
monitor.showMessage(TaskMonitor.Level.ERROR, "Can't have both node and edge columns selected");
return;
}
if (context.selectedOnly && nodeAttributeList != null && nodeAttributeList.size() > 1 && CyTableUtil.getNodesInState(network, CyNetwork.SELECTED, true).size() < 3) {
monitor.showMessage(TaskMonitor.Level.ERROR, "Must have at least three nodes to cluster");
return;
}
// Get our attributes we're going to use for the cluster
String[] attributeArray;
if (nodeAttributeList != null && nodeAttributeList.size() > 0) {
Collections.sort(nodeAttributeList);
attributeArray = new String[nodeAttributeList.size()];
int i = 0;
for (String attr : nodeAttributeList) {
attributeArray[i++] = "node." + attr;
}
} else {
attributeArray = new String[1];
attributeArray[0] = "edge." + edgeAttribute;
}
monitor.showMessage(TaskMonitor.Level.INFO, "Initializing");
// System.out.println("Initializing");
resetAttributes(network, SHORTNAME);
// Create a new clusterer
DistanceMetric metric = context.metric.getSelectedValue();
RunHierarchical algorithm = new RunHierarchical(network, attributeArray, metric, clusterMethod, monitor, context);
// Cluster the attributes, if requested
if (context.clusterAttributes && (attributeArray.length > 1 || context.isAssymetric())) {
monitor.setStatusMessage("Clustering attributes");
// System.out.println("Clustering attributes");
Integer[] rowOrder = algorithm.cluster(true);
attributeTree = algorithm.getAttributeList();
CyMatrix matrix = algorithm.getMatrix();
updateAttributes(network, SHORTNAME, rowOrder, attributeArray, attributeTree, matrix);
attributeOrder = new ArrayList<String>();
for (int i = 0; i < rowOrder.length; i++) {
attributeOrder.add(matrix.getRowLabel(rowOrder[i]));
}
}
monitor.setStatusMessage("Clustering nodes");
// Cluster the nodes
// System.out.println("Clustering nodes");
Integer[] rowOrder = algorithm.cluster(false);
nodeTree = algorithm.getAttributeList();
CyMatrix matrix = algorithm.getMatrix();
updateAttributes(network, SHORTNAME, rowOrder, attributeArray, nodeTree, matrix);
nodeOrder = new ArrayList<CyNode>();
for (int i = 0; i < rowOrder.length; i++) {
nodeOrder.add(matrix.getRowNode(rowOrder[i]));
}
// TODO: Deal with params!
List<String> params = context.getParams(algorithm.getMatrix());
updateParams(network, params);
if (context.showUI) {
insertTasksAfterCurrentTask(new TreeView(clusterManager));
}
monitor.setStatusMessage("Done");
}
use of edu.ucsf.rbvi.clusterMaker2.internal.api.ClusterManager in project clusterMaker2 by RBVI.
the class FFT method run.
public void run(TaskMonitor monitor) {
this.monitor = monitor;
monitor.setTitle("Performing " + getName());
List<String> nodeAttributeList = context.attributeList.getNodeAttributeList();
String edgeAttribute = context.attributeList.getEdgeAttribute();
if (nodeAttributeList == null && edgeAttribute == null) {
monitor.showMessage(TaskMonitor.Level.ERROR, "Must select either one edge column or two or more node columns");
return;
}
if (nodeAttributeList != null && nodeAttributeList.size() > 0 && edgeAttribute != null) {
monitor.showMessage(TaskMonitor.Level.ERROR, "Can't have both node and edge columns selected");
return;
}
if (context.selectedOnly && CyTableUtil.getNodesInState(network, CyNetwork.SELECTED, true).size() < 3) {
monitor.showMessage(TaskMonitor.Level.ERROR, "Must have at least three nodes to cluster");
return;
}
createGroups = context.createGroups;
if (nodeAttributeList != null && nodeAttributeList.size() > 0) {
// To make debugging easier, sort the attribute list
Collections.sort(nodeAttributeList);
}
// Get our attributes we're going to use for the cluster
String[] attributeArray;
if (nodeAttributeList != null && nodeAttributeList.size() > 0) {
attributeArray = new String[nodeAttributeList.size()];
int i = 0;
for (String attr : nodeAttributeList) {
attributeArray[i++] = "node." + attr;
}
} else {
attributeArray = new String[1];
attributeArray[0] = "edge." + edgeAttribute;
}
monitor.setStatusMessage("Initializing");
resetAttributes(network, SHORTNAME);
// Create a new clusterer
RunFFT algorithm = new RunFFT(network, attributeArray, distanceMetric, monitor, context, this);
// System.out.println("Algorithm defined");
String resultsString = "FFT results:";
// Cluster the attributes, if requested
if (context.clusterAttributes && attributeArray.length > 1) {
monitor.setStatusMessage("Clustering attributes");
Integer[] rowOrder = algorithm.cluster(clusterManager, context.kcluster.kNumber, 1, true, "fft", context.kcluster, false);
updateAttributes(network, SHORTNAME, rowOrder, attributeArray, algorithm.getAttributeList(), algorithm.getMatrix());
}
// Cluster the nodes
monitor.setStatusMessage("Clustering nodes");
Integer[] rowOrder = algorithm.cluster(clusterManager, context.kcluster.kNumber, 1, false, "fft", context.kcluster, createGroups);
updateAttributes(network, SHORTNAME, rowOrder, attributeArray, algorithm.getAttributeList(), algorithm.getMatrix());
// System.out.println(resultsString);
if (context.showUI) {
insertTasksAfterCurrentTask(new KnnView(clusterManager));
}
}
Aggregations