Program: 161277
Project: 161277
Buggy source:
private void build(){
  final Function<SAMRecord,Color> samRecord2color=new ColorUtils.SAMRecordColorExtractor();
  final Function<Character,Color> base2color=C -> {
switch (Character.toUpperCase(C)) {
case 'N':
      return Color.BLACK;
case 'A':
    return Color.RED;
case 'T':
  return Color.GREEN;
case 'G':
return Color.YELLOW;
case 'C':
return Color.BLUE;
default :
return Color.ORANGE;
}
}
;
final Predicate<Integer> inInterval=refPos -> !(refPos < Bam2Raster.this.interval.getStart() || refPos > Bam2Raster.this.interval.getEnd());
String positionFormat="String_Node_Str";
final int refw=(int)Math.max(1.0,WIDTH / (double)(1 + interval.getEnd() - interval.getStart()));
final int ruler_height=String.format(positionFormat,Bam2Raster.this.interval.getEnd()).length() * refw;
final Dimension imageSize=new Dimension(WIDTH,refw + Bam2Raster.this.spaceYbetweenFeatures + ruler_height+ Bam2Raster.this.spaceYbetweenFeatures+ refw+ Bam2Raster.this.spaceYbetweenFeatures+ refw+ Bam2Raster.this.spaceYbetweenFeatures+ (Math.max(0,Bam2Raster.this.depthSize))+ (Bam2Raster.this.depthSize > 0 ? Bam2Raster.this.spaceYbetweenFeatures : 0)+ (Bam2Raster.this.maxNumberOfRows < 0 ? this.rows.size() : Math.min(this.rows.size(),Bam2Raster.this.maxNumberOfRows)) * (Bam2Raster.this.spaceYbetweenFeatures + refw) + Bam2Raster.this.spaceYbetweenFeatures);
this.image=new BufferedImage(imageSize.width,imageSize.height,BufferedImage.TYPE_INT_RGB);
final CharSequence genomicSequence;
if (Bam2Raster.this.indexedFastaSequenceFile != null) {
genomicSequence=new GenomicSequence(Bam2Raster.this.indexedFastaSequenceFile,Bam2Raster.this.interval.getContig());
}
 else {
genomicSequence=new AbstractCharSequence(){
@Override public int length(){
return interval.getEnd() + 10;
}
@Override public char charAt(int index){
return 'N';
}
}
;
}
final Graphics2D g=this.image.createGraphics();
g.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_COLOR_RENDER_QUALITY);
g.setColor(Color.WHITE);
g.fillRect(0,0,imageSize.width,imageSize.height);
LOG.info("String_Node_Str" + imageSize.width + "String_Node_Str"+ imageSize.height);
Map<Integer,Counter<Character>> ref2consensus=new HashMap<Integer,Counter<Character>>();
for (final Integer refpos : Bam2Raster.this.highlightPositions) {
g.setColor(new Color(255,235,246));
g.fill(new Rectangle2D.Double(convertToX(refpos),0,refw,this.image.getHeight()));
}
int y=0;
{
String title=interval.getContig() + "String_Node_Str" + this.key;
g.setColor(Color.BLACK);
hersheyFont.paint(g,title,new Rectangle2D.Double(1,1,title.length() * refw,refw));
y+=refw + Bam2Raster.this.spaceYbetweenFeatures;
}
for (int x=Bam2Raster.this.interval.getStart(); x <= Bam2Raster.this.interval.getEnd(); ++x) {
final double oneBaseWidth=convertToX(x + 1) - convertToX(x);
g.setColor(x % 10 == 0 ? Color.BLACK : Color.LIGHT_GRAY);
g.draw(new Line2D.Double(convertToX(x),0,convertToX(x),imageSize.height));
if ((x - Bam2Raster.this.interval.getStart()) % 10 == 0) {
g.setColor(Color.BLACK);
final String xStr=String.format(positionFormat,x);
final AffineTransform tr=g.getTransform();
final AffineTransform tr2=new AffineTransform(tr);
tr2.translate(convertToX(x + 1),y);
tr2.rotate(Math.PI / 2.0);
g.setTransform(tr2);
hersheyFont.paint(g,xStr,0,0,ruler_height,oneBaseWidth);
g.setTransform(tr);
}
}
y+=ruler_height + Bam2Raster.this.spaceYbetweenFeatures;
for (int x=Bam2Raster.this.interval.getStart(); x <= Bam2Raster.this.interval.getEnd(); ++x) {
final double oneBaseWidth=convertToX(x + 1) - convertToX(x);
final char c=x < 1 || x > genomicSequence.length() ? 'N' : genomicSequence.charAt(x - 1);
g.setColor(base2color.apply(c));
Bam2Raster.this.hersheyFont.paint(g,String.valueOf(c),convertToX(x) + 1,y,oneBaseWidth - 2,oneBaseWidth - 2);
}
y+=refw + Bam2Raster.this.spaceYbetweenFeatures;
final int consensus_y=y;
y+=refw + Bam2Raster.this.spaceYbetweenFeatures;
final int depth_y=y;
final int depth_array[]=new int[1 + (interval.getEnd() - interval.getStart())];
if (depthSize > 0) {
Arrays.fill(depth_array,0);
y+=depthSize + Bam2Raster.this.spaceYbetweenFeatures;
}
for (int rowIndex=0; rowIndex < rows.size(); ++rowIndex) {
final List<SAMRecord> row=rows.get(rowIndex);
boolean printThisRow=(Bam2Raster.this.maxNumberOfRows < 0 || rowIndex < Bam2Raster.this.maxNumberOfRows);
for (final SAMRecord rec : row) {
final Set<Integer> refposOfInsertions=new HashSet<>();
double x0=left2pixel(rec);
double x1=right2pixel(rec);
double y0=y;
double y1=y0 + refw;
Shape shapeRec=null;
if (x1 - x0 < Bam2Raster.this.minArrowWidth) {
shapeRec=new Rectangle2D.Double(x0,y0,x1 - x0,y1 - y0);
}
 else {
final GeneralPath path=new GeneralPath();
double arrow=Math.max(Bam2Raster.this.minArrowWidth,Math.min(Bam2Raster.this.maxArrowWidth,x1 - x0));
if (!rec.getReadNegativeStrandFlag()) {
path.moveTo(x0,y0);
path.lineTo(x1 - arrow,y0);
path.lineTo(x1,(y0 + y1) / 2);
path.lineTo(x1 - arrow,y1);
path.lineTo(x0,y1);
}
 else {
path.moveTo(x0 + arrow,y0);
path.lineTo(x0,(y0 + y1) / 2);
path.lineTo(x0 + arrow,y1);
path.lineTo(x1,y1);
path.lineTo(x1,y0);
}
path.closePath();
shapeRec=path;
}
if (printThisRow) {
Color ycColor=samRecord2color.apply(rec);
final Stroke oldStroke=g.getStroke();
g.setStroke(new BasicStroke(2f));
if (noReadGradient) {
if (ycColor == null) ycColor=new Color(255,222,173);
g.setColor(ycColor);
g.fill(shapeRec);
}
 else {
if (ycColor == null) ycColor=Color.DARK_GRAY;
final Paint oldpaint=g.getPaint();
final LinearGradientPaint gradient=new LinearGradientPaint(0f,(float)shapeRec.getBounds2D().getY(),0f,(float)shapeRec.getBounds2D().getMaxY(),new float[]{0f,0.5f,1f},new Color[]{ycColor,Color.WHITE,ycColor});
g.setPaint(gradient);
g.fill(shapeRec);
g.setPaint(oldpaint);
}
g.setColor(Bam2Raster.this.strokeColorizer.getColor(rec));
g.draw(shapeRec);
g.setStroke(oldStroke);
}
final Shape oldClip=g.getClip();
g.setClip(shapeRec);
final Cigar cigar=rec.getCigar();
if (cigar != null) {
final Function<Integer,Character> readBaseAt=IDX -> {
final byte bases[]=rec.getReadBases();
if (SAMRecord.NULL_SEQUENCE.equals(bases)) return 'N';
if (IDX < 0 || IDX >= bases.length) return 'N';
return (char)bases[IDX];
}
;
final Function<Integer,Character> readNameAt=readpos -> {
char c1;
if (readpos < rec.getReadName().length()) {
c1=rec.getReadName().charAt(readpos);
c1=rec.getReadNegativeStrandFlag() ? Character.toLowerCase(c1) : Character.toUpperCase(c1);
}
 else {
c1=' ';
}
return c1;
}
;
int refpos=rec.getUnclippedStart();
int readpos=0;
for (final CigarElement ce : cigar.getCigarElements()) {
switch (ce.getOperator()) {
case S:
case H:
{
  if (Bam2Raster.this.showClip) {
    g.setColor(Color.PINK);
    if (printThisRow)     g.fill(new Rectangle2D.Double(convertToX(refpos),y0,convertToX(refpos + ce.getLength()) - convertToX(refpos),y1 - y0));
    if (ce.getOperator().equals(CigarOperator.S)) {
      final double mutW=convertToX(refpos + 1) - convertToX(refpos);
      for (int i=0; i < ce.getLength(); ++i) {
        if (!inInterval.test(refpos + i))         continue;
        char c1=readBaseAt.apply(readpos + i);
        g.setColor(base2color.apply(c1));
        final Shape mut=new Rectangle2D.Double(convertToX(refpos + i),y0,mutW,y1 - y0);
        if (Bam2Raster.this.printName)         c1=readNameAt.apply(readpos + i);
        if (printThisRow)         Bam2Raster.this.hersheyFont.paint(g,String.valueOf(c1),mut);
      }
    }
  }
  refpos+=ce.getLength();
  if (ce.getOperator().equals(CigarOperator.S))   readpos+=ce.getLength();
  break;
}
case I:
{
refposOfInsertions.add(refpos);
readpos+=ce.getLength();
break;
}
case P:
break;
case D:
case N:
{
g.setColor(Color.ORANGE);
if (printThisRow) g.fill(new Rectangle2D.Double(convertToX(refpos),y0,convertToX(refpos + ce.getLength()) - convertToX(refpos),y1 - y0));
refpos+=ce.getLength();
break;
}
case EQ:
case X:
case M:
{
for (int i=0; i < ce.getLength(); ++i) {
boolean drawbase=!Bam2Raster.this.hideBases;
char c1=readBaseAt.apply(readpos);
Counter<Character> consensus=ref2consensus.get(refpos);
if (consensus == null) {
consensus=new Counter<Character>();
ref2consensus.put(refpos,consensus);
}
consensus.incr(Character.toUpperCase(c1));
char c2=genomicSequence.charAt(refpos - 1);
double mutW=convertToX(refpos + 1) - convertToX(refpos);
g.setColor(Color.BLACK);
final Shape mut=new Rectangle2D.Double(convertToX(refpos),y0,mutW,y1 - y0);
if (ce.getOperator() == CigarOperator.X || (c2 != 'N' && c2 != 'n' && Character.toUpperCase(c1) != Character.toUpperCase(c2))) {
drawbase=true;
g.setColor(Color.RED);
if (printThisRow) g.fill(mut);
g.setColor(Color.WHITE);
}
 else {
g.setColor(base2color.apply(c1));
}
if (Bam2Raster.this.printName) {
drawbase=true;
c1=readNameAt.apply(readpos);
}
if (!inInterval.test(refpos)) {
drawbase=false;
}
if (!printThisRow) {
drawbase=false;
}
if (drawbase) {
Bam2Raster.this.hersheyFont.paint(g,String.valueOf(c1),mut);
}
if (inInterval.test(refpos)) {
depth_array[refpos - Bam2Raster.this.interval.getStart()]++;
}
readpos++;
refpos++;
}
break;
}
default :
LOG.error("String_Node_Str" + ce.getOperator());
break;
}
}
}
for (final Integer refpos : refposOfInsertions) {
g.setColor(Color.GREEN);
if (printThisRow) g.fill(new Rectangle2D.Double(convertToX(refpos),y0,2,y1 - y0));
}
g.setClip(oldClip);
}
if (printThisRow) {
y+=refw + Bam2Raster.this.spaceYbetweenFeatures;
}
}
for (int x=Bam2Raster.this.interval.getStart(); x <= Bam2Raster.this.interval.getEnd(); ++x) {
Counter<Character> cons=ref2consensus.get(x);
if (cons == null || cons.getCountCategories() == 0) {
continue;
}
final double oneBaseWidth=(convertToX(x + 1) - convertToX(x)) - 1;
double x0=convertToX(x) + 1;
for (final Character c : cons.keySetDecreasing()) {
double weight=oneBaseWidth * (cons.count(c) / (double)cons.getTotal());
g.setColor(Color.BLACK);
if (genomicSequence != null && Character.toUpperCase(genomicSequence.charAt(x - 1)) != Character.toUpperCase(c)) {
g.setColor(Color.RED);
}
hersheyFont.paint(g,String.valueOf(c),x0,consensus_y,weight,oneBaseWidth - 2);
x0+=weight;
}
}
if (Bam2Raster.this.depthSize > 0) {
double minDepth=Arrays.stream(depth_array).min().orElse(0);
double maxDepth=Arrays.stream(depth_array).max().orElse(1);
if (minDepth == maxDepth) minDepth--;
for (int i=0; i < depth_array.length; ++i) {
final double d=depth_array[i];
final double h=((d - minDepth) / (maxDepth - minDepth)) * Bam2Raster.this.depthSize;
final Rectangle2D.Double rd=new Rectangle2D.Double();
rd.x=convertToX(interval.getStart() + i);
rd.y=depth_y + Bam2Raster.this.depthSize - h;
rd.width=refw;
rd.height=h;
g.setColor(d < 10 ? Color.RED : (d < 50 ? Color.BLUE : Color.GREEN));
g.fill(rd);
g.setColor(Color.BLACK);
g.draw(rd);
}
final String label="String_Node_Str" + (int)minDepth + "String_Node_Str"+ (int)maxDepth+ "String_Node_Str";
for (int x=0; x < 2; ++x) {
g.setColor(x == 0 ? Color.WHITE : Color.BLACK);
hersheyFont.paint(g,label,new Rectangle2D.Double(1 + x,depth_y + x + Bam2Raster.this.depthSize - refw,label.length() * refw,refw));
}
}
for (final Integer refpos : Bam2Raster.this.highlightPositions) {
g.setColor(Color.RED);
g.draw(new Rectangle2D.Double(convertToX(refpos),0,refw,this.image.getHeight()));
}
g.dispose();
}

Fixed version (ground truth):
private void build(){
  final Function<SAMRecord,Color> samRecord2color=new ColorUtils.SAMRecordColorExtractor();
  final Function<Character,Color> base2color=C -> {
switch (Character.toUpperCase(C)) {
case 'N':
      return Color.BLACK;
case 'A':
    return Color.RED;
case 'T':
  return Color.GREEN;
case 'G':
return Color.YELLOW;
case 'C':
return Color.BLUE;
default :
return Color.ORANGE;
}
}
;
final Predicate<Integer> inInterval=refPos -> !(refPos < Bam2Raster.this.interval.getStart() || refPos > Bam2Raster.this.interval.getEnd());
String positionFormat="String_Node_Str";
final int refw=(int)Math.max(1.0,WIDTH / (double)(1 + interval.getEnd() - interval.getStart()));
final int ruler_height=String.format(positionFormat,Bam2Raster.this.interval.getEnd()).length() * refw;
final Dimension imageSize=new Dimension(WIDTH,refw + Bam2Raster.this.spaceYbetweenFeatures + ruler_height+ Bam2Raster.this.spaceYbetweenFeatures+ refw+ Bam2Raster.this.spaceYbetweenFeatures+ refw+ Bam2Raster.this.spaceYbetweenFeatures+ (Math.max(0,Bam2Raster.this.depthSize))+ (Bam2Raster.this.depthSize > 0 ? Bam2Raster.this.spaceYbetweenFeatures : 0)+ (Bam2Raster.this.maxNumberOfRows < 0 ? this.rows.size() : Math.min(this.rows.size(),Bam2Raster.this.maxNumberOfRows)) * (Bam2Raster.this.spaceYbetweenFeatures + refw) + Bam2Raster.this.spaceYbetweenFeatures);
this.image=new BufferedImage(imageSize.width,imageSize.height,BufferedImage.TYPE_INT_RGB);
final CharSequence genomicSequence;
if (Bam2Raster.this.indexedFastaSequenceFile != null) {
genomicSequence=new GenomicSequence(Bam2Raster.this.indexedFastaSequenceFile,Bam2Raster.this.interval.getContig());
}
 else {
genomicSequence=new AbstractCharSequence(){
@Override public int length(){
return interval.getEnd() + 10;
}
@Override public char charAt(int index){
return 'N';
}
}
;
}
final Graphics2D g=this.image.createGraphics();
g.setColor(Color.WHITE);
g.fillRect(0,0,imageSize.width,imageSize.height);
LOG.info("String_Node_Str" + imageSize.width + "String_Node_Str"+ imageSize.height);
Map<Integer,Counter<Character>> ref2consensus=new HashMap<Integer,Counter<Character>>();
for (final Integer refpos : Bam2Raster.this.highlightPositions) {
g.setColor(new Color(255,235,246));
g.fill(new Rectangle2D.Double(convertToX(refpos),0,refw,this.image.getHeight()));
}
int y=0;
{
String title=interval.getContig() + "String_Node_Str" + this.key;
g.setColor(Color.BLACK);
hersheyFont.paint(g,title,new Rectangle2D.Double(1,1,title.length() * refw,refw));
y+=refw + Bam2Raster.this.spaceYbetweenFeatures;
}
for (int x=Bam2Raster.this.interval.getStart(); x <= Bam2Raster.this.interval.getEnd(); ++x) {
final double oneBaseWidth=convertToX(x + 1) - convertToX(x);
g.setColor(x % 10 == 0 ? Color.BLACK : Color.LIGHT_GRAY);
g.draw(new Line2D.Double(convertToX(x),0,convertToX(x),imageSize.height));
if ((x - Bam2Raster.this.interval.getStart()) % 10 == 0) {
g.setColor(Color.BLACK);
final String xStr=String.format(positionFormat,x);
final AffineTransform tr=g.getTransform();
final AffineTransform tr2=new AffineTransform(tr);
tr2.translate(convertToX(x + 1),y);
tr2.rotate(Math.PI / 2.0);
g.setTransform(tr2);
hersheyFont.paint(g,xStr,0,0,ruler_height,oneBaseWidth);
g.setTransform(tr);
}
}
y+=ruler_height + Bam2Raster.this.spaceYbetweenFeatures;
for (int x=Bam2Raster.this.interval.getStart(); x <= Bam2Raster.this.interval.getEnd(); ++x) {
final double oneBaseWidth=convertToX(x + 1) - convertToX(x);
final char c=x < 1 || x > genomicSequence.length() ? 'N' : genomicSequence.charAt(x - 1);
g.setColor(base2color.apply(c));
Bam2Raster.this.hersheyFont.paint(g,String.valueOf(c),convertToX(x) + 1,y,oneBaseWidth - 2,oneBaseWidth - 2);
}
y+=refw + Bam2Raster.this.spaceYbetweenFeatures;
final int consensus_y=y;
y+=refw + Bam2Raster.this.spaceYbetweenFeatures;
final int depth_y=y;
final int depth_array[]=new int[1 + (interval.getEnd() - interval.getStart())];
if (depthSize > 0) {
Arrays.fill(depth_array,0);
y+=depthSize + Bam2Raster.this.spaceYbetweenFeatures;
}
for (int rowIndex=0; rowIndex < rows.size(); ++rowIndex) {
final List<SAMRecord> row=rows.get(rowIndex);
boolean printThisRow=(Bam2Raster.this.maxNumberOfRows < 0 || rowIndex < Bam2Raster.this.maxNumberOfRows);
for (final SAMRecord rec : row) {
final Set<Integer> refposOfInsertions=new HashSet<>();
double x0=left2pixel(rec);
double x1=right2pixel(rec);
double y0=y;
double y1=y0 + refw;
Shape shapeRec=null;
if (x1 - x0 < Bam2Raster.this.minArrowWidth) {
shapeRec=new Rectangle2D.Double(x0,y0,x1 - x0,y1 - y0);
}
 else {
final GeneralPath path=new GeneralPath();
double arrow=Math.max(Bam2Raster.this.minArrowWidth,Math.min(Bam2Raster.this.maxArrowWidth,x1 - x0));
if (!rec.getReadNegativeStrandFlag()) {
path.moveTo(x0,y0);
path.lineTo(x1 - arrow,y0);
path.lineTo(x1,(y0 + y1) / 2);
path.lineTo(x1 - arrow,y1);
path.lineTo(x0,y1);
}
 else {
path.moveTo(x0 + arrow,y0);
path.lineTo(x0,(y0 + y1) / 2);
path.lineTo(x0 + arrow,y1);
path.lineTo(x1,y1);
path.lineTo(x1,y0);
}
path.closePath();
shapeRec=path;
}
if (printThisRow) {
Color ycColor=samRecord2color.apply(rec);
final Stroke oldStroke=g.getStroke();
g.setStroke(new BasicStroke(2f));
if (noReadGradient) {
if (ycColor == null) ycColor=new Color(255,222,173);
g.setColor(ycColor);
g.fill(shapeRec);
}
 else {
if (ycColor == null) ycColor=Color.DARK_GRAY;
final Paint oldpaint=g.getPaint();
final LinearGradientPaint gradient=new LinearGradientPaint(0f,(float)shapeRec.getBounds2D().getY(),0f,(float)shapeRec.getBounds2D().getMaxY(),new float[]{0f,0.5f,1f},new Color[]{ycColor,Color.WHITE,ycColor});
g.setPaint(gradient);
g.fill(shapeRec);
g.setPaint(oldpaint);
}
g.setColor(Bam2Raster.this.strokeColorizer.getColor(rec));
g.draw(shapeRec);
g.setStroke(oldStroke);
}
final Shape oldClip=g.getClip();
g.setClip(shapeRec);
final Cigar cigar=rec.getCigar();
if (cigar != null) {
final Function<Integer,Character> readBaseAt=IDX -> {
final byte bases[]=rec.getReadBases();
if (SAMRecord.NULL_SEQUENCE.equals(bases)) return 'N';
if (IDX < 0 || IDX >= bases.length) return 'N';
return (char)bases[IDX];
}
;
final Function<Integer,Character> readNameAt=readpos -> {
char c1;
if (readpos < rec.getReadName().length()) {
c1=rec.getReadName().charAt(readpos);
c1=rec.getReadNegativeStrandFlag() ? Character.toLowerCase(c1) : Character.toUpperCase(c1);
}
 else {
c1=' ';
}
return c1;
}
;
int refpos=rec.getUnclippedStart();
int readpos=0;
for (final CigarElement ce : cigar.getCigarElements()) {
switch (ce.getOperator()) {
case S:
case H:
{
  if (Bam2Raster.this.showClip) {
    g.setColor(Color.PINK);
    if (printThisRow)     g.fill(new Rectangle2D.Double(convertToX(refpos),y0,convertToX(refpos + ce.getLength()) - convertToX(refpos),y1 - y0));
    if (ce.getOperator().equals(CigarOperator.S)) {
      final double mutW=convertToX(refpos + 1) - convertToX(refpos);
      for (int i=0; i < ce.getLength(); ++i) {
        if (!inInterval.test(refpos + i))         continue;
        char c1=readBaseAt.apply(readpos + i);
        g.setColor(base2color.apply(c1));
        final Shape mut=new Rectangle2D.Double(convertToX(refpos + i),y0,mutW,y1 - y0);
        if (Bam2Raster.this.printName)         c1=readNameAt.apply(readpos + i);
        if (printThisRow)         Bam2Raster.this.hersheyFont.paint(g,String.valueOf(c1),mut);
      }
    }
  }
  refpos+=ce.getLength();
  if (ce.getOperator().equals(CigarOperator.S))   readpos+=ce.getLength();
  break;
}
case I:
{
refposOfInsertions.add(refpos);
readpos+=ce.getLength();
break;
}
case P:
break;
case D:
case N:
{
g.setColor(Color.ORANGE);
if (printThisRow) g.fill(new Rectangle2D.Double(convertToX(refpos),y0,convertToX(refpos + ce.getLength()) - convertToX(refpos),y1 - y0));
refpos+=ce.getLength();
break;
}
case EQ:
case X:
case M:
{
for (int i=0; i < ce.getLength(); ++i) {
boolean drawbase=!Bam2Raster.this.hideBases;
char c1=readBaseAt.apply(readpos);
Counter<Character> consensus=ref2consensus.get(refpos);
if (consensus == null) {
consensus=new Counter<Character>();
ref2consensus.put(refpos,consensus);
}
consensus.incr(Character.toUpperCase(c1));
char c2=genomicSequence.charAt(refpos - 1);
double mutW=convertToX(refpos + 1) - convertToX(refpos);
g.setColor(Color.BLACK);
final Shape mut=new Rectangle2D.Double(convertToX(refpos),y0,mutW,y1 - y0);
if (ce.getOperator() == CigarOperator.X || (c2 != 'N' && c2 != 'n' && Character.toUpperCase(c1) != Character.toUpperCase(c2))) {
drawbase=true;
g.setColor(Color.RED);
if (printThisRow) g.fill(mut);
g.setColor(Color.WHITE);
}
 else {
g.setColor(base2color.apply(c1));
}
if (Bam2Raster.this.printName) {
drawbase=true;
c1=readNameAt.apply(readpos);
}
if (!inInterval.test(refpos)) {
drawbase=false;
}
if (!printThisRow) {
drawbase=false;
}
if (drawbase) {
Bam2Raster.this.hersheyFont.paint(g,String.valueOf(c1),mut);
}
if (inInterval.test(refpos)) {
depth_array[refpos - Bam2Raster.this.interval.getStart()]++;
}
readpos++;
refpos++;
}
break;
}
default :
LOG.error("String_Node_Str" + ce.getOperator());
break;
}
}
}
for (final Integer refpos : refposOfInsertions) {
g.setColor(Color.GREEN);
if (printThisRow) g.fill(new Rectangle2D.Double(convertToX(refpos),y0,2,y1 - y0));
}
g.setClip(oldClip);
}
if (printThisRow) {
y+=refw + Bam2Raster.this.spaceYbetweenFeatures;
}
}
for (int x=Bam2Raster.this.interval.getStart(); x <= Bam2Raster.this.interval.getEnd(); ++x) {
Counter<Character> cons=ref2consensus.get(x);
if (cons == null || cons.getCountCategories() == 0) {
continue;
}
final double oneBaseWidth=(convertToX(x + 1) - convertToX(x)) - 1;
double x0=convertToX(x) + 1;
for (final Character c : cons.keySetDecreasing()) {
double weight=oneBaseWidth * (cons.count(c) / (double)cons.getTotal());
g.setColor(Color.BLACK);
if (genomicSequence != null && Character.toUpperCase(genomicSequence.charAt(x - 1)) != Character.toUpperCase(c)) {
g.setColor(Color.RED);
}
hersheyFont.paint(g,String.valueOf(c),x0,consensus_y,weight,oneBaseWidth - 2);
x0+=weight;
}
}
if (Bam2Raster.this.depthSize > 0) {
double minDepth=Arrays.stream(depth_array).min().orElse(0);
double maxDepth=Arrays.stream(depth_array).max().orElse(1);
if (minDepth == maxDepth) minDepth--;
for (int i=0; i < depth_array.length; ++i) {
final double d=depth_array[i];
final double h=((d - minDepth) / (maxDepth - minDepth)) * Bam2Raster.this.depthSize;
final Rectangle2D.Double rd=new Rectangle2D.Double();
rd.x=convertToX(interval.getStart() + i);
rd.y=depth_y + Bam2Raster.this.depthSize - h;
rd.width=refw;
rd.height=h;
g.setColor(d < 10 ? Color.RED : (d < 50 ? Color.BLUE : Color.GREEN));
g.fill(rd);
g.setColor(Color.BLACK);
g.draw(rd);
}
final String label="String_Node_Str" + (int)minDepth + "String_Node_Str"+ (int)maxDepth+ "String_Node_Str";
for (int x=0; x < 2; ++x) {
g.setColor(x == 0 ? Color.WHITE : Color.BLACK);
hersheyFont.paint(g,label,new Rectangle2D.Double(1 + x,depth_y + x + Bam2Raster.this.depthSize - refw,label.length() * refw,refw));
}
}
for (final Integer refpos : Bam2Raster.this.highlightPositions) {
g.setColor(Color.RED);
g.draw(new Rectangle2D.Double(convertToX(refpos),0,refw,this.image.getHeight()));
}
g.dispose();
}