4 package jalview.renderer;
7 import java.awt.Graphics;
9 import jalview.api.AlignViewportI;
10 import jalview.datamodel.AlignmentAnnotation;
11 import jalview.datamodel.Annotation;
12 import jalview.datamodel.ColumnSelection;
13 import jalview.datamodel.ContactListI;
14 import jalview.datamodel.ContactRange;
15 import jalview.datamodel.HiddenColumns;
16 import jalview.renderer.api.AnnotationRowRendererI;
22 public class ContactMapRenderer implements AnnotationRowRendererI
26 public void renderRow(Graphics g, int charWidth, int charHeight,
27 boolean hasHiddenColumns, AlignViewportI viewport,
28 HiddenColumns hiddenColumns, ColumnSelection columnSelection,
29 AlignmentAnnotation _aa, Annotation[] aa_annotations, int sRes,
30 int eRes, float min, float max, int y)
32 if (sRes > aa_annotations.length)
36 eRes = Math.min(eRes, aa_annotations.length);
40 g.setColor(Color.pink);
42 g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
45 int aaMax = aa_annotations.length - 1;
46 while (x < eRes - sRes)
51 column = hiddenColumns.visibleToAbsoluteColumn(column);
53 // TODO: highlight columns selected
54 boolean colsel = false;
55 if (columnSelection != null)
57 colsel = columnSelection.contains(column);
65 if (aa_annotations[column] == null)
70 if (_aa.sequenceRef != null)
72 // get the sequence position for the column
73 column = _aa.sequenceRef.findPosition(column) - 1;
75 ContactListI contacts = viewport.getContactList(_aa, column);
80 // Bean holding mapping from contact list to pixels
81 final ContactGeometry cgeom = new ContactGeometry(contacts,
84 for (int ht = y2, eht = y2
85 - _aa.graphHeight; ht >= eht; ht -= cgeom.pixels_step)
87 ContactGeometry.contactInterval ci = cgeom.mapFor(y2 - ht,
88 y2 - ht + cgeom.pixels_step);
89 // cstart = (int) Math.floor(((double) y2 - ht) * contacts_per_pixel);
90 // cend = (int) Math.min(contact_height,
91 // Math.ceil(cstart + contacts_per_pixel * pixels_step));
93 // TODO show maximum colour for range - sort of done
94 // also need a 'getMaxPosForRange(start,end)' to accurately render
96 boolean rowsel = false;
97 if (!colsel && columnSelection != null)
99 if (_aa.sequenceRef == null)
101 rowsel = columnSelection.intersects(ci.cStart, ci.cEnd);
105 // TODO check we have correctly mapped cstart to local sequence
107 int s = _aa.sequenceRef.findIndex(ci.cStart);
108 int e = _aa.sequenceRef.findIndex(ci.cEnd);
109 if (s > 0 && s < _aa.sequenceRef.getLength())
111 rowsel = columnSelection.intersects(s, e);
115 // TODO: show selected region
116 if (colsel || rowsel)
119 col = getSelectedColorForRange(min, max, contacts, ci.cStart,
125 col = getColorForRange(min, max, contacts, ci.cStart, ci.cEnd);
128 if (cgeom.pixels_step > 1)
130 g.fillRect(x * charWidth, ht, charWidth, 1 + cgeom.pixels_step);
134 g.drawLine(x * charWidth, ht, (x + 1) * charWidth, ht);
142 // Shading parameters
143 // currently hardwired for alphafold
144 Color maxColor = new Color(246, 252, 243),
145 minColor = new Color(0, 60, 26),
146 selMinColor = new Color(26, 0, 60),
147 selMaxColor = new Color(243, 246, 252);
149 Color shadeFor(float min, float max, float value)
151 return jalview.util.ColorUtils.getGraduatedColour(value, 0, minColor,
155 public Color getColorForRange(float min, float max, ContactListI cl,
158 ContactRange cr = cl.getRangeFor(i, j);
159 // average for moment - probably more interested in maxIntProj though
160 return shadeFor(min, max, (float) cr.getMean());
163 public Color getSelectedColorForRange(float min, float max,
164 ContactListI cl, int i, int j)
166 ContactRange cr = cl.getRangeFor(i, j);
167 // average for moment - probably more interested in maxIntProj though
168 return jalview.util.ColorUtils.getGraduatedColour((float) cr.getMean(),
169 0, selMinColor, max, selMaxColor);