X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2Ffeatures%2FFeatureStore.java;h=eb5688c6b9ef303e19b3344b73ae858c1b7e55ef;hb=57738a1f3c19b1c3a00bd3ac5108f8cd0af32f99;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..eb5688c 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 @@ -182,18 +182,17 @@ public class FeatureStore { if (feature.isNonPositional()) { - return nonPositionalFeatures == null ? false : nonPositionalFeatures - .contains(feature); + return nonPositionalFeatures == null ? false + : nonPositionalFeatures.contains(feature); } if (feature.isContactFeature()) { - return contactFeatureStarts == null ? false : listContains( - contactFeatureStarts, feature); + return contactFeatureStarts == null ? false + : listContains(contactFeatureStarts, feature); } - return features == null ? false : features - .contains(feature); + return features == null ? false : features.contains(feature); } /** @@ -277,16 +276,15 @@ 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); - /* * insert into list sorted by end (second contact position): * binary search the sorted list to find the insertion point */ - insertPosition = BinarySearcher.findFirst(contactFeatureEnds, - f -> f.getEnd() >= feature.getEnd()); + insertPosition = BinarySearcher.findFirst(contactFeatureEnds, false, + Compare.GE, feature.getEnd()); contactFeatureEnds.add(insertPosition, feature); return true; @@ -314,8 +312,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) { @@ -395,16 +393,16 @@ public class FeatureStore * find the first contact feature (if any) * whose end point is not before the target range */ - int index = BinarySearcher.findFirst(contactFeatureEnds, - f -> f.getEnd() >= from); + int index = BinarySearcher.findFirst(contactFeatureEnds, false, + Compare.GE, (int) from); while (index < contactFeatureEnds.size()) { SequenceFeature sf = contactFeatureEnds.get(index); if (!sf.isContactFeature()) { - System.err.println("Error! non-contact feature type " - + sf.getType() + " in contact features list"); + System.err.println("Error! non-contact feature type " + sf.getType() + + " in contact features list"); index++; continue; } @@ -448,8 +446,8 @@ public class FeatureStore protected void findContactStartOverlaps(long from, long to, List result) { - int index = BinarySearcher.findFirst(contactFeatureStarts, - f -> f.getBegin() >= from); + int index = BinarySearcher.findFirst(contactFeatureStarts, true, + Compare.GE, (int) from); while (index < contactFeatureStarts.size()) { @@ -675,10 +673,9 @@ public class FeatureStore public boolean isEmpty() { boolean hasFeatures = (contactFeatureStarts != null - && !contactFeatureStarts - .isEmpty()) - || (nonPositionalFeatures != null && !nonPositionalFeatures - .isEmpty()) + && !contactFeatureStarts.isEmpty()) + || (nonPositionalFeatures != null + && !nonPositionalFeatures.isEmpty()) || (features != null && features.size() > 0); return !hasFeatures; @@ -700,9 +697,9 @@ public class FeatureStore } else { - return nonPositionalFeatureGroups == null ? Collections - . emptySet() : Collections - .unmodifiableSet(nonPositionalFeatureGroups); + return nonPositionalFeatureGroups == null + ? Collections. emptySet() + : Collections.unmodifiableSet(nonPositionalFeatureGroups); } } @@ -717,8 +714,8 @@ public class FeatureStore { if (!positional) { - return nonPositionalFeatures == null ? 0 : nonPositionalFeatures - .size(); + return nonPositionalFeatures == null ? 0 + : nonPositionalFeatures.size(); } int size = 0; @@ -802,8 +799,8 @@ public class FeatureStore for (SequenceFeature sf : sfs) { String featureGroup = sf.getFeatureGroup(); - if (group == null && featureGroup == null || group != null - && group.equals(featureGroup)) + if (group == null && featureGroup == null + || group != null && group.equals(featureGroup)) { result.add(sf); } @@ -812,13 +809,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 +827,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; }