JAL-2629 HMMs dropped on the alignment now map to the rf annotation
[jalview.git] / src / jalview / datamodel / Sequence.java
index a673514..4736981 100755 (executable)
@@ -1563,6 +1563,41 @@ public class Sequence extends ASequence implements SequenceI
 
   }
 
+  /**
+   * Maps the HMM sequence to the reference annotation.
+   * 
+   * @param rf
+   */
+  @Override
+  public void mapToReference(AlignmentAnnotation rf)
+  {
+    if (this.isHMMConsensusSequence)
+    {
+      int node = 1;
+      hmm.emptyNodeLookup();
+      for (int i = 0; i < getLength(); i++)
+      {
+        if (rf.annotations[i].displayCharacter.equals("x")
+                || rf.annotations[i].displayCharacter.equals("X"))
+        {
+          if (i < hmm.getNodeAlignmentColumn(node))
+          {
+            this.deleteChars(i, hmm.getNodeAlignmentColumn(node));
+            updateHMMMapping();
+          }
+          else if (i > hmm.getNodeAlignmentColumn(node))
+          {
+            int length = i - hmm.getNodeAlignmentColumn(node);
+            this.insertCharAt(hmm.getNodeAlignmentColumn(node), length,
+                    '-');
+            updateHMMMapping();
+          }
+          node++;
+        }
+      }
+    }
+  }
+
   @Override
   public boolean isHMMConsensusSequence()
   {