use of uk.ac.babraham.SeqMonk.Gradients.ColourGradient 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);
}
use of uk.ac.babraham.SeqMonk.Gradients.ColourGradient 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);
}
use of uk.ac.babraham.SeqMonk.Gradients.ColourGradient in project SeqMonk by s-andrews.
the class HierarchicalClusterDialog method progressComplete.
public void progressComplete(String command, Object result) {
clusterPanelGroup = new JPanel();
clusterPanelGroup.setLayout(new BorderLayout());
ColourGradient gradient = (ColourGradient) gradients.getSelectedItem();
if (invertGradient.isSelected()) {
gradient = new InvertedGradient(gradient);
}
if (negativeScale) {
scaleBar = new GradientScaleBar(gradient, -2, 2);
} else {
scaleBar = new GradientScaleBar(gradient, 0, 2);
}
JPanel topBottomSplit = new JPanel();
topBottomSplit.setLayout(new GridLayout(2, 1));
topBottomSplit.add(new JPanel());
topBottomSplit.add(scaleBar);
clusterPanel = new HierarchicalClusterPanel(probes, stores, (ClusterPair) result, normalise, (ColourGradient) gradients.getSelectedItem());
clusterPanelGroup.add(clusterPanel, BorderLayout.CENTER);
clusterPanelGroup.add(topBottomSplit, BorderLayout.EAST);
getContentPane().add(clusterPanelGroup, BorderLayout.CENTER);
setLocationRelativeTo(SeqMonkApplication.getInstance());
stateChanged(new ChangeEvent(clusterSlider));
setVisible(true);
}
use of uk.ac.babraham.SeqMonk.Gradients.ColourGradient in project SeqMonk by s-andrews.
the class HierarchicalClusterDialog method updateGradients.
private void updateGradients() {
ColourGradient gradient = (ColourGradient) gradients.getSelectedItem();
if (invertGradient.isSelected()) {
gradient = new InvertedGradient(gradient);
}
if (clusterPanel != null) {
clusterPanel.setGradient(gradient);
scaleBar.setGradient(gradient);
}
}
use of uk.ac.babraham.SeqMonk.Gradients.ColourGradient 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);
}
Aggregations