import jalview.datamodel.Annotation;
import jalview.datamodel.ColumnSelection;
import jalview.datamodel.ProfilesI;
+import jalview.renderer.api.AnnotationRendererFactoryI;
+import jalview.renderer.api.AnnotationRowRendererI;
import jalview.schemes.ColourSchemeI;
import jalview.schemes.ResidueProperties;
import jalview.util.Platform;
hStrucConsensus = null;
fadedImage = null;
annotationPanel = null;
+ rendererFactoryI = null;
}
void drawStemAnnot(Graphics g, Annotation[] row_annotations, int lastSSX,
boolean rna = false;
+ private AnnotationRendererFactoryI rendererFactoryI;
+
/**
* Render the annotation rows associated with an alignment.
*
}
else if (row.graph == AlignmentAnnotation.BAR_GRAPH)
{
- if (row.autoCalculated && row.label != null
- && row.label.startsWith("Consen"))
- {
- drawProfileDensity(g, row, row_annotations, startRes, endRes,
- row.graphMin, row.graphMax, y);
- }
- else
- {
drawBarGraph(g, row, row_annotations, startRes, endRes,
row.graphMin, row.graphMax, y, renderHistogram,
renderProfile, normaliseProfile);
+ }
+ else
+ {
+ AnnotationRowRendererI renderer = rendererFactoryI
+ .getRendererFor(row);
+ if (renderer != null)
+ {
+ renderer.renderRow(g, charWidth, charHeight,
+ hasHiddenColumns, av, columnSelection, row,
+ row_annotations, startRes, endRes, row.graphMin,
+ row.graphMax, y);
+ System.err.println("rendered with "
+ + renderer.getClass().toString());
}
}
}
}
}
-
- void drawProfileDensity(Graphics g, AlignmentAnnotation _aa,
- Annotation[] aa_annotations, int sRes, int eRes, float min,
- float max, int y)
- {
- if (sRes > aa_annotations.length)
- {
- return;
- }
- Font ofont = g.getFont();
- 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;
- }
- if (aa_annotations[column].colour == null)
- {
- g.setColor(Color.black);
- }
- else
- {
- g.setColor(aa_annotations[column].colour);
- }
-
-
- /*
- * {profile type, #values, total count, char1, pct1, char2, pct2...}
- */
- int profl[] = getProfileFor(_aa, column);
-
- // just try to draw the logo if profl is not null
- if (profl != null && profl[2] != 0)
- {
- boolean isStructureProfile = profl[0] == AlignmentAnnotation.STRUCTURE_PROFILE;
- boolean isCdnaProfile = profl[0] == AlignmentAnnotation.CDNA_PROFILE;
- float ht = y2; // - _aa.graphHeight;
- char[] dc;
-
- /**
- * Render a single base for a sequence profile, a base pair for
- * structure profile, and a triplet for a cdna profile
- */
- dc = new char[isStructureProfile ? 2 : (isCdnaProfile ? 3 : 1)];
-
- double scale = _aa.graphHeight / (profl[1]);
-
- /*
- * Traverse the character(s)/percentage data in the array
- */
- int c = 3;
- int valuesProcessed = 0;
- // profl[1] is the number of values in the profile
-
- while (valuesProcessed < profl[1])
- {
- if (isStructureProfile)
- {
- // todo can we encode a structure pair as an int, like codons?
- dc[0] = (char) profl[c++];
- dc[1] = (char) profl[c++];
- }
- else if (isCdnaProfile)
- {
- dc = CodingUtils.decodeCodon(profl[c++]);
- }
- else
- {
- dc[0] = (char) profl[c++];
- }
-
- ht -= scale;
- // next profl[] position is profile % for the character(s)
- // render boxes
- g.setColor(jalview.util.ColorUtils.getGraduatedColour(profl[c++],
- 0f, Color.gray, 100, Color.blue));
- // g.setColor(profcolour.findColour(dc[0]).darker());
-
- g.fillRect(x * charWidth, (int) ht, charWidth, (int) scale);
- valuesProcessed++;
- }
- g.setFont(ofont);
- }
- x++;
-
- }
-
- // if (_aa.threshold != null)
- // {
- // g.setColor(_aa.threshold.colour);
- // Graphics2D g2 = (Graphics2D) g;
- // g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE,
- // BasicStroke.JOIN_ROUND, 3f, new float[] { 5f, 3f }, 0f));
- //
- // y2 = (int) (y - ((_aa.threshold.value - min) / range)
- // * _aa.graphHeight);
- // g.drawLine(0, y2, (eRes - sRes) * charWidth, y2);
- // g2.setStroke(new BasicStroke());
- // }
- }
-
}
--- /dev/null
+/**
+ *
+ */
+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.Font;
+import java.awt.Graphics;
+
+/**
+ * @author jprocter
+ *
+ */
+public class ContactMapRenderer implements AnnotationRowRendererI
+{
+ /*
+ *
+ * // TODO Auto-generated method stub
+ void drawProfileDensity(Graphics g, AlignmentAnnotation _aa,
+ Annotation[] aa_annotations, int sRes, int eRes, float min,
+ float max, int y)
+ {
+
+ *
+ *
+ */
+ @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;
+ }
+ Font ofont = g.getFont();
+ 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;
+ }
+
+
+ int scale = Math
+ .max(1, _aa.graphHeight / contacts.getContactHeight());
+ int step = _aa.graphHeight / scale;
+ int valuesProcessed = 0;
+ // 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++)
+ {
+ valuesProcessed = stp * step;
+ g.setColor(contacts.getColorForScore(stp * step));
+
+ if (scale > 1)
+ {
+ g.fillRect(x * charWidth, ht, charWidth, scale);
+ } else {
+ g.drawLine(x * charWidth, ht, (x + 1) * charWidth, ht);
+ }
+ }
+ }
+ x++;
+
+ }
+}