From: Jim Procter Date: Fri, 2 Dec 2016 11:35:54 +0000 (+0000) Subject: basic hack to get (almost) equal height density plot X-Git-Tag: Release_2_11_3_0~23^2~60^2~9^2~36 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=1f84a89eddaa39d8277b0d520c2cfd6356cff020;p=jalview.git basic hack to get (almost) equal height density plot --- diff --git a/src/jalview/renderer/AnnotationRenderer.java b/src/jalview/renderer/AnnotationRenderer.java index a0e530c..5083ac8 100644 --- a/src/jalview/renderer/AnnotationRenderer.java +++ b/src/jalview/renderer/AnnotationRenderer.java @@ -366,8 +366,7 @@ public class AnnotationRenderer } else { - return AAFrequency.extractProfile( -hconsensus.get(column), + return AAFrequency.extractProfile(hconsensus.get(column), av_ignoreGapsConsensus); } } @@ -1030,9 +1029,18 @@ hconsensus.get(column), } 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); + } } } } @@ -1619,4 +1627,129 @@ hconsensus.get(column), } } + + 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()); + // } + } + }