JAL-2629 HMMs now map to reference annotation if exists
authorTZVanaalten <TZVanaalten@LS30916.ad.lifesci.dundee.ac.uk>
Wed, 26 Jul 2017 12:16:48 +0000 (13:16 +0100)
committerTZVanaalten <TZVanaalten@LS30916.ad.lifesci.dundee.ac.uk>
Wed, 26 Jul 2017 12:16:48 +0000 (13:16 +0100)
src/jalview/datamodel/HiddenMarkovModel.java

index 879968f..40f106e 100644 (file)
@@ -1054,5 +1054,40 @@ public class HiddenMarkovModel
     }
     return mostLikely;
   }
+
+  /**
+   * Maps the nodes of the hidden Markov model to the reference annotation.
+   */
+  public void mapToReferenceAnnotation(AlignmentAnnotation alAnnotation)
+  {
+    Annotation[] annots = alAnnotation.annotations;
+    {
+      int nodeIndex = 0;
+      for (int col = 0; col < annots.length; col++)
+      {
+        String character = annots[col].displayCharacter;
+        if ("x".equals(character) || "X".equals(character))
+        {
+          nodeIndex++;
+          if (nodeIndex <= nodes.size())
+          {
+            nodes.get(nodeIndex).setAlignmentColumn(col + 1);
+            nodeLookup.put(col + 1, nodeIndex);
+          }
+          else
+          {
+            System.out.println(
+                    "The reference annotation contains more consensus columns than the hidden Markov model");
+            break;
+          }
+        }
+        else
+        {
+          nodeLookup.remove(col + 1);
+        }
+      }
+
+    }
+  }
 }