use of uk.ac.babraham.SeqMonk.Utilities.AxisScale in project SeqMonk by s-andrews.
the class LineGraphPanel 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() - 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.drawLine(X_AXIS_SPACE, getYPixels(currentYValue), X_AXIS_SPACE - 3, getYPixels(currentYValue));
currentYValue += yAxisScale.getInterval();
}
// Draw x ticks
for (int s = 0; s < stores.length; s++) {
int xTick = X_AXIS_SPACE + (s * ((getWidth() - (10 + X_AXIS_SPACE)) / (stores.length - 1)));
g.drawLine(xTick, getHeight() - Y_AXIS_SPACE, xTick, getHeight() - (Y_AXIS_SPACE - 3));
}
for (int s = 0; s < stores.length; s++) {
int xTick = X_AXIS_SPACE + (s * ((getWidth() - (10 + X_AXIS_SPACE)) / (stores.length - 1)));
int stringWidth = g.getFontMetrics().stringWidth(stores[s].name());
int xStart = xTick - (stringWidth / 2);
if (xStart < 1)
xStart = 1;
if (xStart + stringWidth > (getWidth() - 1))
xStart = (getWidth() - 1) - stringWidth;
g.drawString(stores[s].name(), xStart, getHeight() - (Y_AXIS_SPACE - (g.getFontMetrics().getHeight() + 3)));
}
// Put the probe list name at the top
String listName = list.name() + " (" + probes.length + " probes)";
g.drawString(listName, (getWidth() - 10) - (g.getFontMetrics().stringWidth(listName)), 10);
// Now draw the probes
int lastX = 0;
int lastY = 0;
int thisX = 0;
int thisY = 0;
double value = 0;
if (summarise) {
int upperY;
int lowerY;
g.setColor(BLUE);
for (int s = 0; s < means.length; s++) {
thisX = getXPixels(s);
value = means[s];
if (value < usedMin)
value = usedMin;
if (value > usedMax)
value = usedMax;
thisY = getYPixels(value);
if (s > 0) {
g.drawLine(lastX, lastY, thisX, thisY);
}
upperY = getYPixels(means[s] + confInts[s]);
lowerY = getYPixels(means[s] - confInts[s]);
// Line between upper and lower CIs
g.drawLine(thisX, lowerY, thisX, upperY);
// Bar across lower CI
g.drawLine(thisX - 2, lowerY, thisX + 2, lowerY);
// Bar across upper CI
g.drawLine(thisX - 2, upperY, thisX + 2, upperY);
lastX = thisX;
lastY = thisY;
}
} else {
for (int p = 0; p < probes.length; p++) {
getValues(probes[p]);
g.setColor(DisplayPreferences.getInstance().getGradient().getColor(values[0], usedMin, usedMax));
for (int s = 0; s < values.length; s++) {
thisX = X_AXIS_SPACE + (s * ((getWidth() - (10 + X_AXIS_SPACE)) / (stores.length - 1)));
value = values[s];
if (value < usedMin)
value = usedMin;
if (value > usedMax)
value = usedMax;
thisY = getYPixels(value);
if (s > 0) {
g.drawLine(lastX, lastY, thisX, thisY);
}
lastX = thisX;
lastY = thisY;
}
}
if (selectedProbe != null) {
getValues(selectedProbe);
g.setColor(Color.BLACK);
for (int s = 0; s < values.length; s++) {
thisX = X_AXIS_SPACE + (s * ((getWidth() - (10 + X_AXIS_SPACE)) / (stores.length - 1)));
value = values[s];
if (value < usedMin)
value = usedMin;
if (value > usedMax)
value = usedMax;
thisY = getYPixels(value);
if (s > 0) {
g.drawLine(lastX, lastY, thisX, thisY);
}
lastX = thisX;
lastY = thisY;
}
g.drawString(selectedProbe.name(), selectedX, selectedY);
}
}
}
use of uk.ac.babraham.SeqMonk.Utilities.AxisScale in project SeqMonk by s-andrews.
the class PCAHistogramPanel method paintComponent.
public void paintComponent(Graphics g) {
super.paintComponent(g);
// We want a white background
g.setColor(Color.WHITE);
g.fillRect(0, 0, getWidth(), getHeight());
// Draw the graph axes first. We leave a border on all sides
g.setColor(Color.BLACK);
g.drawLine(X_AXIS_SPACE, 5, X_AXIS_SPACE, getHeight() - Y_AXIS_SPACE);
g.drawLine(X_AXIS_SPACE, getHeight() - Y_AXIS_SPACE, getWidth() - 5, getHeight() - Y_AXIS_SPACE);
// If we don't have any data we can stop here
if (categories == null)
return;
// If we have a stupid scale we can also stop here
if (Double.isInfinite(currentMaxValue) || Double.isNaN(currentMaxValue) || Double.isInfinite(currentMinValue) || Double.isNaN(currentMinValue)) {
System.err.println("Had infinite or NaN ends to the scale - not going to try to draw that");
return;
}
// We need the scaling factor for the y-axis
double yScale = 0;
yScale = (double) (getHeight() - (5 + Y_AXIS_SPACE)) / maxCount;
// Now draw the scale on the y axis
AxisScale yAxisScale = new AxisScale(0, maxCount);
double currentYValue = yAxisScale.getStartingValue();
while (currentYValue < maxCount) {
double yHeight = currentYValue * yScale;
g.drawString(yAxisScale.format(currentYValue), 2, (int) ((getHeight() - Y_AXIS_SPACE) - yHeight) + (g.getFontMetrics().getAscent() / 2));
// Put a line across the plot
if (currentYValue != 0) {
g.setColor(Color.LIGHT_GRAY);
g.drawLine(X_AXIS_SPACE, (int) ((getHeight() - Y_AXIS_SPACE) - yHeight), getWidth() - 5, (int) ((getHeight() - Y_AXIS_SPACE) - yHeight));
g.setColor(Color.BLACK);
}
currentYValue += yAxisScale.getInterval();
}
// Now draw the scale on the x axis
if (categories.length > 0) {
AxisScale xAxisScale = new AxisScale(currentMinValue, currentMaxValue);
double currentXValue = xAxisScale.getStartingValue();
while (currentXValue < currentMaxValue) {
g.drawString(xAxisScale.format(currentXValue), getX(currentXValue), (int) ((getHeight() - Y_AXIS_SPACE) + 15));
currentXValue += xAxisScale.getInterval();
}
}
// Now we can draw the different categories
for (int c = 0; c < categories.length; c++) {
categories[c].xStart = getX(categories[c].minValue);
;
categories[c].xEnd = getX(categories[c].maxValue);
g.setColor(ColourScheme.HISTOGRAM_BAR);
double ySize = categories[c].count * yScale;
g.fillRect(categories[c].xStart, (int) ((getHeight() - Y_AXIS_SPACE) - ySize), categories[c].xEnd - categories[c].xStart, (int) (ySize));
// Draw a box around it
g.setColor(Color.BLACK);
g.drawRect(categories[c].xStart, (int) ((getHeight() - Y_AXIS_SPACE) - ySize), categories[c].xEnd - categories[c].xStart, (int) (ySize));
}
// Draw the line for the cutoff value
g.setColor(Color.RED);
g.drawLine(getX(cutoffValue), 5, getX(cutoffValue), getHeight() - Y_AXIS_SPACE);
}
use of uk.ac.babraham.SeqMonk.Utilities.AxisScale in project SeqMonk by s-andrews.
the class DuplicationPlotPanel method paint.
/* (non-Javadoc)
* @see javax.swing.JComponent#paint(java.awt.Graphics)
*/
public void paint(Graphics g) {
super.paint(g);
if (X_AXIS_SPACE == 0) {
X_AXIS_SPACE = g.getFontMetrics().stringWidth("Dup (%)") + 4;
}
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);
// Centre line
g.setColor(Color.GRAY);
g.drawLine(X_AXIS_SPACE, getY(0), getWidth() - 10, getY(0));
g.setColor(Color.BLACK);
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) {
int xPos = X_AXIS_SPACE - (5 + g.getFontMetrics().stringWidth(yAxisScale.format(currentYValue)));
g.drawString(yAxisScale.format(currentYValue), xPos, getY(currentYValue) + (g.getFontMetrics().getAscent() / 2));
g.drawLine(X_AXIS_SPACE, getY(currentYValue), X_AXIS_SPACE - 3, getY(currentYValue));
currentYValue += yAxisScale.getInterval();
}
// X label
String xLabel = "Log2 Reads per kilobase";
g.drawString(xLabel, (getWidth() / 2) - (metrics.stringWidth(xLabel) / 2), getHeight() - 3);
// Y label
String yLabel = "Dup (%)";
g.drawString(yLabel, 2, 15);
// Sample name
int sampleNameWidth = g.getFontMetrics().stringWidth(name);
g.drawString(name, X_AXIS_SPACE + (((getWidth() - (X_AXIS_SPACE + 3)) / 2) - (sampleNameWidth / 2)), 15);
// ProbeList
// g.drawString(probeList.name(), getWidth()-10-metrics.stringWidth(probeList.name()), 15);
g.setColor(Color.BLUE);
for (int p = 0; p < nonRedundantValues.length; p++) {
if ((madeSelection || makingSelection) && nonRedundantValues[p].yValue >= Math.min(ySelectionStart, ySelectionEnd) && nonRedundantValues[p].yValue <= Math.max(ySelectionStart, ySelectionEnd)) {
g.setColor(Color.BLACK);
} else {
// if (nonRedundantValues[p].color == null) {
// nonRedundantValues[p].color = Color.YELLOW;
// }
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));
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 StrandBiasPlotPanel 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";
if (noData) {
message = "No data to show";
}
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(store.name(), (getWidth() / 2) - (metrics.stringWidth(store.name()) / 2), getHeight() - 3);
// Y label
g.drawString("Proportion Same Strand", X_AXIS_SPACE + 3, 15);
// If we have sublists draw them below this in the right colours
if (subLists != null) {
for (int s = 0; s < subLists.length; s++) {
g.setColor(ColourIndexSet.getColour(s));
g.drawString(subLists[s].name(), X_AXIS_SPACE + 3, 15 + (g.getFontMetrics().getHeight() * (s + 1)));
}
g.setColor(Color.BLACK);
}
// ProbeList
g.drawString(probeList.name(), getWidth() - 10 - metrics.stringWidth(probeList.name()), 15);
g.setColor(Color.BLUE);
for (int p = 0; p < nonRedundantValues.length; p++) {
if ((madeSelection || makingSelection) && nonRedundantValues[p].bias >= Math.min(diffStart, diffEnd) && nonRedundantValues[p].bias <= 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);
}
// 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 VariancePlotPanel 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";
if (noData) {
message = "No data to show";
}
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(repSet.name(), (getWidth() / 2) - (metrics.stringWidth(repSet.name()) / 2), getHeight() - 3);
// Y label
if (varianceMeasure == VARIANCE_SEM) {
g.drawString("SEM", X_AXIS_SPACE + 3, 15);
} else if (varianceMeasure == VARIANCE_STDEV) {
g.drawString("StDev", X_AXIS_SPACE + 3, 15);
} else if (varianceMeasure == VARIANCE_COEF) {
g.drawString("Coef Var", X_AXIS_SPACE + 3, 15);
}
// If we have sublists draw them below this in the right colours
if (subLists != null) {
for (int s = 0; s < subLists.length; s++) {
g.setColor(ColourIndexSet.getColour(s));
g.drawString(subLists[s].name(), X_AXIS_SPACE + 3, 15 + (g.getFontMetrics().getHeight() * (s + 1)));
}
g.setColor(Color.BLACK);
}
// ProbeList
g.drawString(probeList.name(), getWidth() - 10 - metrics.stringWidth(probeList.name()), 15);
g.setColor(Color.BLUE);
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 {
g.setColor(nonRedundantValues[p].color);
}
g.fillRect(nonRedundantValues[p].x - (dotSize / 2), nonRedundantValues[p].y - (dotSize / 2), dotSize, dotSize);
}
// Now we draw the regression for the smoothed values
g.setColor(Color.BLACK);
float[] intensityValues = smoothedTrend.orderedValues();
float[] smoothedVariances = smoothedTrend.orderedSmoothedVariances();
for (int i = 1; i < intensityValues.length; i++) {
g.drawLine(getX(intensityValues[i - 1]), getY(smoothedVariances[i - 1]), getX(intensityValues[i]), getY(smoothedVariances[i]));
}
// We annotate with the overall difference to the mean
String overallDiffLabel = "Overall variance difference = " + df.format(smoothedTrend.averageDeviationFromSmoothed());
g.setColor(Color.BLACK);
g.drawString(overallDiffLabel, getWidth() - (10 + g.getFontMetrics().stringWidth(overallDiffLabel)), getHeight() - (Y_AXIS_SPACE + 3));
// 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(getValueFromY(cursorY) - smoothedTrend.getSmoothedValueForX((float) getValueFromX(cursorX)));
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);
}
}
}
Aggregations