Merge branch 'develop' into features/mchmmer
[jalview.git] / src / jalview / datamodel / Alignment.java
index f268d37..f4be087 100755 (executable)
@@ -288,6 +288,32 @@ public class Alignment implements AlignmentI
   }
 
   /**
+   * Inserts a sequence at a point in the alignment.
+   * 
+   * @param i
+   *          the index of the position the sequence is to be inserted in.
+   */
+  @Override
+  public void insertSequenceAt(int i, SequenceI snew)
+  {
+    synchronized (sequences)
+    {
+      if (sequences.size() > i)
+      {
+        sequences.add(i, snew);
+        return;
+
+      }
+      else
+      {
+        sequences.add(snew);
+        hiddenSequences.adjustHeightSequenceAdded();
+      }
+      return;
+    }
+  }
+
+  /**
    * DOCUMENT ME!
    * 
    * @return DOCUMENT ME!
@@ -1895,4 +1921,47 @@ public class Alignment implements AlignmentI
   {
     hiddenCols = cols;
   }
+
+  /**
+   * Returns all HMM consensus sequences. This will not return real sequences
+   * with HMMs. If remove is set to true, the consensus sequences will be
+   * removed from the alignment.
+   */
+  @Override // TODO make this more efficient.
+  public List<SequenceI> getHMMConsensusSequences(boolean remove)
+  {
+    List<SequenceI> seqs = new ArrayList<>();
+    int position = 0;
+    int seqsRemoved = 0;
+    boolean endReached = false;
+
+    while (!endReached)
+    {
+      SequenceI seq = sequences.get(position);
+      if (seq.isHMMConsensusSequence())
+      {
+        if (remove)
+        {
+          sequences.remove(position);
+          seqsRemoved++;
+          seq.setPreviousPosition(seqsRemoved + position - 1);
+        }
+        else
+        {
+          position++;
+        }
+        seqs.add(seq);
+      }
+      else
+      {
+        position++;
+      }
+
+      if (position >= sequences.size())
+      {
+        endReached = true;
+      }
+    }
+    return seqs;
+  }
 }