Merge commit 'alpha/update_2_12_for_2_11_2_series_merge^2' into HEAD
[jalview.git] / src / jalview / datamodel / Sequence.java
index d52e049..846b876 100755 (executable)
@@ -27,6 +27,7 @@ import jalview.util.Comparison;
 import jalview.util.DBRefUtils;
 import jalview.util.MapList;
 import jalview.util.StringUtils;
+import jalview.workers.InformationThread;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -82,6 +83,9 @@ public class Sequence extends ASequence implements SequenceI
 
   private String vamsasId;
 
+  HiddenMarkovModel hmm;
+
+  boolean isHMMConsensusSequence = false;
   private DBModList<DBRefEntry> dbrefs; // controlled access
 
   /**
@@ -361,6 +365,10 @@ public class Sequence extends ASequence implements SequenceI
         this.addPDBId(new PDBEntry(pdb));
       }
     }
+    if (seq.getHMM() != null)
+    {
+      this.hmm = new HiddenMarkovModel(seq.getHMM(), this);
+    }
   }
 
   @Override
@@ -1069,7 +1077,8 @@ public class Sequence extends ASequence implements SequenceI
   @Override
   public ContiguousI findPositions(int fromColumn, int toColumn)
   {
-    if (toColumn < fromColumn || fromColumn < 1)
+    fromColumn = Math.max(fromColumn, 1);
+    if (toColumn < fromColumn)
     {
       return null;
     }
@@ -1817,12 +1826,12 @@ public class Sequence extends ASequence implements SequenceI
     {
       for (AlignmentAnnotation ann : annotation)
       {
-        if ((ann.calcId != null && ann.calcId.equals(calcId))
+        String id = ann.getCalcId();
+        if ((id != null && id.equals(calcId))
                 && (ann.label != null && ann.label.equals(label))
                 && ((ignoreDescription && description == null)
                         || (ann.description != null
                                 && ann.description.equals(description))))
-
         {
           result.add(ann);
         }
@@ -1941,6 +1950,33 @@ public class Sequence extends ASequence implements SequenceI
     }
   }
 
+  @Override
+  public HiddenMarkovModel getHMM()
+  {
+    return hmm;
+  }
+
+  @Override
+  public void setHMM(HiddenMarkovModel hmm)
+  {
+    this.hmm = hmm;
+  }
+
+  @Override
+  public boolean hasHMMAnnotation()
+  {
+    if (this.annotation == null) {
+      return false;
+    }
+    for (AlignmentAnnotation ann : annotation)
+    {
+      if (InformationThread.HMM_CALC_ID.equals(ann.getCalcId()))
+      {
+        return true;
+      }
+    }
+    return false;
+  }
   /**
    * {@inheritDoc}
    */
@@ -2105,4 +2141,10 @@ public class Sequence extends ASequence implements SequenceI
     // otherwise, sequence was completely hidden
     return 0;
   }
+
+  @Override
+  public boolean hasHMMProfile()
+  {
+    return hmm != null;
+  }
 }