*/
package jalview.datamodel.features;
-import jalview.datamodel.SequenceFeature;
-
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
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
{
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);
}
/**
* 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;
*/
// 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)
{
* 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;
}
protected void findContactStartOverlaps(long from, long to,
List<SequenceFeature> result)
{
- int index = BinarySearcher.findFirst(contactFeatureStarts,
- f -> f.getBegin() >= from);
+ int index = BinarySearcher.findFirst(contactFeatureStarts, true,
+ Compare.GE, (int) from);
while (index < contactFeatureStarts.size())
{
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;
}
else
{
- return nonPositionalFeatureGroups == null ? Collections
- .<String> emptySet() : Collections
- .unmodifiableSet(nonPositionalFeatureGroups);
+ return nonPositionalFeatureGroups == null
+ ? Collections.<String> emptySet()
+ : Collections.unmodifiableSet(nonPositionalFeatureGroups);
}
}
{
if (!positional)
{
- return nonPositionalFeatures == null ? 0 : nonPositionalFeatures
- .size();
+ return nonPositionalFeatures == null ? 0
+ : nonPositionalFeatures.size();
}
int size = 0;
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);
}
}
/**
- * 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
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;
}