X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Frenderer%2FScaleRenderer.java;h=dc3272ff84decd7d8a0a499230a2850cbe870d58;hb=d8720fc191cba996c440171ef8e07462ef9f7035;hp=d92608c2965f48b8f6a788d25e40a0fc22f35faa;hpb=af891ca5a64368cff67d242bbac4eda9dd43a42a;p=jalview.git diff --git a/src/jalview/renderer/ScaleRenderer.java b/src/jalview/renderer/ScaleRenderer.java index d92608c..dc3272f 100644 --- a/src/jalview/renderer/ScaleRenderer.java +++ b/src/jalview/renderer/ScaleRenderer.java @@ -21,9 +21,11 @@ package jalview.renderer; import jalview.api.AlignViewportI; +import jalview.datamodel.HiddenColumns; import jalview.datamodel.SequenceI; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; /** @@ -60,27 +62,19 @@ public class ScaleRenderer column = col; text = txt; } - - /** - * String representation for inspection when debugging only - */ - @Override - public String toString() - { - return String.format("%s:%d:%s", major ? "major" : "minor", column, - text); - } } /** - * Calculates position markers on the alignment ruler + * calculate positions markers on the alignment ruler * * @param av * @param startx - * left-most column in visible view (0..) + * left-most column in visible view * @param endx - * - right-most column in visible view (0..) - * @return + * - right-most column in visible view + * @return List of ScaleMark holding boolean: true/false for major/minor mark, + * marker position in alignment column coords, a String to be rendered + * at the position (or null) */ public List calculateMarks(AlignViewportI av, int startx, int endx) @@ -88,17 +82,27 @@ public class ScaleRenderer int scalestartx = (startx / 10) * 10; SequenceI refSeq = av.getAlignment().getSeqrep(); - int refSp = 0, refStartI = 0, refEndI = -1; + int refSp = 0; + int refStartI = 0; + int refEndI = -1; + + HiddenColumns hc = av.getAlignment().getHiddenColumns(); + if (refSeq != null) { - // find bounds and set origin appopriately - // locate first visible position for this sequence - int[] refbounds = av.getAlignment().getHiddenColumns() - .locateVisibleBoundsOfSequence(refSeq); + // find bounds and set origin appropriately + // locate first residue in sequence which is not hidden + Iterator it = hc.iterator(); + int index = refSeq.firstResidueOutsideIterator(it); + refSp = hc.absoluteToVisibleColumn(index); + + refStartI = refSeq.findIndex(refSeq.getStart()) - 1; + + int seqlength = refSeq.getLength(); + // get sequence position past the end of the sequence + int pastEndPos = refSeq.findPosition(seqlength + 1); + refEndI = refSeq.findIndex(pastEndPos - 1) - 1; - refSp = refbounds[0]; - refStartI = refbounds[4]; - refEndI = refbounds[5]; scalestartx = refSp + ((scalestartx - refSp) / 10) * 10; } @@ -106,41 +110,40 @@ public class ScaleRenderer { scalestartx += 5; } - List marks = new ArrayList(); + List marks = new ArrayList<>(); + String string; + int refN, iadj; // todo: add a 'reference origin column' to set column number relative to for (int i = scalestartx; i <= endx; i += 5) { if (((i - refSp) % 10) == 0) { - String text; if (refSeq == null) { - int iadj = av.getAlignment().getHiddenColumns() - .adjustForHiddenColumns(i - 1) + 1; - text = String.valueOf(iadj); + iadj = hc.visibleToAbsoluteColumn(i - 1) + 1; + string = String.valueOf(iadj); } else { - int iadj = av.getAlignment().getHiddenColumns() - .adjustForHiddenColumns(i - 1); - int refN = refSeq.findPosition(iadj); + iadj = hc.visibleToAbsoluteColumn(i - 1); + refN = refSeq.findPosition(iadj); // TODO show bounds if position is a gap // - ie L--R -> "1L|2R" for // marker if (iadj < refStartI) { - text = String.valueOf(iadj - refStartI); + string = String.valueOf(iadj - refStartI); } else if (iadj > refEndI) { - text = "+" + String.valueOf(iadj - refEndI); + string = "+" + String.valueOf(iadj - refEndI); } else { - text = String.valueOf(refN) + refSeq.getCharAt(iadj); + string = String.valueOf(refN) + refSeq.getCharAt(iadj); } } - marks.add(new ScaleMark(true, i - startx - 1, text)); + marks.add(new ScaleMark(true, i - startx - 1, string)); } else {