JAL-2668 add tests for HMMER commands, annotation and io
[jalview.git] / src / jalview / datamodel / HiddenMarkovModel.java
index 2b9bd3b..086f5cd 100644 (file)
@@ -4,7 +4,6 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Scanner;
 
 /**
  * Data structure which stores a hidden Markov model. Currently contains file
@@ -41,8 +40,6 @@ public class HiddenMarkovModel
   final static String YES = "yes";
 
   final static String NO = "no";
-
-  int numberOfSymbols;
   
   // keys for file properties hashmap
   private final String NAME = "NAME";
@@ -129,7 +126,6 @@ public class HiddenMarkovModel
     this.nodeLookup = new HashMap<>(hmm.nodeLookup);
     this.symbolIndexLookup = new HashMap<>(
             hmm.symbolIndexLookup);
-    this.numberOfSymbols = hmm.numberOfSymbols;
     this.fileHeader = new String(hmm.fileHeader);
   }
 
@@ -454,7 +450,6 @@ public class HiddenMarkovModel
   public Double getStateTransitionProbability(int alignColumn,
           int transition)
   {
-    int transitionIndex;
     int nodeIndex;
     Double probability;
     if (nodeLookup.containsKey(alignColumn))
@@ -499,7 +494,8 @@ public class HiddenMarkovModel
   }
   
   /**
-   * Returns the consensus at a given alignment column.
+   * Returns the consensus at a given alignment column. If the character is
+   * lower case, its emission probability is less than 0.5.
    * 
    * @param columnIndex
    *          The index of the column in the alignment for which the consensus
@@ -532,6 +528,10 @@ public class HiddenMarkovModel
           mostLikely = character;
         }
       }
+      if (highestProb < 0.5)
+      {
+        mostLikely = Character.toLowerCase(mostLikely);
+      }
       return mostLikely;
     }
 
@@ -597,28 +597,7 @@ public class HiddenMarkovModel
    */
   public int getNumberOfSymbols()
   {
-    return numberOfSymbols;
-  }
-
-  /**
-   * Fills symbol array and whilst doing so, updates the value of the number of
-   * symbols.
-   * 
-   * @param parser
-   *          The scanner scanning the symbol line in the file.
-   */
-  public void fillSymbols(Scanner parser)
-  {
-    int i = 0;
-    while (parser.hasNext())
-    {
-      String strSymbol = parser.next();
-      char[] symbol = strSymbol.toCharArray();
-      symbols.add(symbol[0]);
-      symbolIndexLookup.put(symbol[0], i);
-      i++;
-    }
-    numberOfSymbols = symbols.size();
+    return symbols.size();
   }
 
   /**
@@ -1028,6 +1007,15 @@ public class HiddenMarkovModel
     return consensus;
   }
 
+  public int getSymbolIndex(char c)
+  {
+    return symbolIndexLookup.get(c);
+  }
+
+  public void setSymbolIndex(Character c, Integer i)
+  {
+    symbolIndexLookup.put(c, i);
+  }
 
 }