use of uk.ac.babraham.SeqMonk.Utilities.AxisScale in project SeqMonk by s-andrews.
the class ZScoreScatterPlotPanel method paint.
/* (non-Javadoc)
* @see javax.swing.JComponent#paint(java.awt.Graphics)
*/
public void paint(Graphics g) {
super.paint(g);
g.setColor(Color.WHITE);
g.fillRect(0, 0, getWidth(), getHeight());
FontMetrics metrics = getFontMetrics(g.getFont());
if (!readyToDraw) {
g.setColor(Color.GRAY);
String message = "Calculating Plot";
g.drawString(message, (getWidth() / 2) - (metrics.stringWidth(message) / 2), (getHeight() / 2 - 2));
return;
}
// Check to see if we need to work out the counts for this size
if (nonRedundantValues == null || lastNonredWidth != getWidth() || lastNonredHeight != getHeight()) {
calculateNonredundantSet();
}
// If we're here then we can actually draw the graphs
g.setColor(Color.BLACK);
// X axis
g.drawLine(X_AXIS_SPACE, getHeight() - Y_AXIS_SPACE, getWidth() - 10, getHeight() - Y_AXIS_SPACE);
AxisScale xAxisScale = new AxisScale(minValueX, maxValueX);
double currentXValue = xAxisScale.getStartingValue();
while (currentXValue < maxValueX) {
g.drawString(xAxisScale.format(currentXValue), getX(currentXValue), getHeight() - (Y_AXIS_SPACE - (3 + g.getFontMetrics().getHeight())));
g.drawLine(getX(currentXValue), getHeight() - Y_AXIS_SPACE, getX(currentXValue), getHeight() - (Y_AXIS_SPACE - 3));
currentXValue += xAxisScale.getInterval();
}
// Y axis
g.drawLine(X_AXIS_SPACE, 10, X_AXIS_SPACE, getHeight() - Y_AXIS_SPACE);
//
AxisScale yAxisScale = new AxisScale(minValueY, maxValueY);
double currentYValue = yAxisScale.getStartingValue();
while (currentYValue < maxValueY) {
g.drawString(yAxisScale.format(currentYValue), 5, getY(currentYValue) + (g.getFontMetrics().getAscent() / 2));
g.drawLine(X_AXIS_SPACE, getY(currentYValue), X_AXIS_SPACE - 3, getY(currentYValue));
currentYValue += yAxisScale.getInterval();
}
// X label
g.drawString("mean probe intensity", (getWidth() / 2) - (metrics.stringWidth("mean probe intensity") / 2), getHeight() - 3);
// Y label
g.drawString("z-score", X_AXIS_SPACE - metrics.stringWidth("z-score") - 3, 15);
g.setColor(Color.BLUE);
for (int p = 0; p < nonRedundantValues.length; p++) {
if ((madeSelection || makingSelection) && nonRedundantValues[p].yValue >= Math.min(diffStart, diffEnd) && nonRedundantValues[p].yValue <= Math.max(diffStart, diffEnd)) {
g.setColor(Color.BLACK);
} else {
g.setColor(nonRedundantValues[p].color);
}
g.fillRect(nonRedundantValues[p].x - (dotSize / 2), nonRedundantValues[p].y - (dotSize / 2), dotSize, dotSize);
}
// If we have a highlighted list, add the name
if (subLists != null) {
for (int s = 0; s < subLists.length; s++) {
g.setColor(ColourIndexSet.getColour(s));
g.drawString(subLists[s].name(), getWidth() - metrics.stringWidth(subLists[s].name()) - 5, 30 + (g.getFontMetrics().getHeight() * (s + 1)));
}
g.setColor(Color.BLACK);
}
// 0 line
g.setColor(Color.GRAY);
g.drawLine(X_AXIS_SPACE, getY(0), getWidth() - 10, getY(0));
// label the datasets
// the negative z-scores
g.drawString(xStore.name(), X_AXIS_SPACE + 10, getHeight() - 50);
// one with the positive z-scores
g.drawString(yStore.name(), X_AXIS_SPACE + 10, 30);
// Finally we draw the current measures if the mouse is inside the plot
if (cursorX > 0) {
g.setColor(Color.BLACK);
// System.out.println("Drawing label at x="+cursorX+" y="+cursorY+" x*="+getValueFromX(cursorX)+" y*="+getValueFromY(cursorY));
String label = "x=" + df.format(getValueFromX(cursorX)) + " y=" + df.format(getValueFromY(cursorY));
int labelXPos = X_AXIS_SPACE + ((getWidth() - (X_AXIS_SPACE + 10)) / 2) - (g.getFontMetrics().stringWidth(label) / 2);
g.drawString(label, labelXPos, getHeight() - (Y_AXIS_SPACE + 3));
// We also draw the names on the closest point if there is one
if (closestPoint != null && closestPoint.probe() != null) {
g.drawString(closestPoint.probe().name(), closestPoint.x + 1, closestPoint.y - 1);
}
}
}
use of uk.ac.babraham.SeqMonk.Utilities.AxisScale in project SeqMonk by s-andrews.
the class CisTransScatterPlotPanel method paint.
/* (non-Javadoc)
* @see javax.swing.JComponent#paint(java.awt.Graphics)
*/
public void paint(Graphics g) {
super.paint(g);
g.setColor(Color.WHITE);
g.fillRect(0, 0, getWidth(), getHeight());
FontMetrics metrics = getFontMetrics(g.getFont());
if (!readyToDraw) {
g.setColor(Color.GRAY);
String message = "Calculating Plot";
g.drawString(message, (getWidth() / 2) - (metrics.stringWidth(message) / 2), (getHeight() / 2 - 2));
return;
}
// Check to see if we need to work out the counts for this size
if (nonRedundantValues == null || lastNonredWidth != getWidth() || lastNonredHeight != getHeight()) {
calculateNonredundantSet();
}
// If we're here then we can actually draw the graphs
g.setColor(Color.BLACK);
// X axis
g.drawLine(X_AXIS_SPACE, getHeight() - Y_AXIS_SPACE, getWidth() - 10, getHeight() - Y_AXIS_SPACE);
AxisScale xAxisScale = new AxisScale(minValueX, maxValueX);
double currentXValue = xAxisScale.getStartingValue();
while (currentXValue < maxValueX) {
g.drawString(xAxisScale.format(currentXValue), getX(currentXValue), getHeight() - (Y_AXIS_SPACE - (3 + g.getFontMetrics().getHeight())));
g.drawLine(getX(currentXValue), getHeight() - Y_AXIS_SPACE, getX(currentXValue), getHeight() - (Y_AXIS_SPACE - 3));
currentXValue += xAxisScale.getInterval();
}
// Y axis
g.drawLine(X_AXIS_SPACE, 10, X_AXIS_SPACE, getHeight() - Y_AXIS_SPACE);
AxisScale yAxisScale = new AxisScale(minValueY, maxValueY);
double currentYValue = yAxisScale.getStartingValue();
while (currentYValue < maxValueY) {
g.drawString(yAxisScale.format(currentYValue), 5, getY(currentYValue) + (g.getFontMetrics().getAscent() / 2));
g.drawLine(X_AXIS_SPACE, getY(currentYValue), X_AXIS_SPACE - 3, getY(currentYValue));
currentYValue += yAxisScale.getInterval();
}
// X label
g.drawString("Cis", (getWidth() / 2) - (metrics.stringWidth("Cis") / 2), getHeight() - 3);
// Y label
g.drawString("Trans", X_AXIS_SPACE + 3, 15);
// ProbeList
g.drawString(probeList.name(), getWidth() - 10 - metrics.stringWidth(probeList.name()), 15);
// 45 degree line
g.setColor(Color.GRAY);
g.drawLine(X_AXIS_SPACE, getHeight() - Y_AXIS_SPACE, getWidth() - 10, 10);
g.setColor(Color.BLUE);
ColourGradient gradient = new HotColdColourGradient();
for (int p = 0; p < nonRedundantValues.length; p++) {
if ((madeSelection || makingSelection) && nonRedundantValues[p].difference() >= Math.min(diffStart, diffEnd) && nonRedundantValues[p].difference() <= Math.max(diffStart, diffEnd)) {
g.setColor(Color.BLACK);
} else {
if (nonRedundantValues[p].color == null) {
nonRedundantValues[p].color = gradient.getColor(Math.log(nonRedundantValues[p].count), 0, Math.log(maxPointCount));
}
g.setColor(nonRedundantValues[p].color);
}
g.fillRect(nonRedundantValues[p].x - (dotSize / 2), nonRedundantValues[p].y - (dotSize / 2), dotSize, dotSize);
}
// Finally we draw the current measures if the mouse is inside the plot
if (cursorX > 0) {
g.setColor(Color.BLACK);
// System.out.println("Drawing label at x="+cursorX+" y="+cursorY+" x*="+getValueFromX(cursorX)+" y*="+getValueFromY(cursorY));
String label = "x=" + df.format(getValueFromX(cursorX)) + " y=" + df.format(getValueFromY(cursorY)) + " diff=" + df.format(getValueFromX(cursorX) - getValueFromY(cursorY));
int labelXPos = X_AXIS_SPACE + ((getWidth() - (X_AXIS_SPACE + 10)) / 2) - (g.getFontMetrics().stringWidth(label) / 2);
g.drawString(label, labelXPos, getHeight() - (Y_AXIS_SPACE + 3));
// We also draw the names on the closest point if there is one
if (closestPoint != null && closestPoint.probe() != null) {
g.drawString(closestPoint.probe().name(), closestPoint.x + 1, closestPoint.y - 1);
}
}
}
use of uk.ac.babraham.SeqMonk.Utilities.AxisScale in project SeqMonk by s-andrews.
the class CodonBiasPanel method paint.
public void paint(Graphics g) {
super.paint(g);
g.setColor(Color.WHITE);
g.fillRect(0, 0, getWidth(), getHeight());
if (!calculated)
return;
g.setColor(Color.BLACK);
// Draw the axes
// X-axis
g.drawLine(X_AXIS_SPACE, getHeight() - Y_AXIS_SPACE, getWidth() - X_AXIS_SPACE, getHeight() - Y_AXIS_SPACE);
// Y-axis 1
g.drawLine(X_AXIS_SPACE, getHeight() - Y_AXIS_SPACE, X_AXIS_SPACE, 10);
// Y-axis 2
g.drawLine(getWidth() - X_AXIS_SPACE, getHeight() - Y_AXIS_SPACE, getWidth() - X_AXIS_SPACE, 10);
// Draw the Y1 scale
AxisScale yAxisScale = new AxisScale(0, 100);
double currentYValue = yAxisScale.getStartingValue();
while (currentYValue < yAxisScale.getMax()) {
g.drawString(yAxisScale.format(currentYValue), 5, getYPixels(currentYValue) + (g.getFontMetrics().getAscent() / 2));
g.drawLine(X_AXIS_SPACE, getYPixels(currentYValue), X_AXIS_SPACE - 3, getYPixels(currentYValue));
currentYValue += yAxisScale.getInterval();
}
// Draw the Y2 scale (abundance)
yAxisScale = new AxisScale(0, 100);
currentYValue = yAxisScale.getStartingValue();
while (currentYValue < yAxisScale.getMax()) {
g.drawString(yAxisScale.format(currentYValue), getWidth() - (X_AXIS_SPACE - 5), getYPixels(currentYValue) + (g.getFontMetrics().getAscent() / 2));
g.drawLine(getWidth() - X_AXIS_SPACE, getYPixels(currentYValue), getWidth() - (X_AXIS_SPACE - 3), getYPixels(currentYValue));
currentYValue += yAxisScale.getInterval();
}
// Draw x axis
AxisScale xAxisScale = new AxisScale(1, abundance.length);
double currentXValue = xAxisScale.getStartingValue();
while (currentXValue < xAxisScale.getMax()) {
g.drawString(xAxisScale.format(currentXValue), getXPixels(currentXValue), getHeight() - (g.getFontMetrics().getAscent() / 2));
g.drawLine(X_AXIS_SPACE, getYPixels(currentYValue), X_AXIS_SPACE - 3, getYPixels(currentYValue));
currentXValue += xAxisScale.getInterval();
}
// Highlight the exons
int lastExonEndX = getXPixels(0);
for (int i = 1; i < exonBoundaries.length; i++) {
int thisExonX = getXPixels(exonBoundaries[i]);
if (i % 2 != 0) {
g.setColor(GREY);
g.fillRect(lastExonEndX, getYPixels(100), thisExonX - lastExonEndX, getYPixels(0) - getYPixels(100));
}
lastExonEndX = thisExonX;
}
if (exonBoundaries.length % 2 != 0) {
int thisExonX = getXPixels(abundance.length);
g.setColor(GREY);
g.fillRect(lastExonEndX, getYPixels(100), thisExonX - lastExonEndX, getYPixels(0) - getYPixels(100));
}
// Draw the plots per codon
// Work out the max count per codon
int maxCountPerCodon = 0;
for (int p = 0; p < abundance.length; p += 3) {
// Get the total abundance for the codon
int codon = abundance[p] + abundance[p + 1] + abundance[p + 2];
if (codon > maxCountPerCodon)
maxCountPerCodon = codon;
}
float lastY1 = -1;
float lastY2 = -1;
float lastY3 = -1;
float lastYabundance = -1;
for (int p = 0; p < abundance.length - 2; p += 3) {
// Get the total abundance for the codon
int codon = abundance[p] + abundance[p + 1] + abundance[p + 2];
float codonPercent = (codon * 100f) / maxCountPerCodon;
if (p > 0) {
g.setColor(Color.GRAY);
g.drawLine(getXPixels(p - 2), getYPixels(lastYabundance), getXPixels(p + 1), getYPixels(codonPercent));
}
lastYabundance = codonPercent;
// Calculate percentages for each sub-position
// Don't allow infinite values
float c1percent = lastY1;
float c2percent = lastY2;
float c3percent = lastY3;
if (maxCountPerCodon > 0) {
c1percent = (abundance[p] * 100f) / maxCountPerCodon;
c2percent = (abundance[p + 1] * 100f) / maxCountPerCodon;
c3percent = (abundance[p + 2] * 100f) / maxCountPerCodon;
}
System.err.println("Codon at " + p + " 1=" + abundance[p] + " 2=" + abundance[p + 1] + " 3=" + abundance[p + 2] + " total=" + codon);
System.err.println("Codon percentages " + p + " 1=" + c1percent + " 2=" + c2percent + " 3=" + c3percent);
if (p > 0) {
g.setColor(RED);
g.drawLine(getXPixels(p - 3), getYPixels(lastY1), getXPixels(p), getYPixels(c1percent));
g.setColor(GREEN);
g.drawLine(getXPixels(p - 2), getYPixels(lastY2), getXPixels(p + 1), getYPixels(c2percent));
g.setColor(BLUE);
g.drawLine(getXPixels(p - 1), getYPixels(lastY3), getXPixels(p + 2), getYPixels(c3percent));
}
lastY1 = c1percent;
lastY2 = c2percent;
lastY3 = c3percent;
}
}
use of uk.ac.babraham.SeqMonk.Utilities.AxisScale in project SeqMonk by s-andrews.
the class CumulativeDistributionPanel method paint.
public void paint(Graphics g) {
super.paint(g);
g.setColor(Color.WHITE);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(Color.BLACK);
// Draw the axes
// X-axis
g.drawLine(X_AXIS_SPACE, getHeight() - Y_AXIS_SPACE, getWidth() - 10, getHeight() - Y_AXIS_SPACE);
// Y-axis
g.drawLine(X_AXIS_SPACE, getHeight() - Y_AXIS_SPACE, X_AXIS_SPACE, 10);
// Draw the Y scale
AxisScale yAxisScale = new AxisScale(usedMin, usedMax);
double currentYValue = yAxisScale.getStartingValue();
while (currentYValue < usedMax) {
g.drawString(yAxisScale.format(currentYValue), 5, getYPixels(currentYValue) + (g.getFontMetrics().getAscent() / 2));
g.setColor(Color.LIGHT_GRAY);
g.drawLine(X_AXIS_SPACE - 3, getYPixels(currentYValue), getWidth() - 10, getYPixels(currentYValue));
g.drawLine(X_AXIS_SPACE, getYPixels(currentYValue), X_AXIS_SPACE - 3, getYPixels(currentYValue));
g.setColor(Color.LIGHT_GRAY);
g.drawLine(X_AXIS_SPACE + 1, getYPixels(currentYValue), getWidth() - 10, getYPixels(currentYValue));
g.setColor(Color.BLACK);
currentYValue += yAxisScale.getInterval();
}
// Draw x scale
AxisScale xAxisScale = new AxisScale(0, 100);
double currentXValue = xAxisScale.getStartingValue();
while (currentXValue < 100) {
g.drawString(xAxisScale.format(currentXValue), getXPixels(currentXValue), getHeight() - (Y_AXIS_SPACE - (g.getFontMetrics().getHeight() + 3)));
g.drawLine(getXPixels(currentXValue), getHeight() - Y_AXIS_SPACE, getXPixels(currentXValue), getHeight() - (Y_AXIS_SPACE - 3));
currentXValue += xAxisScale.getInterval();
}
// Mark the 50th percentile
g.setColor(Color.LIGHT_GRAY);
g.drawLine(getXPixels(50), getHeight() - Y_AXIS_SPACE, getXPixels(50), 10);
g.setColor(Color.BLACK);
// Put the probe list name at the top
g.drawString(title, (getWidth() - 10) - (g.getFontMetrics().stringWidth(title)), g.getFontMetrics().getHeight());
// Put the names on the right
for (int n = 0; n < names.length; n++) {
g.setColor(ColourIndexSet.getColour(n));
g.drawString(names[n], X_AXIS_SPACE + 5, g.getFontMetrics().getHeight() * (n + 1));
}
// Now draw the lines
for (int d = 0; d < distributions.length; d++) {
g.setColor(ColourIndexSet.getColour(d));
int lastY = 0;
int lastX = 0;
double width = getWidth() - (X_AXIS_SPACE + 10);
for (int x = 0; x < distributions[d].length; x++) {
double proportion = x / (double) distributions[d].length;
int thisY = getYPixels(distributions[d][x]);
int thisX = X_AXIS_SPACE;
thisX += (int) (width * proportion);
if (x > 0) {
g.drawLine(lastX, lastY, thisX, thisY);
}
lastY = thisY;
lastX = thisX;
}
}
}
use of uk.ac.babraham.SeqMonk.Utilities.AxisScale in project SeqMonk by s-andrews.
the class BeanPlotScaleBar method setLimits.
public void setLimits(double min, double max) {
axisScale = new AxisScale(min, max);
repaint();
}
Aggregations