Search in sources :

Example 6 with ColourGradient

use of uk.ac.babraham.SeqMonk.Gradients.ColourGradient in project SeqMonk by s-andrews.

the class VariancePlotPanel method calculateNonredundantSet.

/**
 * This collapses individual points which are over the same
 * pixel when redrawing the plot at a different scale
 */
private synchronized void calculateNonredundantSet() {
    closestPoint = null;
    ProbePairValue[][] grid = new ProbePairValue[getWidth()][getHeight()];
    Probe[] probes = probeList.getAllProbes();
    try {
        for (int p = 0; p < probes.length; p++) {
            float xValue = repSet.getValueForProbeExcludingUnmeasured(probes[p]);
            float yValue = getYValue(probes[p]);
            if (Float.isNaN(xValue) || Float.isInfinite(xValue) || Float.isNaN(yValue) || Float.isInfinite(yValue)) {
                continue;
            }
            int x = getX(xValue);
            int y = getY(yValue);
            if (grid[x][y] == null) {
                grid[x][y] = new ProbePairValue(xValue, yValue, x, y);
                grid[x][y].setProbe(probes[p]);
            } else {
                // belong to
                if (subLists == null)
                    grid[x][y].count++;
                // As we have multiple probes at this point we remove the
                // specific probe annotation.
                grid[x][y].setProbe(null);
            }
        }
        if (subLists != null) {
            for (int s = 0; s < subLists.length; s++) {
                Probe[] subListProbes = subLists[s].getAllProbes();
                for (int p = 0; p < subListProbes.length; p++) {
                    float xValue = repSet.getValueForProbeExcludingUnmeasured(subListProbes[p]);
                    float yValue = getYValue(subListProbes[p]);
                    int x = getX(xValue);
                    int y = getY(yValue);
                    if (grid[x][y] == null) {
                        // This messes up where we catch it in the middle of a redraw
                        continue;
                    // throw new IllegalArgumentException("Found subList position not in main list");
                    }
                    // 1 = no list so 2 is the lowest sublist index
                    grid[x][y].count = s + 2;
                }
            }
        }
    } catch (SeqMonkException e) {
        throw new IllegalStateException(e);
    }
    // Now we need to put all of the ProbePairValues into
    // a single array;
    int count = 0;
    for (int x = 0; x < grid.length; x++) {
        for (int y = 0; y < grid[x].length; y++) {
            if (grid[x][y] != null)
                count++;
        }
    }
    ProbePairValue[] nonred = new ProbePairValue[count];
    count--;
    for (int x = 0; x < grid.length; x++) {
        for (int y = 0; y < grid[x].length; y++) {
            if (grid[x][y] != null) {
                nonred[count] = grid[x][y];
                count--;
            }
        }
    }
    Arrays.sort(nonred);
    // Work out the 95% percentile count
    int minCount = 1;
    int maxCount = 2;
    if (nonred.length > 0) {
        minCount = nonred[0].count;
        maxCount = nonred[((nonred.length - 1) * 95) / 100].count;
    }
    // Go through every nonred assigning a suitable colour
    ColourGradient gradient = new HotColdColourGradient();
    for (int i = 0; i < nonred.length; i++) {
        if (subLists == null) {
            nonred[i].color = gradient.getColor(nonred[i].count, minCount, maxCount);
        } else {
            if (nonred[i].count > subLists.length + 1) {
                throw new IllegalArgumentException("Count above threshold when showing sublists");
            }
            if (nonred[i].count == 1) {
                nonred[i].color = VERY_LIGHT_GREY;
            } else {
                nonred[i].color = ColourIndexSet.getColour(nonred[i].count - 2);
            }
        }
    }
    nonRedundantValues = nonred;
    lastNonredWidth = getWidth();
    lastNonredHeight = getHeight();
// System.out.println("Nonred was "+nonRedundantValues.length+" from "+probes.length);
}
Also used : HotColdColourGradient(uk.ac.babraham.SeqMonk.Gradients.HotColdColourGradient) SeqMonkException(uk.ac.babraham.SeqMonk.SeqMonkException) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe) ColourGradient(uk.ac.babraham.SeqMonk.Gradients.ColourGradient) HotColdColourGradient(uk.ac.babraham.SeqMonk.Gradients.HotColdColourGradient)

Example 7 with ColourGradient

use of uk.ac.babraham.SeqMonk.Gradients.ColourGradient in project SeqMonk by s-andrews.

the class DomainogramDialog method updateGradients.

private void updateGradients() {
    ColourGradient gradient = (ColourGradient) gradients.getSelectedItem();
    if (invertGradient.isSelected()) {
        gradient = new InvertedGradient(gradient);
    }
    for (int i = 0; i < chromosomeDomainPanels.length; i++) {
        // We skipped it
        if (chromosomeDomainPanels[i] == null)
            continue;
        chromosomeDomainPanels[i].setGradient(gradient);
    }
    scaleBar.setGradient(gradient);
}
Also used : InvertedGradient(uk.ac.babraham.SeqMonk.Gradients.InvertedGradient) ColourGradient(uk.ac.babraham.SeqMonk.Gradients.ColourGradient)

Example 8 with ColourGradient

use of uk.ac.babraham.SeqMonk.Gradients.ColourGradient 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);
        }
    }
}
Also used : HotColdColourGradient(uk.ac.babraham.SeqMonk.Gradients.HotColdColourGradient) AxisScale(uk.ac.babraham.SeqMonk.Utilities.AxisScale) FontMetrics(java.awt.FontMetrics) ColourGradient(uk.ac.babraham.SeqMonk.Gradients.ColourGradient) HotColdColourGradient(uk.ac.babraham.SeqMonk.Gradients.HotColdColourGradient)

Example 9 with ColourGradient

use of uk.ac.babraham.SeqMonk.Gradients.ColourGradient in project SeqMonk by s-andrews.

the class CorrelationMatrix method updateGradients.

private void updateGradients() {
    ColourGradient gradient = (ColourGradient) gradients.getSelectedItem();
    if (invertGradient.isSelected()) {
        gradient = new InvertedGradient(gradient);
    }
    this.gradient = gradient;
    if (scaleBar != null) {
        scaleBar.setGradient(gradient);
        if (scaleBox.isSelected()) {
            scaleBar.setLimits(-1, 1);
        } else {
            scaleBar.setLimits(model.getMinCorrelation(), model.getMaxCorrelation());
        }
    }
    repaint();
}
Also used : InvertedGradient(uk.ac.babraham.SeqMonk.Gradients.InvertedGradient) ColourGradient(uk.ac.babraham.SeqMonk.Gradients.ColourGradient)

Example 10 with ColourGradient

use of uk.ac.babraham.SeqMonk.Gradients.ColourGradient in project SeqMonk by s-andrews.

the class DuplicationPlotPanel method calculateNonredundantSet.

/**
 * This collapses individual points which are over the same
 * pixel when redrawing the plot at a different scale
 */
private synchronized void calculateNonredundantSet() {
    closestPoint = null;
    ProbePairValue[][] grid = new ProbePairValue[getWidth()][getHeight()];
    for (int p = 0; p < probes.length; p++) {
        float xValue = densities[p];
        float yValue = duplications[p];
        if (Float.isNaN(xValue) || Float.isInfinite(xValue) || Float.isNaN(yValue) || Float.isInfinite(yValue)) {
            continue;
        }
        int x = getX(xValue);
        int y = getY(yValue);
        if (grid[x][y] == null) {
            grid[x][y] = new ProbePairValue(xValue, yValue, x, y);
            grid[x][y].setProbe(probes[p]);
        } else {
            // We don't increment the count if we're plotting sublists
            // as we use the count field to indicate which sublist we
            // belong to
            grid[x][y].count++;
            // As we have multiple probes at this point we remove the
            // specific probe annotation.
            grid[x][y].setProbe(null);
        }
    }
    // Now we need to put all of the ProbePairValues into
    // a single array;
    int count = 0;
    for (int x = 0; x < grid.length; x++) {
        for (int y = 0; y < grid[x].length; y++) {
            if (grid[x][y] != null)
                count++;
        }
    }
    ProbePairValue[] nonred = new ProbePairValue[count];
    count--;
    for (int x = 0; x < grid.length; x++) {
        for (int y = 0; y < grid[x].length; y++) {
            if (grid[x][y] != null) {
                nonred[count] = grid[x][y];
                count--;
            }
        }
    }
    Arrays.sort(nonred);
    // Work out the 95% percentile count
    int minCount = 1;
    int maxCount = 2;
    if (nonred.length > 0) {
        minCount = nonred[0].count;
        maxCount = nonred[((nonred.length - 1) * 95) / 100].count;
    }
    // Go through every nonred assigning a suitable colour
    ColourGradient gradient = new HotColdColourGradient();
    for (int i = 0; i < nonred.length; i++) {
        // nonred[i].color = ColourGradient.getColor(nonred[i].count, minCount, maxCount);
        nonred[i].color = gradient.getColor(nonred[i].count, minCount, maxCount);
    }
    nonRedundantValues = nonred;
    lastNonredWidth = getWidth();
    lastNonredHeight = getHeight();
// System.out.println("Nonred was "+nonRedundantValues.length+" from "+probes.length);
}
Also used : HotColdColourGradient(uk.ac.babraham.SeqMonk.Gradients.HotColdColourGradient) ColourGradient(uk.ac.babraham.SeqMonk.Gradients.ColourGradient) HotColdColourGradient(uk.ac.babraham.SeqMonk.Gradients.HotColdColourGradient)

Aggregations

ColourGradient (uk.ac.babraham.SeqMonk.Gradients.ColourGradient)13 HotColdColourGradient (uk.ac.babraham.SeqMonk.Gradients.HotColdColourGradient)9 Probe (uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe)5 InvertedGradient (uk.ac.babraham.SeqMonk.Gradients.InvertedGradient)4 SeqMonkException (uk.ac.babraham.SeqMonk.SeqMonkException)4 BorderLayout (java.awt.BorderLayout)1 FontMetrics (java.awt.FontMetrics)1 GridLayout (java.awt.GridLayout)1 JPanel (javax.swing.JPanel)1 ChangeEvent (javax.swing.event.ChangeEvent)1 ClusterPair (uk.ac.babraham.SeqMonk.DataTypes.Cluster.ClusterPair)1 GradientScaleBar (uk.ac.babraham.SeqMonk.Displays.GradientScaleBar.GradientScaleBar)1 AxisScale (uk.ac.babraham.SeqMonk.Utilities.AxisScale)1