JAL-3397 impl.IntervalStore and nonc.IntervalStore unified api
[jalview.git] / src / jalview / datamodel / Alignment.java
index 3e0856a..22d23bc 100755 (executable)
@@ -59,6 +59,15 @@ public class Alignment implements AlignmentI
 
   private boolean nucleotide = true;
 
+  private List<AlignedCodonFrame> codonFrameList;
+
+  private static final SequenceGroup[] noGroups = new SequenceGroup[0];
+
+  /*
+   * persistent object to hold result of findAllGroups(SequenceI)
+   */
+  private List<SequenceGroup> groupsForSequence = new ArrayList<>();
+
   public boolean hasRNAStructure = false;
 
   public AlignmentAnnotation[] annotations;
@@ -69,8 +78,6 @@ public class Alignment implements AlignmentI
 
   public Hashtable alignmentProperties;
 
-  private List<AlignedCodonFrame> codonFrameList;
-
   private void initAlignment(SequenceI[] seqs)
   {
     groups = Collections.synchronizedList(new ArrayList<SequenceGroup>());
@@ -125,8 +132,7 @@ public class Alignment implements AlignmentI
   /**
    * Make a new alignment from an array of SeqCigars
    * 
-   * @param seqs
-   *          SeqCigar[]
+   * @param alseqs
    */
   public Alignment(SeqCigar[] alseqs)
   {
@@ -195,6 +201,7 @@ public class Alignment implements AlignmentI
   {
     synchronized (sequences)
     {
+    
       if (i > -1 && i < sequences.size())
       {
         return sequences.get(i);
@@ -407,11 +414,14 @@ public class Alignment implements AlignmentI
   @Override
   public SequenceGroup[] findAllGroups(SequenceI s)
   {
-    ArrayList<SequenceGroup> temp = new ArrayList<>();
-
     synchronized (groups)
     {
       int gSize = groups.size();
+      if (gSize == 0)
+      {
+        return noGroups;
+      }
+      groupsForSequence.clear();
       for (int i = 0; i < gSize; i++)
       {
         SequenceGroup sg = groups.get(i);
@@ -424,12 +434,12 @@ public class Alignment implements AlignmentI
 
         if (sg.getSequences().contains(s))
         {
-          temp.add(sg);
+          groupsForSequence.add(sg);
         }
       }
     }
-    SequenceGroup[] ret = new SequenceGroup[temp.size()];
-    return temp.toArray(ret);
+    SequenceGroup[] ret = new SequenceGroup[groupsForSequence.size()];
+    return groupsForSequence.toArray(ret);
   }
 
   /**    */
@@ -589,11 +599,12 @@ public class Alignment implements AlignmentI
     int i = 0;
     SequenceI sq = null;
     String sqname = null;
+    int nseq = sequences.size();
     if (startAfter != null)
     {
       // try to find the sequence in the alignment
       boolean matched = false;
-      while (i < sequences.size())
+      while (i < nseq)
       {
         if (getSequenceAt(i++) == startAfter)
         {
@@ -606,7 +617,7 @@ public class Alignment implements AlignmentI
         i = 0;
       }
     }
-    while (i < sequences.size())
+    while (i < nseq)
     {
       sq = getSequenceAt(i);
       sqname = sq.getName();
@@ -712,39 +723,21 @@ public class Alignment implements AlignmentI
   
     for (int i = 0; i < sequences.size(); i++)
     {
-      if (getSequenceAt(i).getLength() > maxLength)
-      {
-        maxLength = getSequenceAt(i).getLength();
-      }
+      maxLength = Math.max(maxLength, getSequenceAt(i).getLength());
     }
-  
     return maxLength;
   }
-  /*
+
   @Override
-  public int getWidth()
+  public int getVisibleWidth()
   {
-    final Wrapper temp = new Wrapper();
-  
-    forEachSequence(new Consumer<SequenceI>()
+    int w = getWidth();
+    if (hiddenCols != null)
     {
-      @Override
-      public void accept(SequenceI s)
-      {
-        if (s.getLength() > temp.inner)
-        {
-          temp.inner = s.getLength();
-        }
-      }
-    }, 0, sequences.size() - 1);
-  
-    return temp.inner;
+      w -= hiddenCols.getSize();
+    }
+    return w;
   }
-  
-  public static class Wrapper
-  {
-    public int inner;
-  }*/
 
   /**
    * DOCUMENT ME!
@@ -1206,7 +1199,8 @@ public class Alignment implements AlignmentI
     int maxLength = -1;
 
     SequenceI current;
-    for (int i = 0; i < sequences.size(); i++)
+    int nseq = sequences.size();
+    for (int i = 0; i < nseq; i++)
     {
       current = getSequenceAt(i);
       for (int j = current.getLength(); j > maxLength; j--)
@@ -1223,7 +1217,7 @@ public class Alignment implements AlignmentI
     maxLength++;
 
     int cLength;
-    for (int i = 0; i < sequences.size(); i++)
+    for (int i = 0; i < nseq; i++)
     {
       current = getSequenceAt(i);
       cLength = current.getLength();
@@ -2042,4 +2036,17 @@ public class Alignment implements AlignmentI
     }
   }
 
+  @Override
+  public void resetColors()
+  {
+    for (int i = getHeight(); --i >= 0;)
+    {
+      sequences.get(i).resetColors();
+    }
+    // if (dataset != null)
+    // {
+    // dataset.resetColors();
+    // }
+  }
+
 }