X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Frenderer%2FContactMapRenderer.java;h=58e6ab15002d8bce407c61a9677e4304b2f1d2d0;hb=c6b983048da1ba01c4edf75349de2d410b45356d;hp=11c51e9ccdee9ad08280ddb2a4dd4797e07ee9af;hpb=4441bd429663862f7746542dc94c2834884f31e3;p=jalview.git diff --git a/src/jalview/renderer/ContactMapRenderer.java b/src/jalview/renderer/ContactMapRenderer.java index 11c51e9..58e6ab1 100644 --- a/src/jalview/renderer/ContactMapRenderer.java +++ b/src/jalview/renderer/ContactMapRenderer.java @@ -50,12 +50,12 @@ public class ContactMapRenderer implements AnnotationRowRendererI { column = hiddenColumns.visibleToAbsoluteColumn(column); } - // // TODO: highlight columns selected - // boolean colsel = false; - // if (columnSelection != null) - // { - // colsel = columnSelection.contains(column); - // } + // TODO: highlight columns selected + boolean colsel = false; + if (columnSelection != null) + { + colsel = columnSelection.contains(column); + } if (column > aaMax) { @@ -67,61 +67,71 @@ public class ContactMapRenderer implements AnnotationRowRendererI x++; continue; } - if (_aa.sequenceRef != null) - { - // get the sequence position for the column - column = _aa.sequenceRef.findPosition(column) - 1; - } ContactListI contacts = viewport.getContactList(_aa, column); if (contacts == null) { - return; - } - int contact_height = contacts.getContactHeight(); - // fractional number of contacts covering each pixel - double contacts_per_pixel = ((double) contact_height) - / ((double) _aa.graphHeight); - - int pixels_step; - - if (contacts_per_pixel >= 1) - { - // many contacts rendered per pixel - pixels_step = 1; - } - else - { - // pixel height for each contact - pixels_step = (int) Math - .ceil(((double) _aa.graphHeight) / (double) contact_height); + x++; + continue; } + // Bean holding mapping from contact list to pixels + final ContactGeometry cgeom = new ContactGeometry(contacts, + _aa.graphHeight); - int cstart = 0, cend; - - for (int ht = y2, - eht = y2 - _aa.graphHeight; ht >= eht; ht -= pixels_step) + for (int ht = y2, eht = y2 + - _aa.graphHeight; ht >= eht; ht -= cgeom.pixels_step) { - cstart = (int) Math.floor(((double) y2 - ht) * contacts_per_pixel); - cend = (int) Math.min(contact_height, - Math.ceil(cstart + contacts_per_pixel * pixels_step)); + ContactGeometry.contactInterval ci = cgeom.mapFor(y2 - ht, + y2 - ht + cgeom.pixels_step); + // cstart = (int) Math.floor(((double) y2 - ht) * contacts_per_pixel); + // cend = (int) Math.min(contact_height, + // Math.ceil(cstart + contacts_per_pixel * pixels_step)); // TODO show maximum colour for range - sort of done // also need a 'getMaxPosForRange(start,end)' to accurately render - Color col = getColorForRange(min, max, contacts, cstart, cend); - + Color col; + boolean rowsel = false; + if (columnSelection != null) + { + if (_aa.sequenceRef == null) + { + rowsel = columnSelection.intersects(ci.cStart, ci.cEnd); + } + else + { + // TODO check we have correctly mapped cstart to local sequence + // numbering + int s = _aa.sequenceRef.findIndex(ci.cStart); + int e = _aa.sequenceRef.findIndex(ci.cEnd); + if (s > 0 && s < _aa.sequenceRef.getLength()) + { + rowsel = columnSelection.intersects(s, e); + } + } + } // TODO: show selected region - // if (colsel || columnSelection!=null && - // columnSelection.intersects(cstart,cend)) - // { - // g.setColor(col.brighter()); - // } - // else + if (colsel || rowsel) { + + col = getSelectedColorForRange(min, max, contacts, ci.cStart, + ci.cEnd); + if (colsel && rowsel) + { + col = new Color(col.getBlue(), col.getGreen(), col.getRed()); + } + else + { + col = new Color(col.getBlue(), col.getBlue(), col.getBlue()); + } g.setColor(col); } - if (pixels_step > 1) + else { - g.fillRect(x * charWidth, ht, charWidth, 1 + pixels_step); + col = getColorForRange(min, max, contacts, ci.cStart, ci.cEnd); + g.setColor(col); + } + if (cgeom.pixels_step > 1) + { + g.fillRect(x * charWidth, ht, charWidth, 1 + cgeom.pixels_step); } else { @@ -134,7 +144,11 @@ public class ContactMapRenderer implements AnnotationRowRendererI } // Shading parameters - Color minColor = Color.white, maxColor = Color.magenta; + // currently hardwired for alphafold + Color maxColor = new Color(246, 252, 243), + minColor = new Color(0, 60, 26), + selMinColor = new Color(26, 0, 60), + selMaxColor = new Color(243, 246, 252); Color shadeFor(float min, float max, float value) { @@ -150,4 +164,13 @@ public class ContactMapRenderer implements AnnotationRowRendererI return shadeFor(min, max, (float) cr.getMean()); } + public Color getSelectedColorForRange(float min, float max, + ContactListI cl, int i, int j) + { + ContactRange cr = cl.getRangeFor(i, j); + // average for moment - probably more interested in maxIntProj though + return jalview.util.ColorUtils.getGraduatedColour((float) cr.getMean(), + 0, selMinColor, max, selMaxColor); + } + }