- /**
- * Returns a (possibly empty) list of features whose extent overlaps the given
- * range. The returned list is not ordered. Contact features are included if
- * either of the contact points lies within the range.
- *
- * @param start
- * start position of overlap range (inclusive)
- * @param end
- * end position of overlap range (inclusive)
- * @return
- */
- public List<SequenceFeature> findOverlappingFeatures(long start, long end)
- {
- List<SequenceFeature> result = new ArrayList<SequenceFeature>();
-
- findNonNestedFeatures(start, end, result);
-
- findContactFeatures(start, end, result);
-
- if (nestedFeatures != null)
- {
- result.addAll(nestedFeatures.findOverlaps(start, end));
- }
-
- return result;
- }
-
- /**
- * Adds contact features to the result list where either the second or the
- * first contact position lies within the target range
- *
- * @param from
- * @param to
- * @param result
- */
- protected void findContactFeatures(long from, long to,
- List<SequenceFeature> result)
- {
- if (contactFeatureStarts != null)
- {
- findContactStartFeatures(from, to, result);
- }
- if (contactFeatureEnds != null)
- {
- findContactEndFeatures(from, to, result);
- }
- }
-
- /**
- * Adds to the result list any contact features whose end (second contact
- * point), but not start (first contact point), lies in the query from-to
- * range
- *
- * @param from
- * @param to
- * @param result
- */
- protected void findContactEndFeatures(long from, long to,
- List<SequenceFeature> result)
- {
- /*
- * find the first contact feature (if any) that does not lie
- * entirely before the target range
- */
- int startPosition = binarySearch(contactFeatureEnds,
- SearchCriterion.byEnd(from));
- for (; startPosition < contactFeatureEnds.size(); startPosition++)
- {
- SequenceFeature sf = contactFeatureEnds.get(startPosition);
- if (!sf.isContactFeature())
- {
- System.err.println("Error! non-contact feature type "
- + sf.getType() + " in contact features list");
- continue;
- }
-
- int begin = sf.getBegin();
- if (begin >= from && begin <= to)
- {
- /*
- * this feature's first contact position lies in the search range
- * so we don't include it in results a second time
- */
- continue;
- }
-
- int end = sf.getEnd();
- if (end >= from && end <= to)
- {
- result.add(sf);
- }
- if (end > to)
- {
- break;
- }
- }
- }
-
- /**
- * Adds non-nested features to the result list that lie within the target
- * range. Non-positional features (start=end=0), contact features and nested
- * features are excluded.
- *
- * @param from
- * @param to
- * @param result
- */
- protected void findNonNestedFeatures(long from, long to,
- List<SequenceFeature> result)
- {
- int startIndex = binarySearch(nonNestedFeatures,
- SearchCriterion.byEnd(from));
-
- findNonNestedFeatures(startIndex, from, to, result);
- }