subsequence bound checks and constructor for selectively duplicating sequence associa...
authorjprocter <Jim Procter>
Wed, 2 May 2007 12:21:26 +0000 (12:21 +0000)
committerjprocter <Jim Procter>
Wed, 2 May 2007 12:21:26 +0000 (12:21 +0000)
src/jalview/datamodel/Sequence.java

index 673177c..d64e133 100755 (executable)
@@ -136,10 +136,21 @@ public class Sequence
    */
   public Sequence(SequenceI seq)
   {
+    this(seq, seq.getAnnotation());
+  }
+  /**
+   * Create a new sequence object with new features, DBRefEntries, and PDBIds
+   * but inherits any existing dataset sequence reference, and duplicate of
+   * any annotation that is present in the given annotation array.
+   * @param seq the sequence to be copied
+   * @param alAnnotation an array of annotation including some associated with seq 
+   */
+  public Sequence(SequenceI seq, AlignmentAnnotation[] alAnnotation)
+  {
     this(seq.getName(),
-         seq.getSequence(),
-         seq.getStart(),
-         seq.getEnd());
+            seq.getSequence(),
+            seq.getStart(),
+            seq.getEnd());
     description = seq.getDescription();
     if (seq.getSequenceFeatures()!=null) {
       SequenceFeature[] sf = seq.getSequenceFeatures();
@@ -154,10 +165,18 @@ public class Sequence
       }
     }
     setDatasetSequence(seq.getDatasetSequence());
-    if (seq.getAnnotation()!=null) {
+    if (seq.getAnnotation()!=null && alAnnotation!=null) {
       AlignmentAnnotation[] sqann = seq.getAnnotation();
       for (int i=0;i<sqann.length; i++)
       {
+        boolean found = sqann == alAnnotation;
+        if (!found)
+        {
+          for (int apos = 0; !found && apos<alAnnotation.length; apos++)
+          {
+            found = (alAnnotation[apos] == sqann[i]);
+          }
+        }
         AlignmentAnnotation newann = new AlignmentAnnotation(sqann[i]);
         addAlignmentAnnotation(newann);
       }
@@ -171,7 +190,6 @@ public class Sequence
     }
   }
 
-
   /**
    * DOCUMENT ME!
    *
@@ -413,6 +431,8 @@ public class Sequence
    */
   public char [] getSequence(int start, int end)
   {
+    if (start<0)
+      start=0;
     // JBPNote - left to user to pad the result here (TODO:Decide on this policy)
     if (start >= sequence.length)
     {