}
/**
+ * Add a contact feature to the lists that hold them ordered by start (first
+ * contact) and by end (second contact) position, ensuring the lists remain
+ * ordered, and returns true. This method allows duplicate features to be
+ * added, so test before calling to avoid this.
+ *
+ * @param feature
+ * @return
+ */
+ @Override
+ protected synchronized boolean addContactFeature(SequenceFeature feature)
+ {
+ if (contactFeatureStarts == null)
+ {
+ contactFeatureStarts = new ArrayList<>();
+ contactFeatureEnds = new ArrayList<>();
+ }
+
+ /*
+ * insert into list sorted by start (first contact position):
+ * binary search the sorted list to find the insertion point
+ */
+ int insertPosition = findFirstBeginStatic(contactFeatureStarts,
+ 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 = findFirstEndStatic(contactFeatureEnds,
+ feature.getEnd());
+ contactFeatureEnds.add(insertPosition, feature);
+
+ return true;
+ }
+
+ /**
* Adds contact features to the result list where either the second or the
* first contact position lies within the target range
*
* 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 = findFirstEndStatic(contactFeatureEnds, from);
int n = contactFeatureEnds.size();
while (index < n)
private void findContactStartOverlaps(long from, long to,
List<SequenceFeature> result)
{
- int index = BinarySearcher.findFirst(contactFeatureStarts,
- f -> f.getBegin() >= from);
+ int index = findFirstBegin(contactFeatureStarts, from);
while (index < contactFeatureStarts.size())
{
{
result.addAll(((IntervalStoreI<SequenceFeature>) features)
.findOverlaps(start, end));
- // TODO Auto-generated method stub
+ }
+
+ @Override
+ protected int findFirstBegin(List<SequenceFeature> list, long pos)
+ {
+ return findFirstBeginStatic(list, pos);
+ }
+ private static int findFirstBeginStatic(List<SequenceFeature> list,
+ long pos)
+ {
+ return BinarySearcher.findFirst(list, f -> f.getBegin() >= pos);
+ }
+
+ @Override
+ protected int findFirstEnd(List<SequenceFeature> list, long pos)
+ {
+ return findFirstEndStatic(list, pos);
+ }
+
+ private static int findFirstEndStatic(List<SequenceFeature> list,
+ long pos)
+ {
+ return BinarySearcher.findFirst(list, f -> f.getEnd() >= pos);
}
}