Author: scooter
Date: 2009-08-12 21:16:54 -0700 (Wed, 12 Aug 2009)
New Revision: 17804
Modified:
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/algorithms/MCL/MCLCluster.java
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/ui/Histogram.java
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/ui/HistogramDialog.java
Log:
Complete Histogram integration
Modified:
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/algorithms/MCL/MCLCluster.java
===================================================================
---
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/algorithms/MCL/MCLCluster.java
2009-08-13 04:10:16 UTC (rev 17803)
+++
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/algorithms/MCL/MCLCluster.java
2009-08-13 04:16:54 UTC (rev 17804)
@@ -75,6 +75,7 @@
boolean undirectedEdges = true;
double maxResidual = 0.001;
Double edgeCutOff = null;
+ HistogramDialog histo = null;
String[] attributeArray = new String[1];
@@ -200,6 +201,9 @@
clusterProperties.add(new Tunable("createMetaNodes","Create
meta nodes for clusters",
Tunable.BOOLEAN, new
Boolean(false)));
+ // TODO: Add a results panel that sets the number of clusters,
average # of nodes/cluster,
+ // average # of inter-cluster edges, average # of
intra-cluster edges
+
clusterProperties.initializeProperties();
updateSettings(true);
}
@@ -268,39 +272,16 @@
}
public void actionPerformed(ActionEvent e) {
- // Get the currently selected attribute
- CyAttributes edgeAttributes = Cytoscape.getEdgeAttributes();
- byte type = edgeAttributes.getType(dataAttribute);
- List attrList = new ArrayList();
- for (CyEdge edge:
(List<CyEdge>)Cytoscape.getCurrentNetwork().edgesList()) {
- if (edgeAttributes.hasAttribute(edge.getIdentifier(),
dataAttribute)) {
-
attrList.add(edgeAttributes.getAttribute(edge.getIdentifier(), dataAttribute));
- }
- }
- double dataArray[] = new double[attrList.size()];
- int index = 0;
- for (Object obj: attrList) {
- if (type == CyAttributes.TYPE_FLOATING) {
- dataArray[index] = ((Double)obj).doubleValue();
- } else {
- dataArray[index] = ((Integer)obj).doubleValue();
- }
- if (takeNegLOG) {
- if (dataArray[index] == 0)
- dataArray[index] = 500; // Arbitrarily
small value (1X10^-500)
- else
- dataArray[index] =
-Math.log10(dataArray[index]);
- }
- index++;
- }
+ double dataArray[] = getData(dataAttribute);
+
int nbins = 100;
if (dataArray.length < 100)
nbins = 10;
else if (dataArray.length > 10000)
nbins = 1000;
String title = "Histogram for "+dataAttribute+" edge attribute";
- HistogramDialog histo = new HistogramDialog(title, dataArray,
nbins);
+ histo = new HistogramDialog(title, dataArray, nbins);
histo.pack();
histo.setVisible(true);
histo.addHistoChangeListener(this);
@@ -339,8 +320,60 @@
t.addTunableValueListener(this);
}
}
+
+ if (histo != null) {
+ double dataArray[] = getData(dataAttribute);
+ histo.updateData(dataArray);
+ histo.pack();
+ }
}
+ public void doCluster(TaskMonitor monitor) {
+ this.monitor = monitor;
+ // Sanity check all of our settings
+ if (debug)
+ logger.debug("Performing MCL clustering with
attributes: "+dataAttribute);
+
+ String clusterAttrName =
Cytoscape.getCurrentNetwork().getIdentifier()+"_cluster";
+ //Cluster the nodes
+ runMCL = new RunMCL(clusterAttrName, dataAttribute,
inflation_parameter,
+ rNumber, clusteringThresh,
maxResidual, logger);
+
+ if (selectedOnly)
+ runMCL.selectedOnly();
+
+ if (createMetaNodes)
+ runMCL.createMetaNodes();
+
+ if (!undirectedEdges)
+ runMCL.setDirectedEdges();
+
+ if (adjustLoops)
+ runMCL.setAdjustLoops();
+
+ if (edgeCutOff != null)
+ runMCL.setEdgeCutOff(edgeCutOff);
+
+ if (takeNegLOG)
+ runMCL.setTakeNegLog(true);
+
+ runMCL.run(monitor);
+
+ // Set up the appropriate attributes
+ CyAttributes netAttr = Cytoscape.getNetworkAttributes();
+
netAttr.setAttribute(Cytoscape.getCurrentNetwork().getIdentifier(),
+ ClusterMaker.CLUSTER_TYPE_ATTRIBUTE,
"mcl");
+
netAttr.setAttribute(Cytoscape.getCurrentNetwork().getIdentifier(),
+ ClusterMaker.CLUSTER_ATTRIBUTE,
clusterAttrName);
+
+ // Tell any listeners that we're done
+ pcs.firePropertyChange(ClusterAlgorithm.CLUSTER_COMPUTED, null,
this);
+ }
+
+ public void halt() {
+ runMCL.halt();
+ }
+
private void getAttributesList(List<String>attributeList, CyAttributes
attributes) {
String[] names = attributes.getAttributeNames();
for (int i = 0; i < names.length; i++) {
@@ -362,6 +395,36 @@
return attrArray;
}
+ private double[] getData(String attribute) {
+ // Get the currently selected attribute
+ CyAttributes edgeAttributes = Cytoscape.getEdgeAttributes();
+ byte type = edgeAttributes.getType(attribute);
+ List attrList = new ArrayList();
+ for (CyEdge edge:
(List<CyEdge>)Cytoscape.getCurrentNetwork().edgesList()) {
+ if (edgeAttributes.hasAttribute(edge.getIdentifier(),
attribute)) {
+
attrList.add(edgeAttributes.getAttribute(edge.getIdentifier(), attribute));
+ }
+ }
+
+ double dataArray[] = new double[attrList.size()];
+ int index = 0;
+ for (Object obj: attrList) {
+ if (type == CyAttributes.TYPE_FLOATING) {
+ dataArray[index] = ((Double)obj).doubleValue();
+ } else {
+ dataArray[index] = ((Integer)obj).doubleValue();
+ }
+ if (takeNegLOG) {
+ if (dataArray[index] == 0)
+ dataArray[index] = 500; // Arbitrarily
small value (1X10^-500)
+ else
+ dataArray[index] =
-Math.log10(dataArray[index]);
+ }
+ index++;
+ }
+ return dataArray;
+ }
+
private double[] getSpan(String attr) throws ArithmeticException {
CyNetwork net = Cytoscape.getCurrentNetwork();
CyAttributes edgeAttrs = Cytoscape.getEdgeAttributes();
@@ -402,49 +465,4 @@
return d;
}
- public void doCluster(TaskMonitor monitor) {
- this.monitor = monitor;
- // Sanity check all of our settings
- if (debug)
- logger.debug("Performing MCL clustering with
attributes: "+dataAttribute);
-
- String clusterAttrName =
Cytoscape.getCurrentNetwork().getIdentifier()+"_cluster";
- //Cluster the nodes
- runMCL = new RunMCL(clusterAttrName, dataAttribute,
inflation_parameter,
- rNumber, clusteringThresh,
maxResidual, logger);
-
- if (selectedOnly)
- runMCL.selectedOnly();
-
- if (createMetaNodes)
- runMCL.createMetaNodes();
-
- if (!undirectedEdges)
- runMCL.setDirectedEdges();
-
- if (adjustLoops)
- runMCL.setAdjustLoops();
-
- if (edgeCutOff != null)
- runMCL.setEdgeCutOff(edgeCutOff);
-
- if (takeNegLOG)
- runMCL.setTakeNegLog(true);
-
- runMCL.run(monitor);
-
- // Set up the appropriate attributes
- CyAttributes netAttr = Cytoscape.getNetworkAttributes();
-
netAttr.setAttribute(Cytoscape.getCurrentNetwork().getIdentifier(),
- ClusterMaker.CLUSTER_TYPE_ATTRIBUTE,
"mcl");
-
netAttr.setAttribute(Cytoscape.getCurrentNetwork().getIdentifier(),
- ClusterMaker.CLUSTER_ATTRIBUTE,
clusterAttrName);
-
- // Tell any listeners that we're done
- pcs.firePropertyChange(ClusterAlgorithm.CLUSTER_COMPUTED, null,
this);
- }
-
- public void halt() {
- runMCL.halt();
- }
}
Modified:
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/ui/Histogram.java
===================================================================
---
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/ui/Histogram.java
2009-08-13 04:10:16 UTC (rev 17803)
+++
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/ui/Histogram.java
2009-08-13 04:16:54 UTC (rev 17804)
@@ -42,7 +42,7 @@
// Y scale values
private int histoMax = Integer.MIN_VALUE;
private int histoMin = 0;
- private int histoMaxUp;
+ private int histoMaxUp = 0;
// X scale values
private double minValue = Double.MAX_VALUE;
@@ -94,7 +94,12 @@
histoArray = new int[NBINS];
this.graphData = graphData;
+ minValue = Double.MAX_VALUE;
+ maxValue = Double.MIN_VALUE;
+ histoMax = Integer.MIN_VALUE;
+ histoMaxUp = 0;
createHistogram(graphData);
+ this.repaint();
}
public void paintComponent(Graphics g) {
Modified:
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/ui/HistogramDialog.java
===================================================================
---
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/ui/HistogramDialog.java
2009-08-13 04:10:16 UTC (rev 17803)
+++
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/ui/HistogramDialog.java
2009-08-13 04:16:54 UTC (rev 17804)
@@ -16,6 +16,8 @@
import java.awt.event.ComponentListener;
import java.awt.ScrollPane;
+import java.util.ArrayList;
+import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
@@ -38,17 +40,26 @@
ScrollPane scrollPanel;
JButton zoomOutButton;
boolean isZoomed = false;
+ List<HistoChangeListener> changeListenerList = null;
public HistogramDialog(String title, double[] inputArray, int nBins) {
super();
this.inputArray = inputArray;
this.nBins = nBins;
this.currentBins = nBins;
+ this.changeListenerList = new ArrayList();
setTitle(title);
initializeOnce();
}
+ public void updateData(double[] inputArray) {
+ this.inputArray = inputArray;
+ if (histo != null) {
+ histo.updateData(inputArray);
+ }
+ }
+
//public double getCutoff() {}
public void actionPerformed(ActionEvent e) {
@@ -143,13 +154,20 @@
}
public void addHistoChangeListener(HistoChangeListener h){
- histo.addHistoChangeListener(h);
+ if (changeListenerList.contains(h)) return;
+ changeListenerList.add(h);
}
public void removeHistoChangeListener(HistoChangeListener h){
- histo.removeHistoChangeListener(h);
+ changeListenerList.remove(h);
}
+ public void histoValueChanged(double bounds){
+ if (changeListenerList.size() == 0) return;
+ for (HistoChangeListener listener: changeListenerList)
+ listener.histoValueChanged(bounds);
+ }
+
private void zoom(double[] inputArray, boolean zoomOut){
mainPanel.removeAll();
@@ -185,10 +203,6 @@
// Trigger a relayout
pack();
}
-
- public void histoValueChanged(double bounds){
- System.out.println("histoValueChanged to "+bounds);
- }
/**
* Main method for testing purposes.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en
-~----------~----~----~----~------~----~------~--~---