From: kiramt Date: Tue, 3 Oct 2017 13:50:39 +0000 (+0100) Subject: JAL-2674 testing X-Git-Tag: Release_2_10_4~55^2~1^2~90 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=8213e48c6973494f7a6e22e1a97290520a461d1b;p=jalview.git JAL-2674 testing --- diff --git a/src/jalview/analysis/Dna.java b/src/jalview/analysis/Dna.java index a6fe541..d534c8f 100644 --- a/src/jalview/analysis/Dna.java +++ b/src/jalview/analysis/Dna.java @@ -71,6 +71,10 @@ public class Dna private final AlignmentI dataset; + private ShiftList vismapping; + + private int[] startcontigs; + /* * Working variables for the translation. * @@ -101,6 +105,45 @@ public class Dna this.annotations = viewport.getAlignment().getAlignmentAnnotation(); this.dnaWidth = viewport.getAlignment().getWidth(); this.dataset = viewport.getAlignment().getDataset(); + initContigs(); + } + + /** + * Initialise contigs used as starting point for translateCodingRegion + */ + private void initContigs() + { + vismapping = new ShiftList(); // map from viscontigs to seqstring + // intervals + + int npos = 0; + int[] lastregion = null; + ArrayList tempcontigs = new ArrayList<>(); + while (contigs.hasNext()) + { + int[] region = contigs.next(); + if (lastregion == null) + { + vismapping.addShift(npos, region[0]); + } + else + { + // hidden region + vismapping.addShift(npos, region[0] - lastregion[1] + 1); + } + lastregion = region; + tempcontigs.add(region[0]); + tempcontigs.add(region[1]); + } + + startcontigs = new int[tempcontigs.size()]; + int i = 0; + for (Integer val : tempcontigs) + { + startcontigs[i] = val; + i++; + } + tempcontigs = null; } /** @@ -393,38 +436,12 @@ public class Dna List proteinSeqs) { List skip = new ArrayList<>(); - int skipint[] = null; - ShiftList vismapping = new ShiftList(); // map from viscontigs to seqstring - // intervals - int vc = 0; - + int[] skipint = null; int npos = 0; - int[] lastregion = null; - while (contigs.hasNext()) - { - int[] region = contigs.next(); - if (lastregion == null) - { - vismapping.addShift(npos, region[0]); - } - else - { - // hidden region - vismapping.addShift(npos, region[0] - lastregion[1] + 1); - } - lastregion = region; - vc++; - } + int vc = 0; - int[] scontigs = new int[vc]; - vc = 0; - while (contigs.hasNext()) - { - int[] region = contigs.next(); - scontigs[vc] = region[0]; - scontigs[vc + 1] = region[1]; - vc++; - } + int[] scontigs = new int[startcontigs.length]; + System.arraycopy(startcontigs, 0, scontigs, 0, startcontigs.length); // allocate a roughly sized buffer for the protein sequence StringBuilder protein = new StringBuilder(seqstring.length() / 2); diff --git a/src/jalview/appletgui/SeqCanvas.java b/src/jalview/appletgui/SeqCanvas.java index 2a66fd8..b499a74 100755 --- a/src/jalview/appletgui/SeqCanvas.java +++ b/src/jalview/appletgui/SeqCanvas.java @@ -561,8 +561,8 @@ public class SeqCanvas extends Panel implements ViewportListenerI else { int screenY = 0; - int blockStart = startRes; - int blockEnd = endRes; + int blockStart; + int blockEnd; HiddenColumns hidden = av.getAlignment().getHiddenColumns(); VisibleBlocksVisBoundsIterator regions = (VisibleBlocksVisBoundsIterator) hidden diff --git a/src/jalview/datamodel/HiddenColumns.java b/src/jalview/datamodel/HiddenColumns.java index f8a7f0c..839cee2 100644 --- a/src/jalview/datamodel/HiddenColumns.java +++ b/src/jalview/datamodel/HiddenColumns.java @@ -1641,14 +1641,14 @@ public class HiddenColumns private List localHidden = new ArrayList<>(); - private int lasthiddenregion; + private int nexthiddenregion; VisibleColsIterator(int firstcol, int lastcol, boolean useCopy) { last = lastcol; current = firstcol; next = firstcol; - lasthiddenregion = -1; + nexthiddenregion = 0; try { @@ -1663,7 +1663,7 @@ public class HiddenColumns { int i = 0; for (i = 0; i < hiddenColumns.size() - && (current < hiddenColumns.get(i)[0]); ++i) + && (current <= hiddenColumns.get(i)[0]); ++i) { if (current >= hiddenColumns.get(i)[0] && current <= hiddenColumns.get(i)[1]) @@ -1671,13 +1671,12 @@ public class HiddenColumns // current is hidden, move to right current = hiddenColumns.get(i)[1] + 1; next = current; + nexthiddenregion = i + 1; } } - lasthiddenregion = i - 1; - for (i = hiddenColumns.size() - 1; i >= 0 - && (last > hiddenColumns.get(i)[1]); --i) + && (last >= hiddenColumns.get(i)[1]); --i) { if (last >= hiddenColumns.get(i)[0] && last <= hiddenColumns.get(i)[1]) @@ -1688,7 +1687,7 @@ public class HiddenColumns } // make a local copy of the bit we need - i = lasthiddenregion + 1; + i = nexthiddenregion; while (i < hiddenColumns.size() && hiddenColumns.get(i)[0] <= last) { @@ -1697,7 +1696,6 @@ public class HiddenColumns localHidden.add(region); i++; } - lasthiddenregion = -1; } } finally { @@ -1723,20 +1721,20 @@ public class HiddenColumns } current = next; if ((localHidden != null) - && (lasthiddenregion + 1 < localHidden.size())) + && (nexthiddenregion < localHidden.size())) { // still some more hidden regions - if (next + 1 < localHidden.get(lasthiddenregion + 1)[0]) + if (next + 1 < localHidden.get(nexthiddenregion)[0]) { // next+1 is still before the next hidden region next++; } - else if ((next + 1 >= localHidden.get(lasthiddenregion + 1)[0]) - && (next + 1 <= localHidden.get(lasthiddenregion + 1)[1])) + else if ((next + 1 >= localHidden.get(nexthiddenregion)[0]) + && (next + 1 <= localHidden.get(nexthiddenregion)[1])) { // next + 1 is in the next hidden region - next = localHidden.get(lasthiddenregion + 1)[1] + 1; - lasthiddenregion++; + next = localHidden.get(nexthiddenregion)[1] + 1; + nexthiddenregion++; } } else @@ -1949,7 +1947,6 @@ public class HiddenColumns int blockEnd = end; int hiddenSoFar = 0; int visSoFar = 0; - int maxVisible = end - start; endsAtHidden = false; // iterate until a region begins within (start,end] @@ -1985,9 +1982,9 @@ public class HiddenColumns i++; } - if (visSoFar < maxVisible) + if (visSoFar < end - start) { - blockEnd = blockStart + maxVisible - visSoFar; + blockEnd = blockStart + end - start - visSoFar; int[] contig = new int[] { blockStart, blockEnd }; vcontigs.add(contig); diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index 82e4481..f72acae 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -852,8 +852,8 @@ public class SeqCanvas extends JComponent implements ViewportListenerI else { int screenY = 0; - int blockStart = startRes; - int blockEnd = endRes; + int blockStart; + int blockEnd; HiddenColumns hidden = av.getAlignment().getHiddenColumns(); VisibleBlocksVisBoundsIterator regions = (VisibleBlocksVisBoundsIterator) hidden @@ -1100,8 +1100,8 @@ public class SeqCanvas extends JComponent implements ViewportListenerI { // package into blocks of visible columns int screenY = 0; - int blockStart = startRes; - int blockEnd = endRes; + int blockStart; + int blockEnd; HiddenColumns hidden = av.getAlignment().getHiddenColumns(); VisibleBlocksVisBoundsIterator regions = (VisibleBlocksVisBoundsIterator) hidden diff --git a/test/jalview/datamodel/VisibleColsIteratorTest.java b/test/jalview/datamodel/VisibleColsIteratorTest.java index 92d39be..f9b01bd 100644 --- a/test/jalview/datamodel/VisibleColsIteratorTest.java +++ b/test/jalview/datamodel/VisibleColsIteratorTest.java @@ -55,7 +55,8 @@ public class VisibleColsIteratorTest int count = 0; while (it.hasNext()) { - it.next(); + int result = it.next(); + System.out.println(result); count++; } assertTrue(count == 4, "hasNext() is false after 4 iterations");