+ SequenceFeature sf = list.get(i);
+ if (sf.getBegin() >= fromPosition)
+ {
+ 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);
+ }
+ }
+ return modified;
+ }
+
+ /**
+ * Answers the position (0, 1...) in the list of the first entry whose end
+ * position is not less than {@ pos}. If no such entry is found, answers the
+ * length of the list.
+ *
+ * @param list
+ * @param pos
+ * @return
+ */
+ protected int findFirstEnd(List<SequenceFeature> list, long pos)
+ {
+ return BinarySearcher.findFirst(list, false, Compare.GE, (int) pos);
+ }
+
+ /**
+ * 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)
+ {
+ findContactStartOverlaps(from, to, result);
+ findContactEndOverlaps(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
+ */
+ private void findContactEndOverlaps(long from, long to,
+ List<SequenceFeature> result)
+ {
+ /*
+ * find the first contact feature (if any)
+ * whose end point is not before the target range
+ */
+ int index = findFirstEnd(contactFeatureEnds, from);
+
+ int n = contactFeatureEnds.size();
+ while (index < n)
+ {
+ SequenceFeature sf = contactFeatureEnds.get(index);
+ if (!sf.isContactFeature())
+ {
+ System.err.println("Error! non-contact feature type " + sf.getType()
+ + " in contact features list");
+ index++;
+ 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
+ */
+ index++;
+ continue;
+ }
+
+ if (sf.getEnd() > to)
+ {
+ /*
+ * this feature (and all following) has end point after the target range
+ */
+ break;
+ }