Author: scooter
Date: 2009-07-20 14:29:45 -0700 (Mon, 20 Jul 2009)
New Revision: 17491
Added:
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/ui/HistoChangeListener.java
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/ui/Histogram.java
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/ui/HistogramDialog.java
Modified:
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/algorithms/MCL/MCLCluster.java
Log:
Initial integration of Earl's histogram dialog
Modified:
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/algorithms/MCL/MCLCluster.java
===================================================================
---
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/algorithms/MCL/MCLCluster.java
2009-07-20 20:36:34 UTC (rev 17490)
+++
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/algorithms/MCL/MCLCluster.java
2009-07-20 21:29:45 UTC (rev 17491)
@@ -34,6 +34,8 @@
import java.awt.Dimension;
import java.awt.GridLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
@@ -53,10 +55,13 @@
import clusterMaker.algorithms.ClusterAlgorithm;
import clusterMaker.algorithms.AbstractClusterAlgorithm;
import clusterMaker.ui.ClusterViz;
+import clusterMaker.ui.HistogramDialog;
+import clusterMaker.ui.HistoChangeListener;
// clusterMaker imports
-public class MCLCluster extends AbstractClusterAlgorithm implements
TunableListener {
+public class MCLCluster extends AbstractClusterAlgorithm
+ implements TunableListener, ActionListener,
HistoChangeListener {
double inflation_parameter = 2.0;
int rNumber = 8;
@@ -175,13 +180,17 @@
clusterProperties.add(new Tunable("edgeCutoffGroup",
"Edge weight cutoff",
- Tunable.GROUP, new
Integer(1)));
+ Tunable.GROUP, new
Integer(2)));
clusterProperties.add(new Tunable("edgeCutOff",
"",
Tunable.DOUBLE, new
Double(0),
new Double(0), new Double(1),
Tunable.USESLIDER));
+ clusterProperties.add(new Tunable("edgeHistogram",
+ "Set Edge Cutoff Using
Histogram",
+ Tunable.BUTTON, "Edge
Histogram", this, null, Tunable.IMMUTABLE));
+
clusterProperties.add(new Tunable("options_panel2",
"Results options",
Tunable.GROUP, new
Integer(2)));
@@ -265,12 +274,56 @@
}
}
+ public void actionPerformed(ActionEvent e) {
+ // Get the currently selected attribute
+ CyAttributes edgeAttributes = Cytoscape.getEdgeAttributes();
+ byte type = edgeAttributes.getType(dataAttribute);
+ System.out.println("attribute: "+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();
+ }
+ index++;
+ }
+ 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.pack();
+ histo.setVisible(true);
+ histo.addHistoChangeListener(this);
+ }
+
+ public void histoValueChanged(double cutoffValue) {
+ Tunable edgeCutoff = clusterProperties.get("edgeCutOff");
+ edgeCutoff.setValue(cutoffValue);
+ }
+
public void tunableChanged(Tunable tunable) {
updateSettings(false);
Tunable edgeCutOffTunable = clusterProperties.get("edgeCutOff");
if (edgeCutOffTunable == null || dataAttribute == null)
return;
+ if (dataAttribute != null) {
+ Tunable t = clusterProperties.get("edgeHistogram");
+ t.clearFlag(Tunable.IMMUTABLE);
+ }
+
try {
double[] span = getSpan(dataAttribute);
Added:
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/ui/HistoChangeListener.java
===================================================================
---
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/ui/HistoChangeListener.java
(rev 0)
+++
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/ui/HistoChangeListener.java
2009-07-20 21:29:45 UTC (rev 17491)
@@ -0,0 +1,21 @@
+/*
+ * @(#)HistoChangeListener.java
+ *
+ *
+ * @author
+ * @version 1.00 2009/7/14
+ */
+package clusterMaker.ui;
+
+public interface HistoChangeListener {
+
+ /**
+ * This method will be called when the user sets a new
+ * bounds value in the histogram
+ *
+ * @param bounds the value the user set
+ */
+ void histoValueChanged(double bounds);
+
+
+}
Added:
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/ui/Histogram.java
===================================================================
---
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/ui/Histogram.java
(rev 0)
+++
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/ui/Histogram.java
2009-07-20 21:29:45 UTC (rev 17491)
@@ -0,0 +1,256 @@
+/**
+ * @(#)Histogram.java
+ *
+ * Java class that implements a Histogram
+ *
+ * @author
+ * @version 1.00 2009/6/30
+ */
+
+package clusterMaker.ui;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.event.*;
+
+import java.lang.Math;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import java.text.DecimalFormat;
+
+import javax.swing.JComponent;
+
+class Histogram extends JComponent implements MouseMotionListener,
MouseListener{
+ private int[] histoArray;
+ private int histoMax = Integer.MIN_VALUE;
+ private double[] graphData;
+ private double minValue = Double.MAX_VALUE;
+ private double maxValue = Double.MIN_VALUE;
+ private int low;
+ private int high;
+ private final int XSTART = 100;
+ private final int YEND = 50;
+ private final int NBINS = 100;
+ private int mouseX;
+ private boolean boolShowLine = false;
+ private double binSize;
+ private List<HistoChangeListener> listeners = null;
+
+
+ DecimalFormat form = new DecimalFormat("0.0##E0"); //rounds values for
drawString
+
+ Histogram(double[] inputData, int nBins) {
+ super();
+ setPreferredSize(new Dimension(800,500));
+ histoArray = new int[NBINS];
+ this.graphData = inputData;
+ for (int i=0; i < graphData.length; i++) {
+ minValue = Math.min(minValue, graphData[i]);
+ maxValue = Math.max(maxValue, graphData[i]);
+ }
+ listeners = new ArrayList();
+ createHistogram(graphData);
+ addMouseMotionListener(this);
+ addMouseListener(this);
+ }
+
+ public void updateData(double[] graphData) {
+ // Trigger redraw
+ }
+
+ public void paint(Graphics g) {
+ super.paint(g);
+ drawGraph(g);
+ if(boolShowLine)
+ mouseLine(mouseX, g);
+ }
+
+ public void mouseMoved(MouseEvent e) {}
+ public void mouseDragged(MouseEvent e) {
+ Dimension dim = getPreferredSize();
+ int width = dim.width;
+ int xIncrement = (width-125)/NBINS;
+ int histoMousePos = (e.getX()-XSTART)/xIncrement;
+
+ if(e.getX()>XSTART && boolShowLine){
+ mouseX = e.getX();
+ repaint();
+ }
+ }
+ public void mouseClicked(MouseEvent e){}
+ public void mouseEntered(MouseEvent e){}
+ public void mouseExited(MouseEvent e){}
+ public void mousePressed(MouseEvent e){
+ Dimension dim = getPreferredSize();
+ int width = dim.width;
+ int xIncrement = (width-125)/NBINS;
+ int histoMousePos = (e.getX()-XSTART)/xIncrement;
+
+ if(e.getX()>XSTART && boolShowLine){
+ mouseX = e.getX();
+ repaint();
+ }
+ }
+
+ public void mouseReleased(MouseEvent e){
+ Dimension dim = getPreferredSize();
+ int width = dim.width;
+ int xIncrement = (width-125)/NBINS;
+ int histoMousePos = (e.getX()-XSTART)/xIncrement;
+ if(e.getX()>XSTART &&
e.getX()<(XSTART+xIncrement*histoArray.length) && boolShowLine){
+ double binValue = minValue+(binSize*histoMousePos);
+ // System.out.println("histoArray["+histoMousePos+"] =
"+ histoArray[histoMousePos]+", "+form.format((binValue)));
+ if (listeners.size() == 0) return;
+ for (HistoChangeListener listener: listeners)
+ listener.histoValueChanged(binValue);
+ }
+
+ }
+
+ //handle the rest of the wizard buttons in a similar fashion
+
+
+
+ public void setBoolShowLine(boolean inShowLine){boolShowLine =
inShowLine;}
+
+ /**
+ * Add a new change listener to this histogram
+ *
+ * @param listener the HistoChangeListener to call when the cutoff
value changes
+ */
+ public void addHistoChangeListener(HistoChangeListener listener) {
+ if (listeners.contains(listener)) return;
+ listeners.add(listener);
+ }
+
+ /**
+ * Remove a change listener from this histogram
+ *
+ * @param listener the HistoChangeListener to remove
+ */
+ public void removeHistoChangeListener(HistoChangeListener listener) {
+ listeners.remove(listener);
+ }
+
+ private void mouseLine(int mX, Graphics g){
+ Dimension dim = getPreferredSize();
+ int height = dim.height-100;
+ int width = dim.width;
+ int xIncrement = (width-125)/NBINS;
+ int histoMousePos = (mX-XSTART)/xIncrement;
+ if(histoMousePos >= histoArray.length)
+ histoMousePos = histoArray.length-1;
+
+ g.setColor(Color.red);
+ g.drawLine(mX, YEND, mX, height);
+ g.setColor(Color.black);
+ g.drawString(form.format((minValue+(binSize*histoMousePos)))+"
("+histoArray[histoMousePos]+" values)",mX-50,YEND-5); //REMOVE THIS LATER
+ }
+
+ private void createHistogram(double[] inputData){
+ histoMax = Integer.MIN_VALUE;
+ binSize = (maxValue - minValue)/NBINS;
+ // System.out.println("binSize = "+binSize);
+ for(double dataItr : inputData){
+ for(int nI=0; nI < NBINS; nI++){
+ if(dataItr==minValue){
+ histoArray[0]+=1;
+ break;
+ }
+ if(dataItr>minValue+binSize*nI &&
dataItr<=minValue+binSize*(nI+1) ){
+ histoArray[nI]+=1;
+ break;
+ }
+ }
+ }
+ int test = 0; //REMOVE THIS LATER
+ for(int nI=0; nI<histoArray.length; nI++){
+ histoMax = Math.max(histoMax, histoArray[nI]);
+ // System.out.println("hitoArray["+nI+"] =
"+histoArray[nI]); //REMOVE THIS LATER
+ test+=histoArray[nI]; //REMOVE THIS LATER
+ }
+ // System.out.println("test = "+test); //REMOVE THIS LATER
+ // System.out.println("histoMax = "+histoMax); //REMOVE THIS
LATER
+ }
+
+ private void drawGraph(Graphics g){
+ Dimension dim = getPreferredSize();
+ int height = dim.height-100;
+ int width = dim.width;
+
+ drawAxes(g, height, width);
+ drawLabels(g, height, width);
+ drawData(g, height, width);
+ }
+
+ private void drawAxes(Graphics g, int height, int width) {
+ g.setColor(Color.black);
+ g.drawLine(XSTART,YEND,XSTART,height);
+ g.setColor(Color.green);
+ g.drawLine(XSTART,height,width,height);
+
+
+ double yIncrement = (height-50)/(double)histoMax;
+ for(int nI=1;nI<=histoMax;nI++){
+ if(nI%10==0)
+ g.setColor(Color.red);
+ else
+ g.setColor(Color.gray);
+
g.drawLine(XSTART-10,height-(int)(yIncrement*nI),width,height-(int)(yIncrement*nI));
+ }
+
+ int xIncrement = (width-125)/NBINS;
+ for(int nI=0; nI<=histoArray.length; nI++){
+ if(nI%10==0){
+ g.setColor(Color.black);
+
g.drawLine(XSTART+xIncrement*nI,height,100+xIncrement*nI,height+10);
+ }
+
+ }
+ }
+
+ private void drawLabels(Graphics g, int height, int width) {
+ g.setColor(Color.gray);
+ double yIncrement = (height-50)/(double)histoMax;
+ for(int nI=1;nI<=histoMax;nI++){
+ if(nI%10==0)
+
g.drawString(""+nI,70,height-(int)(yIncrement*nI)+5);
+ }
+
+ int xIncrement = (width-125)/NBINS;
+ double binSize = (maxValue - minValue)/NBINS;
+
+ g.drawString(""+form.format(minValue),XSTART-25,height+20);
+
g.drawString(""+form.format(maxValue),XSTART-25+xIncrement*histoArray.length,height+20);
+ for(int nI=1; nI<histoArray.length; nI++){
+ if(nI%10==0)
+
g.drawString(""+form.format((minValue+(binSize*nI))),XSTART-25+xIncrement*nI,height+20);
+ }
+ }
+
+
+ // TODO: Change this method to use height and width. You may need to
scale the
+ // the font also.
+ private void drawData(Graphics g, int height, int width){
+ int nBlueChange = 100;
+ double yIncrement = (height-50)/(double)histoMax;
+ //System.out.println("yIncrement = "+yIncrement);
+ int xIncrement = (width-125)/NBINS;
+
+ for(int nI=0; nI<histoArray.length; nI++){
+ g.setColor(new Color(0,0,nBlueChange));
+ g.fillRect(XSTART+xIncrement*nI,
height-(int)(histoArray[nI]*yIncrement), xIncrement,
(int)(histoArray[nI]*yIncrement));
+ g.setColor(Color.black);
+ g.drawRect(XSTART+xIncrement*nI,
height-(int)(histoArray[nI]*yIncrement), xIncrement,
(int)(histoArray[nI]*yIncrement));
+
+ nBlueChange+=15;
+ if(nBlueChange >= 250)
+ nBlueChange = 100;
+ }
+
+ }
+
+}
Added:
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/ui/HistogramDialog.java
===================================================================
---
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/ui/HistogramDialog.java
(rev 0)
+++
csplugins/trunk/ucsf/scooter/clusterMaker/src/clusterMaker/ui/HistogramDialog.java
2009-07-20 21:29:45 UTC (rev 17491)
@@ -0,0 +1,107 @@
+/**
+ * @(#)HistogramDialog.java
+ *
+ * A JDialog component that displays a histogram. This
+ *
+ * @author
+ * @version
+ */
+package clusterMaker.ui;
+
+import java.awt.Dimension;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ComponentEvent;
+import java.awt.event.ComponentListener;
+
+import javax.swing.BorderFactory;
+import javax.swing.BoxLayout;
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JPanel;
+
+import javax.swing.border.Border;
+import javax.swing.border.EtchedBorder;
+
+
+public class HistogramDialog extends JDialog implements ActionListener,
ComponentListener{
+ double[] inputArray;
+ int nBins;
+ Histogram histo;
+
+ public HistogramDialog(String title, double[] inputArray, int nBins) {
+ super();
+ this.inputArray = inputArray;
+ this.nBins = nBins;
+ setTitle(title);
+
+ initializeOnce();
+ }
+
+ //public double getCutoff() {}
+
+ public void actionPerformed(ActionEvent e) {
+ if(e.getActionCommand().equals("set"))
+ histo.setBoolShowLine(true);
+ if(e.getActionCommand().equals("close"))
+ this.dispose();
+ }
+
+ public void componentHidden(ComponentEvent e) {}
+ public void componentShown(ComponentEvent e) {}
+ public void componentMoved(ComponentEvent e) {}
+
+ public void componentResized(ComponentEvent e) {
+ // Get our new size & update histogram
+ Dimension dim = e.getComponent().getSize();
+ histo.setPreferredSize(new Dimension(dim.width, dim.height));
+ }
+
+ private void initializeOnce() {
+
+ JPanel mainPanel = new JPanel();
+ mainPanel.setLayout(new BoxLayout(mainPanel,
BoxLayout.PAGE_AXIS));
+ mainPanel.addComponentListener(this);
+
+
+ // Create and add the histogram component
+ histo = new Histogram(inputArray, nBins);
+ mainPanel.add(histo);
+
+ // TODO: Add box to set lower and upper bounds. Look at JText
and JLabel
+
+ // Create our button box
+ JPanel buttonBox = new JPanel();
+
+ // Close button
+ JButton closeButton = new JButton("close");
+ closeButton.addActionListener(this);
+ closeButton.setActionCommand("close");
+
+ // OK button
+ JButton okButton = new JButton("Set Cutoff");
+ okButton.addActionListener(this);
+ okButton.setActionCommand("set");
+
+ buttonBox.add(okButton);
+ buttonBox.add(closeButton);
+
buttonBox.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
+ Dimension buttonDim = buttonBox.getPreferredSize();
+ buttonBox.setMinimumSize(buttonDim);
+ buttonBox.setMaximumSize(new Dimension(Integer.MAX_VALUE,
buttonDim.height));
+ mainPanel.add(buttonBox);
+
+ setContentPane(mainPanel);
+ setDefaultCloseOperation(DISPOSE_ON_CLOSE);
+
+ }
+
+ public void addHistoChangeListener(HistoChangeListener h){
+ histo.addHistoChangeListener(h);
+ }
+
+ public void removeHistoChangeListener(HistoChangeListener h){
+ histo.removeHistoChangeListener(h);
+ }
+
+}
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---