/** * */ package jalview.renderer; import jalview.api.AlignViewportI; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.Annotation; import jalview.datamodel.ColumnSelection; import jalview.datamodel.ContactListI; import jalview.renderer.api.AnnotationRowRendererI; import java.awt.Color; import java.awt.Graphics; /** * @author jprocter * */ public class ContactMapRenderer implements AnnotationRowRendererI { @Override public void renderRow(Graphics g, int charWidth, int charHeight, boolean hasHiddenColumns, AlignViewportI viewport, ColumnSelection columnSelection, AlignmentAnnotation _aa, Annotation[] aa_annotations, int sRes, int eRes, float min, float max, int y) { if (sRes > aa_annotations.length) { return; } eRes = Math.min(eRes, aa_annotations.length); int x = 0, y2 = y; g.setColor(Color.pink); g.drawLine(x, y2, (eRes - sRes) * charWidth, y2); int column; int aaMax = aa_annotations.length - 1; while (x < eRes - sRes) { column = sRes + x; if (hasHiddenColumns) { column = columnSelection.adjustForHiddenColumns(column); } if (column > aaMax) { break; } if (aa_annotations[column] == null) { x++; continue; } /* * {profile type, #values, total count, char1, pct1, char2, pct2...} */ ContactListI contacts = viewport.getContactList(_aa, column); if (contacts == null) { return; } // cell height to render double scale = (_aa.graphHeight < contacts.getContactHeight()) ? 1 : (((double) _aa.graphHeight) / (double) contacts .getContactHeight()); // distance between contact map per cell int step = (int) ((contacts.getContactHeight()) * scale / _aa.graphHeight); // profl[1] is the number of values in the profile for (int stp = 0, ht = y2, eht = y2 - _aa.graphHeight; ht > eht; ht -= scale, stp++) { g.setColor(contacts .getColorForScore((int) (stp * step * ((double) _aa.graphHeight / (double) contacts .getContactHeight())))); if (scale > 1) { g.fillRect(x * charWidth, ht, charWidth, 1 + (int) scale); } else { g.drawLine(x * charWidth, ht, (x + 1) * charWidth, ht); } } x++; } } }