Merge commit 'alpha/update_2_12_for_2_11_2_series_merge^2' into HEAD
[jalview.git] / src / jalview / datamodel / HMMNode.java
index 30a6a8d..b646eee 100644 (file)
@@ -1,8 +1,5 @@
 package jalview.datamodel;
 
-import java.util.ArrayList;
-import java.util.List;
-
 /**
  * stores data for each node in the hmm model
  * @author TZVanaalten
@@ -11,56 +8,84 @@ import java.util.List;
 public class HMMNode
 {
   //contains the match emissions for each symbol 
-  List<Double> matchEmissions = new ArrayList<>();
+  double[] matchEmissions;
+
   //contains the insert emissions for each symbol 
-  List<Double> insertEmissions = new ArrayList<>();
-  //contains the state transitions for each possible transition. These are bm, bi, bd, im, ii, dm and dd in order (0th position in
-  // the array indicates the probability of a bm transition)
-  List<Double> stateTransitions = new ArrayList<>();
+  double[] insertEmissions;
+
+  // contains the state transitions for each possible transition. These are mm,
+  // mi, md, im, ii, dm and dd in order
+  double[] stateTransitions;
   
   //annotations
-  Integer alignmentColumn = null;
+  int residueNumber;
   char consensusResidue;
   char referenceAnnotation;
   char maskValue;
   char consensusStructure;
-  public List<Double> getMatchEmissions()
+
+  /**
+   * Constructor
+   */
+  public HMMNode()
+  {
+  }
+
+  public double[] getMatchEmissions()
   {
     return matchEmissions;
   }
 
-  public void setMatchEmissions(List<Double> matchEmissionsL)
+  double getMatchEmission(int symbolIndex)
   {
-    this.matchEmissions = matchEmissionsL;
+    return matchEmissions[symbolIndex];
   }
-  public List<Double> getInsertEmissions()
+
+  public void setMatchEmissions(double[] matches)
+  {
+    this.matchEmissions = matches;
+  }
+
+  public double[] getInsertEmissions()
   {
     return insertEmissions;
   }
 
-  public void setInsertEmissions(List<Double> insertEmissionsL)
+  double getInsertEmission(int symbolIndex)
+  {
+    return insertEmissions[symbolIndex];
+  }
+
+  public void setInsertEmissions(double[] insertEmissionsL)
   {
     this.insertEmissions = insertEmissionsL;
   }
-  public List<Double> getStateTransitions()
+
+  public double[] getStateTransitions()
   {
     return stateTransitions;
   }
 
-  public void setStateTransitions(List<Double> stateTransitionsL)
+  double getStateTransition(int transition)
+  {
+    return stateTransitions[transition];
+  }
+
+  public void setStateTransitions(double[] stateTransitionsM)
   {
-    this.stateTransitions = stateTransitionsL;
+    this.stateTransitions = stateTransitionsM;
   }
 
-  public Integer getAlignmentColumn()
+  int getResidueNumber()
   {
-    return alignmentColumn;
+    return residueNumber;
   }
-  public void setAlignmentColumn(int alignmentColumn)
+  public void setResidueNumber(int resNo)
   {
-    this.alignmentColumn = alignmentColumn;
+    this.residueNumber = resNo;
   }
-  public char getConsensusResidue()
+
+  char getConsensusResidue()
   {
     return consensusResidue;
   }
@@ -68,7 +93,8 @@ public class HMMNode
   {
     this.consensusResidue = consensusResidue;
   }
-  public char getReferenceAnnotation()
+
+  char getReferenceAnnotation()
   {
     return referenceAnnotation;
   }
@@ -76,7 +102,8 @@ public class HMMNode
   {
     this.referenceAnnotation = referenceAnnotation;
   }
-  public char getMaskValue()
+
+  char getMaskValue()
   {
     return maskValue;
   }
@@ -84,7 +111,8 @@ public class HMMNode
   {
     this.maskValue = maskValue;
   }
-  public char getConsensusStructure()
+
+  char getConsensusStructure()
   {
     return consensusStructure;
   }
@@ -92,6 +120,29 @@ public class HMMNode
   {
     this.consensusStructure = consensusStructure;
   }
+
+  /**
+   * Answers the symbol index of the symbol with the highest match emission
+   * probability (first symbol in case of a tie). Note this object stores
+   * probabilities, not the negative logarithms as in the HMM file.
+   * 
+   * @return
+   */
+  int getMaxMatchEmissionIndex()
+  {
+    int maxIndex = 0;
+    double max = 0D;
+
+    for (int i = 0; i < matchEmissions.length; i++)
+    {
+      if (matchEmissions[i] > max)
+      {
+        max = matchEmissions[i];
+        maxIndex = i;
+      }
+    }
+    return maxIndex;
+  }
 }