JAL-2629 HMMs dropped on the alignment now map to the rf annotation
authorosboxes <osboxes@osboxes>
Tue, 29 Aug 2017 11:00:15 +0000 (07:00 -0400)
committerosboxes <osboxes@osboxes>
Tue, 29 Aug 2017 11:00:15 +0000 (07:00 -0400)
src/jalview/datamodel/Sequence.java
src/jalview/datamodel/SequenceI.java
src/jalview/io/FileLoader.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()
   {
index 20362dd..fed3eff 100755 (executable)
@@ -502,4 +502,6 @@ public interface SequenceI extends ASequenceI
    *         returns true.
    */
   BitSet getInsertionsAsBits();
+
+  void mapToReference(AlignmentAnnotation rf);
 }
index 73fbc88..90c509e 100755 (executable)
@@ -26,6 +26,7 @@ import jalview.api.FeaturesDisplayedI;
 import jalview.api.FeaturesSourceI;
 import jalview.bin.Cache;
 import jalview.bin.Jalview;
+import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.HiddenColumns;
 import jalview.datamodel.PDBEntry;
@@ -426,6 +427,17 @@ public class FileLoader implements Runnable
               SequenceI seq = alignment
                       .getSequenceAt(alignment.getAbsoluteHeight() - 1);
               seq.setIsHMMConsensusSequence(true);
+              AlignmentAnnotation[] annots = viewport.getAlignment()
+                      .getAlignmentAnnotation();
+              for (AlignmentAnnotation annot : annots)
+              {
+                if ("RF".equals(annot.label)
+                        || annot.label.contains("Reference"))
+                {
+                  seq.mapToReference(annot);
+                  break;
+                }
+              }
               alignment.deleteSequence(alignment.getAbsoluteHeight() - 1);
               alignment.insertSequenceAt(0, seq);
               viewport.getAlignPanel().adjustAnnotationHeight();