JAL-2629 add multiple options for running hmmbuild on alignment/groups
[jalview.git] / src / jalview / datamodel / SequenceGroup.java
index 854b39d..6db870c 100755 (executable)
@@ -1606,4 +1606,47 @@ public class SequenceGroup implements AnnotatedCollectionI
     normaliseSequenceLogo = state;
   }
 
+  /**
+   * 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;
+  }
+
 }