Search in sources :

Example 1 with HotColdColourGradient

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

the class MAPlotPanel 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 = (xStore.getValueForProbe(probes[p]) + yStore.getValueForProbe(probes[p])) / 2;
            float yValue = xStore.getValueForProbe(probes[p]) - yStore.getValueForProbe(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 = (xStore.getValueForProbe(subListProbes[p]) + yStore.getValueForProbe(subListProbes[p])) / 2;
                    float yValue = xStore.getValueForProbe(subListProbes[p]) - yStore.getValueForProbe(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 2 with HotColdColourGradient

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

the class PCAScatterPlotPanel 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()];
    int storeCount = data.getStoreCount();
    for (int p = 0; p < storeCount; p++) {
        float xValue = data.getPCAValue(p, xIndex);
        float yValue = data.getPCAValue(p, yIndex);
        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].setStore(data.getStore(p));
        } else {
            // belong to
            if (highlightedSets == null)
                grid[x][y].count++;
        // We have multiple probes at this location but we'll leave
        // the store set to the first one so we've got something
        // to label at least.
        // grid[x][y].setStore(null);
        }
    }
    if (highlightedSets != null) {
        for (int s = 0; s < highlightedSets.length; s++) {
            for (int p = 0; p < storeCount; p++) {
                if (highlightedSets[s].containsDataStore(data.getStore(p))) {
                    float xValue = data.getPCAValue(p, xIndex);
                    float yValue = data.getPCAValue(p, yIndex);
                    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;
                    }
                    // 1 = no list so 2 is the lowest sublist index
                    grid[x][y].count = s + 2;
                }
            }
        }
    }
    // 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 (highlightedSets == null) {
            nonred[i].color = gradient.getColor(nonred[i].count, minCount, maxCount);
        } else {
            if (nonred[i].count > highlightedSets.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) ColourGradient(uk.ac.babraham.SeqMonk.Gradients.ColourGradient) HotColdColourGradient(uk.ac.babraham.SeqMonk.Gradients.HotColdColourGradient)

Example 3 with HotColdColourGradient

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

the class DisplayPreferences method setGradient.

public void setGradient(int gradientType) {
    if (equalsAny(new int[] { GRADIENT_GREYSCALE, GRADIENT_HOT_COLD, GRADIENT_RED_GREEN, GRADIENT_MAGENTA_GREEN, GRADIENT_RED_WHITE }, gradientType)) {
        currentGradientValue = gradientType;
        switch(gradientType) {
            case GRADIENT_GREYSCALE:
                currentGradient = new GreyscaleColourGradient();
                break;
            case GRADIENT_HOT_COLD:
                currentGradient = new HotColdColourGradient();
                break;
            case GRADIENT_RED_GREEN:
                currentGradient = new RedGreenColourGradient();
                break;
            case GRADIENT_MAGENTA_GREEN:
                currentGradient = new MagentaGreenColourGradient();
                break;
            case GRADIENT_RED_WHITE:
                currentGradient = new RedWhiteColourGradient();
                break;
        }
        if (invertGradient) {
            currentGradient = new InvertedGradient(currentGradient);
        }
        optionsChanged();
    } else {
        throw new IllegalArgumentException("Value " + gradientType + " is not a valid gradient type");
    }
}
Also used : HotColdColourGradient(uk.ac.babraham.SeqMonk.Gradients.HotColdColourGradient) GreyscaleColourGradient(uk.ac.babraham.SeqMonk.Gradients.GreyscaleColourGradient) RedGreenColourGradient(uk.ac.babraham.SeqMonk.Gradients.RedGreenColourGradient) InvertedGradient(uk.ac.babraham.SeqMonk.Gradients.InvertedGradient) MagentaGreenColourGradient(uk.ac.babraham.SeqMonk.Gradients.MagentaGreenColourGradient) RedWhiteColourGradient(uk.ac.babraham.SeqMonk.Gradients.RedWhiteColourGradient)

Example 4 with HotColdColourGradient

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

the class StrandBiasPlotPanel 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 < allValues.length; p++) {
        if (allValues[p].count == 0)
            continue;
        int x = getX(allValues[p].count);
        int y = getY(allValues[p].proportion);
        if (grid[x][y] == null) {
            grid[x][y] = new ProbePairValue(allValues[p].count, allValues[p].proportion, x, y);
            grid[x][y].setProbe(allValues[p].probe);
            // See if we're assigning a sublist
            if (subListProbes.containsKey(allValues[p].probe)) {
                grid[x][y].count = subListProbes.get(allValues[p].probe);
            }
        } 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);
        }
    }
    // 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) ColourGradient(uk.ac.babraham.SeqMonk.Gradients.ColourGradient) HotColdColourGradient(uk.ac.babraham.SeqMonk.Gradients.HotColdColourGradient)

Example 5 with HotColdColourGradient

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

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