X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Futil%2FMappingUtils.java;fp=src%2Fjalview%2Futil%2FMappingUtils.java;h=d60d4eb58dc7043a551ba72d75f226e43167c6ad;hb=d043ce47fc710d3eb2629ba926a8a7417bd67d8c;hp=25cb810cf61228031d1d9e105cda92ee5a3c9e17;hpb=04c8f7bff663aa469127e9eed4164e02933782f1;p=jalview.git diff --git a/src/jalview/util/MappingUtils.java b/src/jalview/util/MappingUtils.java index 25cb810..d60d4eb 100644 --- a/src/jalview/util/MappingUtils.java +++ b/src/jalview/util/MappingUtils.java @@ -20,12 +20,6 @@ */ package jalview.util; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; import jalview.analysis.AlignmentSorter; import jalview.api.AlignViewportI; @@ -49,6 +43,12 @@ import jalview.datamodel.Sequence; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; /** * Helper methods for manipulations involving sequence mappings. * @@ -364,6 +364,7 @@ public final class MappingUtils */ int startResiduePos = selected.findPosition(firstUngappedPos); int endResiduePos = selected.findPosition(lastUngappedPos); + for (SequenceI seq : mapTo.getAlignment().getSequences()) { int mappedStartResidue = 0; @@ -530,7 +531,7 @@ public final class MappingUtils if (colsel == null) { - return; + return; // mappedColumns; } char fromGapChar = mapFrom.getAlignment().getGapCharacter(); @@ -552,9 +553,10 @@ public final class MappingUtils while (regions.hasNext()) { mapHiddenColumns(regions.next(), codonFrames, newHidden, - fromSequences, toSequences, fromGapChar); + fromSequences, + toSequences, fromGapChar); } - return; + return; // mappedColumns; } /** @@ -1026,6 +1028,60 @@ public final class MappingUtils } } } + /** + * Adds the given range to a list of ranges. If the new range just extends + * existing ranges, the current endpoint is updated instead. + * + * @param range + * @param addTo + */ + public static void addRange(int[] range, List addTo) + { + /* + * list is empty - add to it! + */ + if (addTo.size() == 0) + { + addTo.add(range); + return; + } + + int[] last = addTo.get(addTo.size() - 1); + boolean lastForward = last[1] >= last[0]; + boolean newForward = range[1] >= range[0]; + + /* + * contiguous range in the same direction - just update endpoint + */ + if (lastForward == newForward && last[1] == range[0]) + { + last[1] = range[1]; + return; + } + + /* + * next range starts at +1 in forward sense - update endpoint + */ + if (lastForward && newForward && range[0] == last[1] + 1) + { + last[1] = range[1]; + return; + } + + /* + * next range starts at -1 in reverse sense - update endpoint + */ + if (!lastForward && !newForward && range[0] == last[1] - 1) + { + last[1] = range[1]; + return; + } + + /* + * just add the new range + */ + addTo.add(range); + } /** * Converts a list of {@code start-end} ranges to a single array of