X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2Ffeatures%2FFeatureStore.java;h=7651016f6283a390fe21934ae627a4ef750f7b93;hb=af259f508805faf2da90585ee9a67cd7853bf5aa;hp=13472139cb1534d5f7515f44014db3ff4aaf7b68;hpb=81d2ea57ab71c0806a036833f73711bc4ad5c76d;p=jalview.git diff --git a/src/jalview/datamodel/features/FeatureStore.java b/src/jalview/datamodel/features/FeatureStore.java index 1347213..7651016 100644 --- a/src/jalview/datamodel/features/FeatureStore.java +++ b/src/jalview/datamodel/features/FeatureStore.java @@ -20,8 +20,6 @@ */ package jalview.datamodel.features; -import jalview.datamodel.SequenceFeature; - import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; @@ -30,7 +28,9 @@ import java.util.Set; import intervalstore.api.IntervalStoreI; import intervalstore.impl.BinarySearcher; +import intervalstore.impl.BinarySearcher.Compare; import intervalstore.impl.IntervalStore; +import jalview.datamodel.SequenceFeature; /** * A data store for a set of sequence features that supports efficient lookup of @@ -277,7 +277,7 @@ public class FeatureStore * binary search the sorted list to find the insertion point */ int insertPosition = BinarySearcher.findFirst(contactFeatureStarts, - f -> f.getBegin() >= feature.getBegin()); + true, Compare.GE, feature.getBegin()); contactFeatureStarts.add(insertPosition, feature); @@ -286,7 +286,7 @@ public class FeatureStore * binary search the sorted list to find the insertion point */ insertPosition = BinarySearcher.findFirst(contactFeatureEnds, - f -> f.getEnd() >= feature.getEnd()); + false, Compare.GE, feature.getEnd()); contactFeatureEnds.add(insertPosition, feature); return true; @@ -314,8 +314,8 @@ public class FeatureStore */ // int pos = binarySearch(features, // SearchCriterion.byFeature(feature, RangeComparator.BY_START_POSITION)); - int pos = BinarySearcher.findFirst(features, - val -> val.getBegin() >= feature.getBegin()); + int pos = BinarySearcher.findFirst(features, true, Compare.GE, + feature.getBegin()); int len = features.size(); while (pos < len) { @@ -396,7 +396,7 @@ public class FeatureStore * whose end point is not before the target range */ int index = BinarySearcher.findFirst(contactFeatureEnds, - f -> f.getEnd() >= from); + false, Compare.GE, (int) from); while (index < contactFeatureEnds.size()) { @@ -449,7 +449,7 @@ public class FeatureStore List result) { int index = BinarySearcher.findFirst(contactFeatureStarts, - f -> f.getBegin() >= from); + true, Compare.GE, (int) from); while (index < contactFeatureStarts.size()) { @@ -812,13 +812,15 @@ public class FeatureStore } /** - * Adds the shift value to the start and end of all positional features. - * Returns true if at least one feature was updated, else false. + * Adds the shift amount to the start and end of all positional features whose + * start position is at or after fromPosition. Returns true if at least one + * feature was shifted, else false. * - * @param shift + * @param fromPosition + * @param shiftBy * @return */ - public synchronized boolean shiftFeatures(int shift) + public synchronized boolean shiftFeatures(int fromPosition, int shiftBy) { /* * Because begin and end are final fields (to ensure the data store's @@ -828,21 +830,24 @@ public class FeatureStore boolean modified = false; for (SequenceFeature sf : getPositionalFeatures()) { - modified = true; - int newBegin = sf.getBegin() + shift; - int newEnd = sf.getEnd() + shift; - - /* - * sanity check: don't shift left of the first residue - */ - if (newEnd > 0) + if (sf.getBegin() >= fromPosition) { - newBegin = Math.max(1, newBegin); - SequenceFeature sf2 = new SequenceFeature(sf, newBegin, newEnd, - sf.getFeatureGroup(), sf.getScore()); - addFeature(sf2); + modified = true; + int newBegin = sf.getBegin() + shiftBy; + int newEnd = sf.getEnd() + shiftBy; + + /* + * sanity check: don't shift left of the first residue + */ + if (newEnd > 0) + { + newBegin = Math.max(1, newBegin); + SequenceFeature sf2 = new SequenceFeature(sf, newBegin, newEnd, + sf.getFeatureGroup(), sf.getScore()); + addFeature(sf2); + } + delete(sf); } - delete(sf); } return modified; }