Merge branch 'bug/JAL-2829deleteCharsWithGaps' into
[jalview.git] / src / jalview / datamodel / Sequence.java
index 2feb9f6..006afb3 100755 (executable)
@@ -42,10 +42,7 @@ import fr.orsay.lri.varna.models.rna.RNA;
 
 /**
  * 
- * Implements the SequenceI interface for a char[] based sequence object.
- * 
- * @author $author$
- * @version $Revision$
+ * Implements the SequenceI interface for a char[] based sequence object
  */
 public class Sequence extends ASequence implements SequenceI
 {
@@ -744,6 +741,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;
@@ -780,8 +778,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;
 
@@ -1177,12 +1174,13 @@ public class Sequence extends ASequence implements SequenceI
     boolean createNewDs = false;
     // TODO: take a (second look) at the dataset creation validation method for
     // the very large sequence case
+
     int startIndex = findIndex(start) - 1;
     int endIndex = findIndex(end) - 1;
     int startDeleteColumn = -1; // for dataset sequence deletions
     int deleteCount = 0;
 
-    for (int s = i; s < j; s++)
+    for (int s = i; s < j && s < sequence.length; s++)
     {
       if (Comparison.isGap(sequence[s]))
       {
@@ -1696,7 +1694,7 @@ public class Sequence extends ASequence implements SequenceI
   }
 
   /**
-   * @return The index (zero-based) on this sequence in the MSA. It returns
+   * @return The index (zero-based) of this sequence in the MSA. It returns
    *         {@code -1} if this information is not available.
    */
   @Override
@@ -1706,12 +1704,10 @@ public class Sequence extends ASequence implements SequenceI
   }
 
   /**
-   * Defines the position of this sequence in the MSA. Use the value {@code -1}
-   * if this information is undefined.
+   * Defines the (zero-based) position of this sequence in the MSA. Use the
+   * value {@code -1} if this information is undefined.
    * 
-   * @param The
-   *          position for this sequence. This value is zero-based (zero for
-   *          this first sequence)
+   * @param value
    */
   @Override
   public void setIndex(int value)
@@ -1851,6 +1847,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,