only return non-empty subsequences when getting selection as new sequences
authorjprocter <Jim Procter>
Wed, 2 May 2007 13:41:22 +0000 (13:41 +0000)
committerjprocter <Jim Procter>
Wed, 2 May 2007 13:41:22 +0000 (13:41 +0000)
src/jalview/datamodel/SequenceGroup.java

index 47d56b7..18fb53b 100755 (executable)
@@ -93,34 +93,45 @@ public class SequenceGroup
     int iSize = sequences.size();
     SequenceI[] seqs = new SequenceI[iSize];
     SequenceI[] inorder = getSequencesInOrder(align);
-
-    for (int i = 0; i < iSize; i++)
+    
+    for (int i = 0,ipos=0; i < inorder.length; i++)
     {
       SequenceI seq = inorder[i];
 
-      seqs[i] = seq.getSubSequence(startRes, endRes+1);
-
-      seqs[i].setDescription(seq.getDescription());
-      seqs[i].setDBRef(seq.getDBRef());
-      seqs[i].setSequenceFeatures(seq.getSequenceFeatures());
-      if (seq.getDatasetSequence() != null)
+      seqs[ipos] = seq.getSubSequence(startRes, endRes+1);
+      if (seqs[ipos]!=null)
       {
-        seqs[i].setDatasetSequence(seq.getDatasetSequence());
-      }
+        seqs[ipos].setDescription(seq.getDescription());
+        seqs[ipos].setDBRef(seq.getDBRef());
+        seqs[ipos].setSequenceFeatures(seq.getSequenceFeatures());
+        if (seq.getDatasetSequence() != null)
+        {
+          seqs[ipos].setDatasetSequence(seq.getDatasetSequence());
+        }
 
-      if (seq.getAnnotation() != null)
-      {
-        for (int a = 0; a < seq.getAnnotation().length; a++)
+        if (seq.getAnnotation() != null)
         {
-          AlignmentAnnotation newannot = new AlignmentAnnotation(seq.getAnnotation()[a]);
-          newannot.restrict(startRes, endRes);
-          newannot.setSequenceRef(seqs[i]);
-          newannot.adjustForAlignment();
-          seqs[i].addAlignmentAnnotation(newannot);
+          for (int a = 0; a < seq.getAnnotation().length; a++)
+          {
+            AlignmentAnnotation newannot = new AlignmentAnnotation(seq
+                    .getAnnotation()[a]);
+            newannot.restrict(startRes, endRes);
+            newannot.setSequenceRef(seqs[ipos]);
+            newannot.adjustForAlignment();
+            seqs[ipos].addAlignmentAnnotation(newannot);
+          }
         }
+        ipos++;
+      } else {
+        iSize--;
       }
     }
-
+    if (iSize!=inorder.length)
+    {
+      SequenceI[] nseqs = new SequenceI[iSize];
+      System.arraycopy(seqs, 0, nseqs, 0, iSize);
+      seqs = nseqs;
+    }
     return seqs;
 
   }