JAL-2599 fix issue where parser exported map annotation incorrectly
authorTZVanaalten <TZVanaalten@LS30916.ad.lifesci.dundee.ac.uk>
Wed, 2 Aug 2017 09:52:25 +0000 (10:52 +0100)
committerTZVanaalten <TZVanaalten@LS30916.ad.lifesci.dundee.ac.uk>
Wed, 2 Aug 2017 09:52:25 +0000 (10:52 +0100)
src/jalview/io/HMMFile.java
test/jalview/io/HMMFileTest.java

index 4ff8e77..e7f8030 100644 (file)
@@ -487,7 +487,7 @@ public class HMMFile extends AlignFile
 
       if (node != 0)
       {
-        matchLine += SPACE + hmm.getNodeAlignmentColumn(node) + 1;
+        matchLine += SPACE + (hmm.getNodeAlignmentColumn(node) + 1);
         matchLine += SPACE + hmm.getConsensusResidue(node);
         matchLine += SPACE + hmm.getReferenceAnnotation(node);
         if (hmm.getFileHeader().contains("HMMER3/f"))
index 70bfc27..15d51c2 100644 (file)
@@ -8,8 +8,10 @@ import jalview.datamodel.HiddenMarkovModel;
 
 import java.io.BufferedReader;
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.io.IOException;
+import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Scanner;
@@ -114,13 +116,13 @@ public class HMMFileTest {
     assertEquals(getStateTransition(209, 0, hmm), 0.99, 0.001d);
     assertEquals(getStateTransition(243, 1, hmm), 0.0066, 0.001d);
   
-    assertEquals(hmm.getNodeAlignmentColumn(3).intValue(), 3);
+    assertEquals(hmm.getNodeAlignmentColumn(3).intValue(), 2);
     assertEquals(hmm.getReferenceAnnotation(7), '-');
     assertEquals(hmm.getConsensusResidue(23), 't');
     assertEquals(hmm.getMaskedValue(30), '-');
     assertEquals(hmm.getConsensusStructure(56), 'S');
   
-    assertEquals(hmm.getNodeAlignmentColumn(78).intValue(), 136);
+    assertEquals(hmm.getNodeAlignmentColumn(78).intValue(), 135);
     assertEquals(hmm.getReferenceAnnotation(93), '-');
     assertEquals(hmm.getConsensusResidue(145), 'a');
     assertEquals(hmm.getMaskedValue(183), '-');
@@ -310,25 +312,16 @@ public class HMMFileTest {
   
     HiddenMarkovModel hmm = testFile.getHMM();
   
-    assertEquals(hmm.getNodeAlignmentColumn(1).intValue(), 1345);
+    assertEquals(hmm.getNodeAlignmentColumn(1).intValue(), 1344);
     assertEquals(hmm.getConsensusResidue(1), 't');
     assertEquals(hmm.getReferenceAnnotation(1), 't');
     assertEquals(hmm.getMaskedValue(1), 't');
     assertEquals(hmm.getConsensusStructure(1), 't');
   
-    assertEquals(hmm.findNodeIndex(1345).intValue(), 1);
+    assertEquals(hmm.findNodeIndex(1344).intValue(), 1);
   
     scanner.close();
   
-    assertNull(hmm.getNodeAlignmentColumn(2));
-    assertEquals(hmm.getConsensusResidue(2), 'y');
-    assertEquals(hmm.getReferenceAnnotation(2), 'x');
-    assertEquals(hmm.getMaskedValue(2), '-');
-    assertEquals(hmm.getConsensusStructure(2), '-');
-  
-    assertNull(hmm.findNodeIndex(2));
-  
-    scanner2.close();
   }
   
   /**
@@ -404,11 +397,17 @@ public class HMMFileTest {
   }
   
   @Test(priority = 1)
-  public void testAppendFileProperties()
+  public void testAppendFileProperties() throws FileNotFoundException
   {
-    StringBuilder testBuilder = new StringBuilder();
-    fn3.appendFileProperties(testBuilder);
-    Scanner testScanner = new Scanner(testBuilder.toString());
+    PrintWriter writer = new PrintWriter(
+            "test/jalview/io/test_export_hmm.txt");
+    fn3.appendFileProperties(writer);
+    writer.close();
+    String content;
+    File file = new File("test/jalview/io/test_export_hmm.txt");
+
+    Scanner testScanner = new Scanner(file);
+    testScanner.useDelimiter("\\Z");
   
     String[] expected = new String[] { "HMMER3/f [3.1b1 | May 2013]",
         "NAME  fn3", "ACC   PF00041.13",
@@ -429,11 +428,18 @@ public class HMMFileTest {
   }
   
   @Test(priority = 2)
-  public void testAppendModel()
+  public void testAppendModel() throws FileNotFoundException
   {
-    StringBuilder testBuilder = new StringBuilder();
-    fn3.appendModel(testBuilder);
-    String string = testBuilder.toString();
+    PrintWriter writer = new PrintWriter(
+            "test/jalview/io/test_export_hmm.txt");
+    fn3.appendModel(writer);
+    writer.close();
+    String string;
+    File file = new File("test/jalview/io/test_export_hmm.txt");
+    Scanner scanner = new Scanner(file);
+    scanner.useDelimiter("\\Z");
+    string = scanner.next();
+
     assertEquals(findValue(2, 2, 2, string), "4.42225");
     assertEquals(findValue(12, 14, 1, string), "2.79307");
     assertEquals(findValue(6, 24, 3, string), "0.48576");