JAL-2541 it works!! it works!!!
[jalview.git] / src / jalview / datamodel / Sequence.java
index b758d51..6aaa68b 100755 (executable)
@@ -724,6 +724,7 @@ public class Sequence extends ASequence implements SequenceI
      * preserve end residue column provided cursor was valid
      */
     int endColumn = isValidCursor(cursor) ? cursor.lastColumnPosition : 0;
+
     if (residuePos == this.end)
     {
       endColumn = column;
@@ -760,8 +761,7 @@ public class Sequence extends ASequence implements SequenceI
     /*
      * move left or right to find pos from hint.position
      */
-    int col = curs.columnPosition - 1; // convert from base 1 to 0-based array
-                                       // index
+    int col = curs.columnPosition - 1; // convert from base 1 to base 0
     int newPos = curs.residuePosition;
     int delta = newPos > pos ? -1 : 1;
 
@@ -1159,9 +1159,9 @@ public class Sequence extends ASequence implements SequenceI
     // the very large sequence case
     int eindex = -1, sindex = -1;
     boolean ecalc = false, scalc = false;
-    for (int s = i; s < j; s++)
+    for (int s = i; s < j && s < sequence.length; s++)
     {
-      if (jalview.schemes.ResidueProperties.aaIndex[sequence[s]] != 23)
+      if (!Comparison.isGap(sequence[s]))
       {
         if (createNewDs)
         {
@@ -1818,6 +1818,15 @@ public class Sequence extends ASequence implements SequenceI
 
     List<SequenceFeature> result = getFeatures().findFeatures(startPos,
             endPos, types);
+    if (datasetSequence != null)
+    {
+      result = datasetSequence.getFeatures().findFeatures(startPos, endPos,
+              types);
+    }
+    else
+    {
+      result = sequenceFeatureStore.findFeatures(startPos, endPos, types);
+    }
 
     /*
      * if end column is gapped, endPos may be to the right, 
@@ -1898,75 +1907,4 @@ public class Sequence extends ASequence implements SequenceI
 
     return count;
   }
-
-  @Override
-  public List<SequenceFeature[]> adjustFeatures(int fromColumn, int toColumn)
-  {
-    List<SequenceFeature[]> amended = new ArrayList<>();
-
-    if (toColumn < fromColumn)
-    {
-      return amended;
-    }
-
-    synchronized (sequenceFeatureStore)
-    {
-      /*
-       * get features that overlap or span the cut region
-       */
-      List<SequenceFeature> overlaps = findFeatures(fromColumn, toColumn);
-      int cutWidth = toColumn - fromColumn + 1;
-
-      /*
-       * get features that strictly follow the cut region,
-       *  and shift them left by the width of the cut
-       */
-      List<SequenceFeature> follow = findFeatures(toColumn + 1,
-              Integer.MAX_VALUE);
-      follow.removeAll(overlaps);
-      for (SequenceFeature sf : follow)
-      {
-        SequenceFeature copy = new SequenceFeature(sf, sf.getBegin()
-                - cutWidth, sf.getEnd() - cutWidth, sf.getFeatureGroup(),
-                sf.getScore());
-        deleteFeature(sf);
-        addSequenceFeature(copy);
-      }
-
-      /*
-       * adjust start-end of overlapping features, and delete if enclosed by
-       * the cut, or a partially overlapping contact feature
-       */
-      for (SequenceFeature sf : overlaps)
-      {
-        // TODO recode to compute newBegin, newEnd, isDelete
-        // then perform the action
-        int sfBegin = sf.getBegin();
-        int sfEnd = sf.getEnd();
-        int startCol = findIndex(sfBegin);
-        int endCol = findIndex(sfEnd);
-        if (startCol >= fromColumn && endCol <= toColumn)
-        {
-          // within cut region - delete feature
-          deleteFeature(sf);
-          amended.add(new SequenceFeature[] { sf, null });
-          continue;
-        }
-        if (startCol < fromColumn && endCol > toColumn)
-        {
-          // feature spans cut region - shift end left
-          SequenceFeature copy = new SequenceFeature(sf, sf.getBegin(),
-                  sf.getEnd() - cutWidth, sf.getFeatureGroup(),
-                  sf.getScore());
-          deleteFeature(sf);
-          addSequenceFeature(copy);
-          amended.add(new SequenceFeature[] { sf, copy });
-          continue;
-        }
-        // todo partial overlap - delete if contact feature
-      }
-    }
-
-    return amended;
-  }
 }