From c65931a7b6b0625f39b2e50d318b2b330679d64f Mon Sep 17 00:00:00 2001
From: tcarver <tjc>
Date: Wed, 24 Oct 2012 15:34:48 +0100
Subject: [PATCH] fixes for heatmap
---
.../artemis/components/alignment/BamView.java | 6 +-
.../components/alignment/CoveragePanel.java | 70 ++++++++++++-------
2 files changed, 46 insertions(+), 30 deletions(-)
diff --git a/uk/ac/sanger/artemis/components/alignment/BamView.java b/uk/ac/sanger/artemis/components/alignment/BamView.java
index ca938c72d..b0d974619 100644
--- a/uk/ac/sanger/artemis/components/alignment/BamView.java
+++ b/uk/ac/sanger/artemis/components/alignment/BamView.java
@@ -677,7 +677,7 @@ public class BamView extends JPanel
final int cov[] = new int[nbins];
for(int i=0; i<nbins; i++)
cov[i] = 0;
-
+
final CloseableIterator<SAMRecord> it = inputSam.queryOverlapping(refName, start, end);
try
{
@@ -1809,7 +1809,7 @@ public class BamView extends JPanel
}
int hgt = jspView.getVisibleRect().height-scaleHeight;
- if(!cbCoverageStrandView.isSelected() && !cbCoverageHeatMap.isSelected())
+ if(!cbCoverageStrandView.isSelected() && !coverageView.isPlotHeatMap())
{
try
{
@@ -1824,7 +1824,7 @@ public class BamView extends JPanel
g2.translate(0, getJspView().getViewport().getViewPosition().y);
coverageView.drawSelectionRange(g2, pixPerBase, start, end, getHeight(), Color.PINK);
- coverageView.draw(g2, getWidth(), hgt);
+ coverageView.draw(g2, getWidth(), hgt, hideBamList);
coverageView.drawMax(g2);
}
diff --git a/uk/ac/sanger/artemis/components/alignment/CoveragePanel.java b/uk/ac/sanger/artemis/components/alignment/CoveragePanel.java
index 8942ad5e0..1f46780d7 100644
--- a/uk/ac/sanger/artemis/components/alignment/CoveragePanel.java
+++ b/uk/ac/sanger/artemis/components/alignment/CoveragePanel.java
@@ -180,7 +180,7 @@ import net.sf.samtools.SAMRecord;
}
}
- draw(g2, getWidth(), getHeight());
+ draw(g2, getWidth(), getHeight(), null);
}
protected void addRecord(SAMRecord thisRead, int offset, String fileName)
@@ -196,7 +196,7 @@ import net.sf.samtools.SAMRecord;
}
final int col;
- if(plotByStrand && thisRead.getReadNegativeStrandFlag())
+ if(plotByStrand && !isPlotHeatMap() && thisRead.getReadNegativeStrandFlag())
col = 1;
else
col = 0;
@@ -226,7 +226,7 @@ import net.sf.samtools.SAMRecord;
}
}
- protected void draw(Graphics2D g2, int wid, int hgt)
+ protected void draw(Graphics2D g2, int wid, int hgt, List<Short> hideBamList)
{
int size = bamView.bamList.size();
if(includeCombined)
@@ -237,35 +237,43 @@ import net.sf.samtools.SAMRecord;
else
lines = getLineAttributes(size);
-
Enumeration<String> plotEum = plots.keys();
while(plotEum.hasMoreElements())
{
String fileName = (String) plotEum.nextElement();
int[][] thisPlot = plots.get(fileName);
- int index;
+ int idx;
if(fileName.equals("-1"))
- index = lines.length-1;
+ idx = lines.length-1;
else
- index = bamView.bamList.indexOf(fileName);
+ idx = bamView.bamList.indexOf(fileName);
+ final LineAttributes line = lines[idx];
if(plotHeatMap)
- drawHeatMap(g2, hgt, index, thisPlot);
+ {
+ if(hideBamList != null)
+ {
+ for(Short i: hideBamList)
+ if(idx > i)
+ idx--;
+ }
+ drawHeatMap(g2, hgt, line, idx, thisPlot);
+ }
else
- drawLinePlot(g2, wid, hgt, index, thisPlot);
+ drawLinePlot(g2, wid, hgt, line, thisPlot);
}
}
- private void drawLinePlot(final Graphics2D g2, int wid, int hgt, int index, int[][] thisPlot)
+ private void drawLinePlot(final Graphics2D g2, int wid, int hgt, LineAttributes line, int[][] thisPlot)
{
- g2.setColor(lines[index].getLineColour());
+ g2.setColor(line.getLineColour());
int hgt2 = hgt/2;
float maxVal = getValue(max);
- if(lines[index].getPlotType() == LineAttributes.PLOT_TYPES[0])
+ if(line.getPlotType() == LineAttributes.PLOT_TYPES[0])
{
- g2.setStroke(lines[index].getStroke());
+ g2.setStroke(line.getStroke());
for(int i=1; i<thisPlot.length; i++)
{
int x0 = (int) ((((i-1)*(windowSize)) + windowSize/2.f)*pixPerBase);
@@ -351,34 +359,34 @@ import net.sf.samtools.SAMRecord;
* Draw as heat map
* @param g2
* @param hgt
- * @param index
+ * @param line
+ * @param idx
* @param thisPlot
*/
- private void drawHeatMap(final Graphics2D g2, int hgt, int index, int[][] thisPlot)
+ private void drawHeatMap(final Graphics2D g2, int hgt, LineAttributes line, int idx, int[][] thisPlot)
{ // heat map
- int NUMBER_OF_SHADES = 254;
+ int NUMBER_OF_SHADES = 240;
int plotHgt = hgt/plots.size();
- int plotPos = plotHgt * index;
- Color definedColours[] = Plot.makeColours(lines[index].getLineColour(),
+ int plotPos = plotHgt * idx;
+ Color definedColours[] = Plot.makeColours(line.getLineColour(),
NUMBER_OF_SHADES);
-
+
float maxVal = getValue(max);
for(int i=0; i<thisPlot.length; i++)
{
int xpos = (int) (i*windowSize*pixPerBase);
-
// this is a number between 0.0 and 1.0
final float scaledValue = getValue(thisPlot[i][0]) / maxVal;
// set color based on value
- int colourIndex =
+ int colourIdx =
(int)(definedColours.length * 0.999 * scaledValue);
- if(colourIndex > definedColours.length - 1)
- colourIndex = definedColours.length - 1;
- else if (colourIndex < 0)
- colourIndex = 0;
-
- g2.setColor(definedColours[ colourIndex ]);
+ if(colourIdx > definedColours.length - 1)
+ colourIdx = definedColours.length - 1;
+ else if (colourIdx <= 0)
+ continue;
+
+ g2.setColor(definedColours[ colourIdx ]);
g2.fillRect(xpos, plotPos, windowSize, plotHgt);
}
}
@@ -433,6 +441,14 @@ import net.sf.samtools.SAMRecord;
this.plotHeatMap = plotHeatMap;
}
+ /**
+ * @return the plotHeatMap
+ */
+ protected boolean isPlotHeatMap()
+ {
+ return plotHeatMap;
+ }
+
private void defineOpts()
{
final JPanel opts = new JPanel(new GridBagLayout());
--
GitLab