Search in sources :

Example 6 with HotColdColourGradient

use of uk.ac.babraham.SeqMonk.Gradients.HotColdColourGradient 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 7 with HotColdColourGradient

use of uk.ac.babraham.SeqMonk.Gradients.HotColdColourGradient 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)

Example 8 with HotColdColourGradient

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

the class CisTransScatterPlotPanel 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();
    Arrays.sort(probes);
    for (int p = 0; p < probes.length; p++) {
        if (filterChromosome != null && probes[p].chromosome() != filterChromosome)
            continue;
        float xValue = xData[p];
        float yValue = yData[p];
        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 {
            grid[x][y].count++;
            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 = nonred[0].count;
    int 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 = 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) Probe(uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe) ColourGradient(uk.ac.babraham.SeqMonk.Gradients.ColourGradient) HotColdColourGradient(uk.ac.babraham.SeqMonk.Gradients.HotColdColourGradient)

Example 9 with HotColdColourGradient

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

the class ZScoreScatterPlotPanel 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()];
    try {
        for (int p = 0; p < probes.length; p++) {
            /* x value is the mean intensity */
            float xValue = (xStore.getValueForProbe(probes[p]) + yStore.getValueForProbe(probes[p])) / 2;
            /* y value is the z-score */
            float yValue = probeZScoreLookupTable.get(probes[p]).floatValue();
            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++) {
                    // TODO: this needs to be sorted out properly - it's to do with the filtering out of NA probes
                    if (probeZScoreLookupTable.containsKey(subListProbes[p])) {
                        // System.err.println("p = " + p + ", name = " + subListProbes[p].name());
                        /* x value is the mean intensity */
                        float xValue = (xStore.getValueForProbe(subListProbes[p]) + yStore.getValueForProbe(subListProbes[p])) / 2;
                        /* y value is the z-score */
                        float yValue = probeZScoreLookupTable.get(subListProbes[p]).floatValue();
                        // System.err.println("for " + probes[p].name() + ", xValue = " + xValue+ ", yValue = " + yValue);
                        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 = Color.LIGHT_GRAY;
            } else {
                nonred[i].color = ColourIndexSet.getColour(nonred[i].count - 2);
            }
        }
    }
    nonRedundantValues = nonred;
    lastNonredWidth = getWidth();
    lastNonredHeight = getHeight();
}
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 10 with HotColdColourGradient

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

the class DisplayPreferences method reset.

public void reset() {
    listeners.removeAllElements();
    currentColourType = COLOUR_TYPE_GRADIENT;
    currentDisplayMode = DISPLAY_MODE_READS_ONLY;
    currentGradient = new HotColdColourGradient();
    currentGradientValue = GRADIENT_HOT_COLD;
    currentGraphType = GRAPH_TYPE_BAR;
    currentReadDensity = READ_DENSITY_LOW;
    currentReadDisplay = READ_DISPLAY_COMBINED;
    currentScaleType = SCALE_TYPE_POSITIVE;
}
Also used : HotColdColourGradient(uk.ac.babraham.SeqMonk.Gradients.HotColdColourGradient)

Aggregations

HotColdColourGradient (uk.ac.babraham.SeqMonk.Gradients.HotColdColourGradient)11 ColourGradient (uk.ac.babraham.SeqMonk.Gradients.ColourGradient)9 Probe (uk.ac.babraham.SeqMonk.DataTypes.Probes.Probe)5 SeqMonkException (uk.ac.babraham.SeqMonk.SeqMonkException)4 FontMetrics (java.awt.FontMetrics)1 GreyscaleColourGradient (uk.ac.babraham.SeqMonk.Gradients.GreyscaleColourGradient)1 InvertedGradient (uk.ac.babraham.SeqMonk.Gradients.InvertedGradient)1 MagentaGreenColourGradient (uk.ac.babraham.SeqMonk.Gradients.MagentaGreenColourGradient)1 RedGreenColourGradient (uk.ac.babraham.SeqMonk.Gradients.RedGreenColourGradient)1 RedWhiteColourGradient (uk.ac.babraham.SeqMonk.Gradients.RedWhiteColourGradient)1 AxisScale (uk.ac.babraham.SeqMonk.Utilities.AxisScale)1