transferred the storage position of the HMM to annotations
[jalview.git] / src / jalview / io / HMMFile.java
index 6e49af6..6945ea6 100644 (file)
@@ -256,7 +256,9 @@ public class HMMFile extends AlignFile
       }
       else
       {
-        list.add(Double.valueOf(next));
+        double prob = Double.valueOf(next);
+        prob = Math.pow(Math.E, -prob);
+        list.add(prob);
       }
     }
     return list;
@@ -278,7 +280,6 @@ public class HMMFile extends AlignFile
     StringBuilder file = new StringBuilder();
     appendFileProperties(file);
     appendModel(file);
-    
     file.append("//");
 
     PrintWriter output = new PrintWriter(exportLocation);
@@ -325,13 +326,18 @@ public class HMMFile extends AlignFile
     for (double value : list)
     {
       String strValue;
-      if (value == Double.NEGATIVE_INFINITY)
+      if (value > 0)
       {
-        strValue = "*";
+        strValue = String.format("%.5f", value);
+
+      }
+      else if (value == -0.00000d)
+      {
+        strValue = "0.00000";
       }
       else
       {
-        strValue = String.format("%.5f", value);
+        strValue = "*";
       }
 
       strList.add(strValue);
@@ -382,6 +388,7 @@ public class HMMFile extends AlignFile
       List<String> strMatches;
       List<Double> doubleMatches;
       doubleMatches = hmm.getNode(node).getMatchEmissions();
+      convertListToLogSpace(doubleMatches);
       strMatches = doubleListToStringList(doubleMatches, 5);
       matchLine += addData(10, 9, strMatches);
 
@@ -402,6 +409,7 @@ public class HMMFile extends AlignFile
       List<String> strInserts;
       List<Double> doubleInserts;
       doubleInserts = hmm.getNode(node).getInsertEmissions();
+      convertListToLogSpace(doubleInserts);
       strInserts = doubleListToStringList(doubleInserts, 5);
       insertLine += addData(17, 9, strInserts);
 
@@ -411,6 +419,7 @@ public class HMMFile extends AlignFile
       List<String> strTransitions;
       List<Double> doubleTransitions;
       doubleTransitions = hmm.getNode(node).getStateTransitions();
+      convertListToLogSpace(doubleTransitions);
       strTransitions = doubleListToStringList(doubleTransitions, 5);
       transitionLine += addData(17, 9, strTransitions);
 
@@ -550,5 +559,19 @@ public class HMMFile extends AlignFile
 
     return null;
   }
+
+  void convertListToLogSpace(List<Double> list)
+  {
+
+    for (int i = 0; i < list.size(); i++)
+    {
+      double prob = list.get(i);
+      double logProb = -1 * Math.log(prob);
+
+      list.set(i, logProb);
+    }
+
+
+  }
 }