mapping bug fixes
[jalview.git] / src / jalview / datamodel / Alignment.java
index 9c7f2fb..c474142 100755 (executable)
@@ -108,6 +108,8 @@ public class Alignment
 
   public SequenceI[] getSequencesArray()
   {
+    if (sequences==null)
+      return null;
     SequenceI[] reply = new SequenceI[sequences.size()];
     for (int i = 0; i < sequences.size(); i++)
     {
@@ -489,8 +491,8 @@ public class Alignment
         swap=true;
         continue;
       }
-
-      temp[tIndex++] = annotations[i];
+      if (tIndex<temp.length)
+        temp[tIndex++] = annotations[i];
     }
 
     if (swap)
@@ -725,5 +727,86 @@ public class Alignment
   {
     return alignmentProperties;
   }
+  AlignedCodonFrame[] codonFrameList=null;
+  /* (non-Javadoc)
+   * @see jalview.datamodel.AlignmentI#addCodonFrame(jalview.datamodel.AlignedCodonFrame)
+   */
+  public void addCodonFrame(AlignedCodonFrame codons)
+  {
+    if (codons==null)
+      return;
+    if (codonFrameList==null)
+    {
+      codonFrameList = new AlignedCodonFrame[] { codons };
+      return;
+    }
+    AlignedCodonFrame[] t = new AlignedCodonFrame[codonFrameList.length+1];
+    System.arraycopy(codonFrameList, 0, t, 0, codonFrameList.length);
+    t[codonFrameList.length] = codons;
+    codonFrameList = t;
+  }
+
+  /* (non-Javadoc)
+   * @see jalview.datamodel.AlignmentI#getCodonFrame(int)
+   */
+  public AlignedCodonFrame getCodonFrame(int index)
+  {
+    return codonFrameList[index];
+  }
 
+  /* (non-Javadoc)
+   * @see jalview.datamodel.AlignmentI#getCodonFrame(jalview.datamodel.SequenceI)
+   */
+  public AlignedCodonFrame[] getCodonFrame(SequenceI seq)
+  {
+    if (seq==null || codonFrameList==null)
+      return null;
+    Vector cframes=new Vector();
+    for (int f=0;f<codonFrameList.length; f++)
+    {
+      if (codonFrameList[f].involvesSequence(seq))
+        cframes.addElement(codonFrameList[f]);
+    }
+    if (cframes.size()==0)
+      return null;
+    AlignedCodonFrame[] cfr = new AlignedCodonFrame[cframes.size()];
+    cframes.copyInto(cfr);
+    return cfr;
+  }
+
+  /* (non-Javadoc)
+   * @see jalview.datamodel.AlignmentI#getCodonFrames()
+   */
+  public AlignedCodonFrame[] getCodonFrames()
+  {
+    return codonFrameList;
+  }
+
+  /* (non-Javadoc)
+   * @see jalview.datamodel.AlignmentI#removeCodonFrame(jalview.datamodel.AlignedCodonFrame)
+   */
+  public boolean removeCodonFrame(AlignedCodonFrame codons)
+  {
+    if (codons==null || codonFrameList==null)
+      return false;
+    boolean removed=false;
+    int i=0,iSize=codonFrameList.length;
+    while (i<iSize)
+    {
+      if (codonFrameList[i]==codons)
+      {
+        removed=true;
+        if (i+1<iSize)
+        {
+          System.arraycopy(codonFrameList,i+1,codonFrameList, i, iSize-i-1);
+        }
+        iSize--;
+      }
+      else
+      {
+        i++;
+      }
+    }
+    return removed;
+  }
 }