From 9970b02398165216f07b967fd77fcf5af3b75daa Mon Sep 17 00:00:00 2001 From: TZVanaalten Date: Wed, 2 Aug 2017 10:52:25 +0100 Subject: [PATCH] JAL-2599 fix issue where parser exported map annotation incorrectly --- src/jalview/io/HMMFile.java | 2 +- test/jalview/io/HMMFileTest.java | 48 +++++++++++++++++++++----------------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/jalview/io/HMMFile.java b/src/jalview/io/HMMFile.java index 4ff8e77..e7f8030 100644 --- a/src/jalview/io/HMMFile.java +++ b/src/jalview/io/HMMFile.java @@ -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")) diff --git a/test/jalview/io/HMMFileTest.java b/test/jalview/io/HMMFileTest.java index 70bfc27..15d51c2 100644 --- a/test/jalview/io/HMMFileTest.java +++ b/test/jalview/io/HMMFileTest.java @@ -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"); -- 1.7.10.2