4 package jalview.renderer;
7 import java.awt.Graphics;
8 import java.util.Iterator;
10 import jalview.api.AlignViewportI;
11 import jalview.datamodel.AlignmentAnnotation;
12 import jalview.datamodel.Annotation;
13 import jalview.datamodel.ColumnSelection;
14 import jalview.datamodel.ContactListI;
15 import jalview.datamodel.ContactRange;
16 import jalview.datamodel.HiddenColumns;
17 import jalview.renderer.api.AnnotationRowRendererI;
23 public class ContactMapRenderer implements AnnotationRowRendererI
27 public void renderRow(Graphics g, int charWidth, int charHeight,
28 boolean hasHiddenColumns, AlignViewportI viewport,
29 HiddenColumns hiddenColumns, ColumnSelection columnSelection,
30 AlignmentAnnotation _aa, Annotation[] aa_annotations, int sRes,
31 int eRes, float min, float max, int y)
33 if (sRes > aa_annotations.length)
37 eRes = Math.min(eRes, aa_annotations.length);
41 g.setColor(Color.pink);
43 g.drawLine(x, y2, (eRes - sRes) * charWidth, y2);
46 int aaMax = aa_annotations.length - 1;
47 while (x < eRes - sRes)
52 column = hiddenColumns.visibleToAbsoluteColumn(column);
54 // TODO: highlight columns selected
55 boolean colsel = false;
56 if (columnSelection != null)
58 colsel = columnSelection.contains(column);
66 if (aa_annotations[column] == null)
71 ContactListI contacts = viewport.getContactList(_aa, column);
77 // feature still in development - highlight or omit regions hidden in
78 // the alignment - currently marks them as red rows
79 boolean maskHiddenCols = false;
80 // TODO: pass visible column mask to the ContactGeometry object so it maps
81 // only visible contacts to geometry
82 // Bean holding mapping from contact list to pixels
83 final ContactGeometry cgeom = new ContactGeometry(contacts,
86 for (int ht = y2, eht = y2
87 - _aa.graphHeight; ht >= eht; ht -= cgeom.pixels_step)
89 ContactGeometry.contactInterval ci = cgeom.mapFor(y2 - ht,
90 y2 - ht + cgeom.pixels_step);
91 // cstart = (int) Math.floor(((double) y2 - ht) * contacts_per_pixel);
92 // cend = (int) Math.min(contact_height,
93 // Math.ceil(cstart + contacts_per_pixel * pixels_step));
96 boolean rowsel = false, containsHidden = false;
97 if (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 (maskHiddenCols && hasHiddenColumns)
111 // TODO: turn into function and create test !!
112 Iterator<int[]> viscont = hiddenColumns
113 .getVisContigsIterator(s, e, false);
114 containsHidden = !viscont.hasNext();
116 if (s > 0 && s < _aa.sequenceRef.getLength())
118 rowsel = columnSelection.intersects(s, e);
123 // TODO: show selected region
124 if (colsel || rowsel)
127 col = getSelectedColorForRange(min, max, contacts, ci.cStart,
129 if (colsel && rowsel)
131 col = new Color(col.getBlue(), col.getGreen(), col.getRed());
135 col = new Color(col.getBlue(), col.getBlue(), col.getBlue());
140 col = getColorForRange(min, max, contacts, ci.cStart, ci.cEnd);
147 if (cgeom.pixels_step > 1)
149 g.fillRect(x * charWidth, ht, charWidth, 1 + cgeom.pixels_step);
153 g.drawLine(x * charWidth, ht, (x + 1) * charWidth, ht);
161 // Shading parameters
162 // currently hardwired for alphafold
163 Color maxColor = new Color(246, 252, 243),
164 minColor = new Color(0, 60, 26),
165 selMinColor = new Color(26, 0, 60),
166 selMaxColor = new Color(243, 246, 252);
168 Color shadeFor(float min, float max, float value)
170 return jalview.util.ColorUtils.getGraduatedColour(value, 0, minColor,
174 public Color getColorForRange(float min, float max, ContactListI cl,
177 ContactRange cr = cl.getRangeFor(i, j);
178 // average for moment - probably more interested in maxIntProj though
179 return shadeFor(min, max, (float) cr.getMean());
182 public Color getSelectedColorForRange(float min, float max,
183 ContactListI cl, int i, int j)
185 ContactRange cr = cl.getRangeFor(i, j);
186 // average for moment - probably more interested in maxIntProj though
187 return jalview.util.ColorUtils.getGraduatedColour((float) cr.getMean(),
188 0, selMinColor, max, selMaxColor);