JAL-2599 fix issue where parser exported map annotation incorrectly
[jalview.git] / test / jalview / io / HMMFileTest.java
index 9beaab0..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;
@@ -18,41 +20,55 @@ import org.testng.annotations.Test;
 
 public class HMMFileTest {
 
-  HMMFile fn3 = new HMMFile("H:/fn3.hmm");
 
-  HMMFile emptyFile = new HMMFile("H:/EmptyFile.hmm");
 
-  HMMFile pKinase = new HMMFile("H:/Pkinase.hmm");
+  HMMFile fn3 = new HMMFile(
+          new FileParse("test/jalview/io/test_fn3_hmm.txt",
+                  DataSourceType.FILE));
+
+  HMMFile pKinase = new HMMFile(
+          new FileParse("test/jalview/io/test_PKinase_hmm.txt",
+                  DataSourceType.FILE));
+
+  HMMFile made1 = new HMMFile(
+          new FileParse("test/jalview/io/test_MADE1_hmm.txt",
+                  DataSourceType.FILE));
+
+  HMMFileTest() throws IOException
+  {
+
+  }
+
+  
 
-  HMMFile made1 = new HMMFile("H:/MADE1.hmm");
 
   @Test
   public void testParse() throws IOException
   {
-
+  
     pKinase.parse();
-
-    assertEquals(pKinase.hmm.getName(), "Pkinase");
-    assertEquals(pKinase.hmm.getAccessionNumber(), "PF00069.17");
-    assertEquals(pKinase.hmm.getDescription(), "Protein kinase domain");
-    assertEquals(pKinase.hmm.getLength().intValue(), 260);
-    assertNull(pKinase.hmm.getMaxInstanceLength());
-    assertEquals(pKinase.hmm.getAlphabetType(), "amino");
-    assertEquals(pKinase.hmm.referenceAnnotationIsActive(), false);
-    assertEquals(pKinase.hmm.maskValueIsActive(), false);
-    assertEquals(pKinase.hmm.consensusResidueIsActive(), true);
-    assertEquals(pKinase.hmm.consensusStructureIsActive(),
+    HiddenMarkovModel hmm = pKinase.getHMM();
+    assertEquals(hmm.getName(), "Pkinase");
+    assertEquals(hmm.getAccessionNumber(), "PF00069.17");
+    assertEquals(hmm.getDescription(), "Protein kinase domain");
+    assertEquals(hmm.getLength().intValue(), 260);
+    assertNull(hmm.getMaxInstanceLength());
+    assertEquals(hmm.getAlphabetType(), "amino");
+    assertEquals(hmm.referenceAnnotationIsActive(), false);
+    assertEquals(hmm.maskValueIsActive(), false);
+    assertEquals(hmm.consensusResidueIsActive(), true);
+    assertEquals(hmm.consensusStructureIsActive(),
             true);
-    assertEquals(pKinase.hmm.mapIsActive(), true);
-    assertEquals(pKinase.hmm.getDate(), "Thu Jun 16 11:44:06 2011");
-    assertNull(pKinase.hmm.getCommandLineLog());
-    assertEquals(pKinase.hmm.getNumberOfSequences().intValue(), 54);
-    assertEquals(pKinase.hmm.getEffectiveNumberOfSequences(), 3.358521, 4d);
-    assertEquals(pKinase.hmm.getCheckSum().longValue(), 3106786190l);
-    assertEquals(pKinase.hmm.getGatheringThreshold(), "70.30 70.30");
-    assertEquals(pKinase.hmm.getTrustedCutoff(), "70.30 70.30");
-    assertEquals(pKinase.hmm.getNoiseCutoff(), "70.20 70.20");
-
+    assertEquals(hmm.mapIsActive(), true);
+    assertEquals(hmm.getDate(), "Thu Jun 16 11:44:06 2011");
+    assertNull(hmm.getCommandLineLog());
+    assertEquals(hmm.getNumberOfSequences().intValue(), 54);
+    assertEquals(hmm.getEffectiveNumberOfSequences(), 3.358521, 4d);
+    assertEquals(hmm.getCheckSum().longValue(), 3106786190l);
+    assertEquals(hmm.getGatheringThreshold(), "70.30 70.30");
+    assertEquals(hmm.getTrustedCutoff(), "70.30 70.30");
+    assertEquals(hmm.getNoiseCutoff(), "70.20 70.20");
+  
     List<Character> symbols = new ArrayList<>();
     symbols.add('A');
     symbols.add('C');
@@ -74,74 +90,59 @@ public class HMMFileTest {
     symbols.add('V');
     symbols.add('W');
     symbols.add('Y');
-
-    assertEquals(pKinase.hmm.getSymbols(), symbols);
-
-    assertEquals(pKinase.hmm.getMatchEmission(0, 19), 3.43274);
-    assertEquals(pKinase.hmm.getMatchEmission(12, 12), 4.33979);
-    assertEquals(pKinase.hmm.getMatchEmission(23, 7), 3.65600);
-    assertEquals(pKinase.hmm.getMatchEmission(54, 1), 4.76187);
-    assertEquals(pKinase.hmm.getMatchEmission(79, 0), 2.81579);
-    assertEquals(pKinase.hmm.getMatchEmission(100, 0), 1.86496);
-    assertEquals(pKinase.hmm.getMatchEmission(112, 14), 2.77179);
-    assertEquals(pKinase.hmm.getMatchEmission(143, 17), 5.10478);
-    assertEquals(pKinase.hmm.getMatchEmission(156, 4), 4.69372);
-    assertEquals(pKinase.hmm.getMatchEmission(178, 3), 2.52594);
-    assertEquals(pKinase.hmm.getMatchEmission(210, 2), 4.23598);
-    assertEquals(pKinase.hmm.getMatchEmission(260, 19), 3.81122);
-
-    assertEquals(pKinase.hmm.getInsertEmission(2, 1), 4.42225);
-    assertEquals(pKinase.hmm.getInsertEmission(15, 6), 3.72501);
-    assertEquals(pKinase.hmm.getInsertEmission(22, 9), 2.69355);
-    assertEquals(pKinase.hmm.getInsertEmission(57, 2), 2.77519);
-    assertEquals(pKinase.hmm.getInsertEmission(62, 14), 2.89801);
-    assertEquals(pKinase.hmm.getInsertEmission(95, 17), 2.98532);
-    assertEquals(pKinase.hmm.getInsertEmission(105, 4), 3.46354);
-    assertEquals(pKinase.hmm.getInsertEmission(134, 1), 4.42225);
-    assertEquals(pKinase.hmm.getInsertEmission(143, 0), 2.68618);
-    assertEquals(pKinase.hmm.getInsertEmission(152, 16), 2.77519);
-    assertEquals(pKinase.hmm.getInsertEmission(203, 16), 2.77519);
-    assertEquals(pKinase.hmm.getInsertEmission(255, 12), 2.73739);
-
-    assertEquals(pKinase.hmm.getStateTransition(0, 6),
+  
+    assertEquals(hmm.getSymbols(), symbols);
+  
+    assertEquals(getMatchEmission(0, 19, hmm), 0.032298, 0.001d);
+    assertEquals(getMatchEmission(12, 12, hmm), 0.0130, 0.001d);
+    assertEquals(getMatchEmission(23, 7, hmm), 0.02583, 0.001d);
+    assertEquals(getMatchEmission(54, 1, hmm), 0.008549, 0.001d);
+    assertEquals(getMatchEmission(178, 3, hmm), 0.07998, 0.001d);
+    assertEquals(getMatchEmission(210, 2, hmm), 0.014465, 0.001d);
+    assertEquals(getMatchEmission(260, 19, hmm), 0.02213, 0.001d);
+  
+    assertEquals(getInsertEmission(2, 1, hmm), 0.012, 0.001d);
+    assertEquals(getInsertEmission(15, 6, hmm), 0.02411, 0.001d);
+    assertEquals(getInsertEmission(22, 9, hmm), 0.06764, 0.001d);
+    assertEquals(getInsertEmission(57, 2, hmm), 0.0623, 0.001d);
+    assertEquals(getInsertEmission(203, 16, hmm), 0.0623, 0.001d);
+    assertEquals(getInsertEmission(255, 12, hmm), 0.0647, 0.001d);
+  
+    assertEquals(getStateTransition(0, 6, hmm),
             Double.NEGATIVE_INFINITY);
-    assertEquals(pKinase.hmm.getStateTransition(3, 6), 0.95510);
-    assertEquals(pKinase.hmm.getStateTransition(29, 3), 0.61958);
-    assertEquals(pKinase.hmm.getStateTransition(46, 4), 0.77255);
-    assertEquals(pKinase.hmm.getStateTransition(53, 1), 5.01631);
-    assertEquals(pKinase.hmm.getStateTransition(79, 2), 5.73865);
-    assertEquals(pKinase.hmm.getStateTransition(101, 2), 5.73865);
-    assertEquals(pKinase.hmm.getStateTransition(120, 5), 0.48576);
-    assertEquals(pKinase.hmm.getStateTransition(146, 5), 0.70219);
-    assertEquals(pKinase.hmm.getStateTransition(169, 3), 1.23224);
-    assertEquals(pKinase.hmm.getStateTransition(209, 0), 0.01003);
-    assertEquals(pKinase.hmm.getStateTransition(243, 1), 5.01631);
-
-    assertEquals(pKinase.hmm.getNodeAlignmentColumn(3).intValue(), 3);
-    assertEquals(pKinase.hmm.getReferenceAnnotation(7), '-');
-    assertEquals(pKinase.hmm.getConsensusResidue(23), 't');
-    assertEquals(pKinase.hmm.getMaskedValue(30), '-');
-    assertEquals(pKinase.hmm.getConsensusStructure(56), 'S');
-
-    assertEquals(pKinase.hmm.getNodeAlignmentColumn(78).intValue(), 136);
-    assertEquals(pKinase.hmm.getReferenceAnnotation(93), '-');
-    assertEquals(pKinase.hmm.getConsensusResidue(145), 'a');
-    assertEquals(pKinase.hmm.getMaskedValue(183), '-');
-    assertEquals(pKinase.hmm.getConsensusStructure(240), 'H');
-
+    assertEquals(getStateTransition(3, 6, hmm), 0.3848, 0.001d);
+    assertEquals(getStateTransition(29, 3, hmm), 0.5382, 0.001d);
+    assertEquals(getStateTransition(169, 3, hmm), 0.2916, 0.001d);
+    assertEquals(getStateTransition(209, 0, hmm), 0.99, 0.001d);
+    assertEquals(getStateTransition(243, 1, hmm), 0.0066, 0.001d);
+  
+    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(), 135);
+    assertEquals(hmm.getReferenceAnnotation(93), '-');
+    assertEquals(hmm.getConsensusResidue(145), 'a');
+    assertEquals(hmm.getMaskedValue(183), '-');
+    assertEquals(hmm.getConsensusStructure(240), 'H');
+  
   }
-
+  
   @Test
   public void testParseFileProperties() throws IOException
   {
-    FileReader fr = new FileReader(fn3.getDataObject());
+    FileReader fr = new FileReader(
+            new File("test/jalview/io/test_fn3_hmm.txt"));
     BufferedReader br = new BufferedReader(fr);
     fn3.parseFileProperties(br);
+    fn3.parseModel(br); // this is for a later test
     HiddenMarkovModel testHMM = new HiddenMarkovModel();
-    testHMM = fn3.getHmm();
+    testHMM = fn3.getHMM();
     br.close();
     fr.close();
-
+  
     assertEquals(testHMM.getName(), "fn3");
     assertEquals(testHMM.getAccessionNumber(), "PF00041.13");
     assertEquals(testHMM.getDescription(),
@@ -165,48 +166,16 @@ public class HMMFileTest {
     assertEquals(testHMM.getViterbi(), "-9.7737  0.71847");
     assertEquals(testHMM.getMSV(), "-9.4043  0.71847");
     assertEquals(testHMM.getForward(), "-3.8341  0.71847");
-
-    FileReader fr2 = new FileReader(emptyFile.getDataObject());
-    BufferedReader br2 = new BufferedReader(fr2);
-    emptyFile.parseFileProperties(br2);
-    testHMM = emptyFile.getHmm();
-    br2.close();
-    fr2.close();
-
-    assertNull(testHMM.getName());
-    assertNull(testHMM.getAccessionNumber());
-    assertNull(testHMM.getDescription());
-    assertNull(testHMM.getLength());
-    assertNull(testHMM.getMaxInstanceLength());
-    assertNull(testHMM.getAlphabetType());
-    assertEquals(testHMM.referenceAnnotationIsActive(), false);
-    assertEquals(testHMM.maskValueIsActive(), false);
-    assertEquals(testHMM.consensusResidueIsActive(), false);
-    assertEquals(testHMM.consensusStructureIsActive(),
-            false);
-    assertEquals(testHMM.mapIsActive(), false);
-    assertNull(testHMM.getDate());
-    assertNull(testHMM.getCommandLineLog());
-    assertNull(testHMM.getNumberOfSequences());
-    assertNull(testHMM.getEffectiveNumberOfSequences());
-    assertNull(testHMM.getCheckSum());
-    assertNull(testHMM.getGatheringThreshold());
-    assertNull(testHMM.getGatheringThreshold());
-    assertNull(testHMM.getTrustedCutoff());
-    assertNull(testHMM.getTrustedCutoff());
-    assertNull(testHMM.getNoiseCutoff());
-    assertNull(testHMM.getNoiseCutoff());
-    assertNull(testHMM.getViterbi());
-    assertNull(testHMM.getMSV());
-    assertNull(testHMM.getForward());
-
-    FileReader fr3 = new FileReader(made1.getDataObject());
+  
+  
+    FileReader fr3 = new FileReader(
+            new File("test/jalview/io/test_MADE1_hmm.txt"));
     BufferedReader br3 = new BufferedReader(fr3);
     made1.parseFileProperties(br3);
-    testHMM = made1.getHmm();
+    testHMM = made1.getHMM();
     br3.close();
     fr3.close();
-
+  
     assertEquals(testHMM.getName(), "MADE1");
     assertEquals(testHMM.getAccessionNumber(), "DF0000629.2");
     assertEquals(testHMM.getDescription(),
@@ -230,61 +199,59 @@ public class HMMFileTest {
     assertEquals(testHMM.getViterbi(), "-9.3632  0.71858");
     assertEquals(testHMM.getMSV(), "-8.5786  0.71858");
     assertEquals(testHMM.getForward(), "-3.4823  0.71858");
-
+  
+  
   }
-
-  @Test
-  public void testGetTransitionType()
-  {
-
-    assertEquals(fn3.getTransitionType("mm").intValue(), 0);
-    assertEquals(fn3.getTransitionType("mi").intValue(), 1);
-    assertEquals(fn3.getTransitionType("md").intValue(), 2);
-    assertEquals(fn3.getTransitionType("im").intValue(), 3);
-    assertEquals(fn3.getTransitionType("ii").intValue(), 4);
-    assertEquals(fn3.getTransitionType("dm").intValue(), 5);
-    assertEquals(fn3.getTransitionType("dd").intValue(), 6);
-    assertNull(fn3.getTransitionType("df"));
-
-  }
-
+  
   @Test
   public void testFillList()
   {
     Scanner scanner1 = new Scanner("1.3 2.4 5.3 3.9 9.8 4.7 4.3 2.3 6.9");
     ArrayList<Double> filledArray = new ArrayList<>();
+  
+    filledArray.add(0.27253);
+    filledArray.add(0.0907);
+    filledArray.add(0.00499);
+    filledArray.add(0.02024);
+    filledArray.add(0.00005);
+    filledArray.add(0.00909);
+    filledArray.add(0.01357);
+    filledArray.add(0.10026);
+    filledArray.add(0.001);
+  
+    List<Double> testList = HMMFile.fillList(scanner1, 9);
+
+    for (int i = 0; i < 9; i++)
+    {
+      assertEquals(testList.get(i), filledArray.get(i), 0.001d);
 
-    filledArray.add(1.3);
-    filledArray.add(2.4);
-    filledArray.add(5.3);
-    filledArray.add(3.9);
-    filledArray.add(9.8);
-    filledArray.add(4.7);
-    filledArray.add(4.3);
-    filledArray.add(2.3);
-    filledArray.add(6.9);
+    }
 
-    assertEquals(HMMFile.fillList(scanner1, 9), filledArray);
     filledArray.clear();
     scanner1.close();
-
+  
     Scanner scanner2 = new Scanner(
-            "1.346554 5.58756754 35.3523645 12345.3564 1.4");
-    filledArray.add(1.346554);
-    filledArray.add(5.58756754);
-    filledArray.add(35.3523645);
-    filledArray.add(12345.3564);
-    filledArray.add(1.4);
-
-    assertEquals(HMMFile.fillList(scanner2, 5), filledArray);
-    scanner2.close();
-
+            "1.346 5.554 35.345 5.64 1.4");
+    filledArray.add(0.2603);
+    filledArray.add(0.00387);
+    filledArray.add(0d);
+    filledArray.add(0.00355);
+    filledArray.add(0.2466);
+  
+    testList = HMMFile.fillList(scanner2, 5);
+
+    for (int i = 0; i < 5; i++)
+    {
+      assertEquals(testList.get(i), filledArray.get(i), 0.001d);
+    }
+  
   }
-
+  
   @Test
   public void testParseModel() throws IOException
   {
-    FileReader fr = new FileReader(made1.getDataObject());
+    FileReader fr = new FileReader(
+            new File("test/jalview/io/test_MADE1_hmm.txt"));
     BufferedReader br = new BufferedReader(fr);
     HiddenMarkovModel testHMM = new HiddenMarkovModel();
     for (int i = 0; i < 24; i++)
@@ -292,102 +259,156 @@ public class HMMFileTest {
       br.readLine();
     }
     made1.parseModel(br);
-    testHMM = made1.getHmm();
+    testHMM = made1.getHMM();
     br.close();
     fr.close();
-
-    assertEquals(testHMM.getMatchEmission(0, 2), 1.62906);
-    assertEquals(testHMM.getMatchEmission(2, 1), 2.37873);
-    assertEquals(testHMM.getMatchEmission(12, 2), 2.61355);
-    assertEquals(testHMM.getMatchEmission(26, 0), 1.86925);
-    assertEquals(testHMM.getMatchEmission(32, 3), 2.58263);
-    assertEquals(testHMM.getMatchEmission(59, 3), 2.20507);
-    assertEquals(testHMM.getMatchEmission(63, 0), 0.41244);
-    assertEquals(testHMM.getMatchEmission(69, 1), 3.17398);
-    assertEquals(testHMM.getMatchEmission(76, 2), 2.65861);
-
-    assertEquals(testHMM.getInsertEmission(0, 1), 1.38629);
-    assertEquals(testHMM.getInsertEmission(1, 2), 1.38629);
-    assertEquals(testHMM.getInsertEmission(31, 3), 1.28150);
-    assertEquals(testHMM.getInsertEmission(43, 0), 1.32290);
-    assertEquals(testHMM.getInsertEmission(48, 2), 1.52606);
-    assertEquals(testHMM.getInsertEmission(52, 1), 1.62259);
-    assertEquals(testHMM.getInsertEmission(67, 0), 1.38141);
-    assertEquals(testHMM.getInsertEmission(70, 3), 1.38629);
-    assertEquals(testHMM.getInsertEmission(80, 3), 1.38629);
-
-    assertEquals(testHMM.getStateTransition(2, 0), 0.03725);
-    assertEquals(testHMM.getStateTransition(6, 1), 3.89715);
-    assertEquals(testHMM.getStateTransition(9, 3), 1.38021);
-    assertEquals(testHMM.getStateTransition(20, 4), 0.23815);
-    assertEquals(testHMM.getStateTransition(34, 6), 0.33363);
-    assertEquals(testHMM.getStateTransition(46, 5), 1.05474);
-    assertEquals(testHMM.getStateTransition(57, 6), 0.31164);
-    assertEquals(testHMM.getStateTransition(68, 2), 3.99242);
-    assertEquals(testHMM.getStateTransition(80, 6),
+  
+    assertEquals(getMatchEmission(0, 2, testHMM), 0.1961, 0.001d);
+    assertEquals(getMatchEmission(2, 1, testHMM), 0.09267, 0.001d);
+    assertEquals(getMatchEmission(12, 2, testHMM), 0.07327, 0.001d);
+    assertEquals(getMatchEmission(69, 1, testHMM), 0.04184, 0.001d);
+    assertEquals(getMatchEmission(76, 2, testHMM), 0.07, 0.001d);
+  
+    assertEquals(getInsertEmission(0, 1, testHMM), 0.25, 0.001d);
+    assertEquals(getInsertEmission(1, 2, testHMM), 0.25, 0.001d);
+    assertEquals(getInsertEmission(31, 3, testHMM), 0.2776, 0.001d);
+    assertEquals(getInsertEmission(70, 3, testHMM), 0.25, 0.001d);
+    assertEquals(getInsertEmission(80, 3, testHMM), 0.25, 0.001d);
+
+    assertEquals(getStateTransition(2, 0, testHMM), 0.9634, 0.001d);
+    assertEquals(getStateTransition(6, 1, testHMM), 0.0203, 0.001d);
+    assertEquals(getStateTransition(9, 3, testHMM), 0.2515, 0.001d);
+    assertEquals(getStateTransition(20, 4, testHMM), 0.78808, 0.001d);
+    assertEquals(getStateTransition(68, 2, testHMM), 0.01845, 0.001d);
+    assertEquals(getStateTransition(80, 6, testHMM),
             Double.NEGATIVE_INFINITY);
-
+  
   }
-
+  
   @Test
   public void testParseAnnotations()
   {
-    HMMFile testFile = new HMMFile("H:/EmptyFile.hmm");
-    testFile.hmm.getNodes().add(new HMMNode());
-    testFile.hmm.getNodes().add(new HMMNode());
-
-    testFile.hmm.setConsensusResidueStatus(true);
-    testFile.hmm.setMAPStatus(true);
-    testFile.hmm.setReferenceAnnotationStatus(true);
-    testFile.hmm.setConsensusStructureStatus(true);
-    testFile.hmm.setMaskedValueStatus(true);
+    HMMFile testFile = new HMMFile();
+    testFile.getHMM().getNodes().add(new HMMNode());
+    testFile.getHMM().getNodes().add(new HMMNode());
+    testFile.getHMM().getNodes().add(new HMMNode());
+  
+  
+    testFile.getHMM().setConsensusResidueStatus(true);
+    testFile.getHMM().setMAPStatus(true);
+    testFile.getHMM().setReferenceAnnotationStatus(true);
+    testFile.getHMM().setConsensusStructureStatus(true);
+    testFile.getHMM().setMaskedValueStatus(true);
     Scanner scanner = new Scanner("1345 t t t t");
-    testFile.parseAnnotations(scanner, 0);
-    assertEquals(testFile.hmm.getNodeAlignmentColumn(0).intValue(), 1345);
-    assertEquals(testFile.hmm.getConsensusResidue(0), 't');
-    assertEquals(testFile.hmm.getReferenceAnnotation(0), 't');
-    assertEquals(testFile.hmm.getMaskedValue(0), 't');
-    assertEquals(testFile.hmm.getConsensusStructure(0), 't');
-
-    scanner.close();
-
-    testFile.hmm.setConsensusResidueStatus(true);
-    testFile.hmm.setMAPStatus(false);
-    testFile.hmm.setReferenceAnnotationStatus(true);
-    testFile.hmm.setConsensusStructureStatus(false);
-    testFile.hmm.setMaskedValueStatus(false);
+    testFile.parseAnnotations(scanner, 1);
+  
+    testFile.getHMM().setConsensusResidueStatus(true);
+    testFile.getHMM().setMAPStatus(false);
+    testFile.getHMM().setReferenceAnnotationStatus(true);
+    testFile.getHMM().setConsensusStructureStatus(false);
+    testFile.getHMM().setMaskedValueStatus(false);
     Scanner scanner2 = new Scanner("- y x - -");
-    testFile.parseAnnotations(scanner2, 1);
-    assertNull(testFile.hmm.getNodeAlignmentColumn(1));
-    assertEquals(testFile.hmm.getConsensusResidue(1), 'y');
-    assertEquals(testFile.hmm.getReferenceAnnotation(1), 'x');
-    assertEquals(testFile.hmm.getMaskedValue(1), '-');
-    assertEquals(testFile.hmm.getConsensusStructure(1), '-');
-
-    scanner2.close();
+    testFile.parseAnnotations(scanner2, 2);
+  
+    HiddenMarkovModel hmm = testFile.getHMM();
+  
+    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(1344).intValue(), 1);
+  
+    scanner.close();
+  
   }
+  
+  /**
+   * tests to see if file produced by the output matches the file from the input
+   * 
+   * @throws IOException
+   */
 
-  @Test(priority = 2)
+
+  @Test(priority = 3)
   public void testExportFile() throws IOException
   {
-    File file = new File(fn3.getDataObject());
-    FileReader fr = new FileReader(file);
-    BufferedReader br = new BufferedReader(fr);
-    for (int i = 0; i < 23; i++)
+    pKinase.exportFile("test/jalview/io/test_export_hmm.txt");
+    HMMFile pKinaseClone = new HMMFile(
+            new FileParse("test/jalview/io/test_export_hmm.txt",
+                    DataSourceType.FILE));
+    pKinaseClone.parse();
+    HiddenMarkovModel pKinaseHMM = new HiddenMarkovModel();
+    HiddenMarkovModel pKinaseCloneHMM = new HiddenMarkovModel();
+    pKinaseHMM = pKinase.getHMM();
+    pKinaseCloneHMM = pKinaseClone.getHMM();
+  
+    for (int i = 0; i < pKinaseHMM.getLength(); i++)
     {
-      br.readLine();
+      List<Double> list1;
+      List<Double> list2;
+      boolean result;
+  
+      list1 = pKinaseHMM.getNode(i).getMatchEmissions();
+      list2 = pKinaseCloneHMM.getNode(i).getMatchEmissions();
+  
+      result = checkIfListsAreIdentical(list1, list2);
+      assertEquals(result, true);
+  
+      list1 = pKinaseHMM.getNode(i).getInsertEmissions();
+      list2 = pKinaseCloneHMM.getNode(i).getInsertEmissions();
+  
+      result = checkIfListsAreIdentical(list1, list2);
+      assertEquals(result, true);
+  
+      list1 = pKinaseHMM.getNode(i).getStateTransitions();
+      list2 = pKinaseCloneHMM.getNode(i).getStateTransitions();
+  
+      result = checkIfListsAreIdentical(list1, list2);
+      assertEquals(result, true);
+  
+      if (i > 0)
+      {
+        int alignColumn1;
+        int alignColumn2;
+  
+        alignColumn1 = pKinaseHMM.getNodeAlignmentColumn(i);
+        alignColumn2 = pKinaseCloneHMM.getNodeAlignmentColumn(i);
+  
+        assertEquals(alignColumn1, alignColumn2);
+  
+        char annotation1;
+        char annotation2;
+  
+        annotation1 = pKinaseHMM.getReferenceAnnotation(i);
+        annotation2 = pKinaseCloneHMM.getReferenceAnnotation(i);
+  
+        assertEquals(annotation1, annotation2);
+  
+        annotation1 = pKinaseHMM.getConsensusResidue(i);
+        annotation2 = pKinaseCloneHMM.getConsensusResidue(i);
+  
+        assertEquals(annotation1, annotation2);
+      }
+  
     }
-    fn3.parseModel(br);
-    fn3.exportFile("H:/WriteFileTest.hmm");
+  
   }
-
+  
   @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",
         "DESC  Fibronectin type III domain", "LENG  86", "ALPH  amino",
@@ -397,20 +418,160 @@ public class HMMFileTest {
         "NC    7.90 7.90", "STATS LOCAL MSV       -9.4043  0.71847",
         "STATS LOCAL VITERBI   -9.7737  0.71847",
         "STATS LOCAL FORWARD   -3.8341  0.71847" };
-
+  
     for (String value : expected)
     {
       assertEquals(testScanner.nextLine(), value);
     }
-
+  
     testScanner.close();
   }
-
-  public moveAheadBy(Scanner scanner, int nodeChange, int indexChange)
+  
+  @Test(priority = 2)
+  public void testAppendModel() throws FileNotFoundException
   {
-    for (int y = 0; y < nodeChange; y++)
+    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");
+    assertEquals(findValue(19, 33, 2, string), "4.58477");
+    assertEquals(findValue(20, 64, 2, string), "3.61505");
+    assertEquals(findValue(3, 72, 3, string), "6.81068");
+    assertEquals(findValue(10, 80, 2, string), "2.69355");
+    assertEquals(findValue(16, 65, 1, string), "2.81003");
+    assertEquals(findValue(14, 3, 1, string), "2.69012");
+    assertEquals(findValue(11, 32, 1, string), "4.34805");
+  
+  }
+  
+  /**
+   * 
+   * @param symbolIndex
+   *          index of symbol being searched. First symbol has index 1.
+   * @param nodeIndex
+   *          index of node being searched. Begin node has index 0. First node
+   *          has index 1.
+   * @param line
+   *          index of line being searched in node. First line has index 1.
+   * @param model
+   *          string model being searched
+   * @return value at specified position
+   */
+
+  public String findValue(int symbolIndex, int nodeIndex, int line,
+          String model)
+  {
+  
+    String value = "";
+    Scanner scanner = new Scanner(model);
+    scanner.nextLine();
+    scanner.nextLine();
+  
+    for (int lineIndex = 0; lineIndex < line - 1; lineIndex++)
+    {
+      scanner.nextLine();
+    }
+    for (int node = 0; node < nodeIndex; node++)
+    {
+      scanner.nextLine();
+      scanner.nextLine();
+      scanner.nextLine();
+    }
+  
+    for (int symbol = 0; symbol < symbolIndex; symbol++)
     {
-      
+      value = scanner.next();
+      if ("COMPO".equals(value))
+      {
+        scanner.next();
+      }
+      else if (value.length() < 7)
+      {
+        scanner.next();
+      }
+  
     }
+    return value;
+  
   }
+  
+  public boolean checkIfListsAreIdentical(List<Double> list1,
+          List<Double> list2)
+  {
+    boolean isDifferent = false;
+    for (int i = 0; i < list1.size(); i++)
+    {
+      Double entry1;
+      Double entry2;
+      entry1 = list1.get(i);
+      entry2 = list2.get(i);
+      if (!(entry1 == entry2))
+      {
+        isDifferent = true;
+      }
+    }
+    return isDifferent;
+  }
+
+  /**
+   * gets the match emission at a node for a symbol
+   * 
+   * @param nodeIndex
+   *          position of node in model
+   * @param symbolIndex
+   *          index of symbol being searched
+   * @return negative log probability of a match emission of the given symbol
+   */
+  public double getMatchEmission(int nodeIndex, int symbolIndex,
+          HiddenMarkovModel hmm)
+  {
+    double value = hmm.getNodes().get(nodeIndex).getMatchEmissions()
+            .get(symbolIndex);
+    return value;
+  }
+
+  /**
+   * gets the insert emission at a node for a symbol
+   * 
+   * @param nodeIndex
+   *          position of node in model
+   * @param symbolIndex
+   *          index of symbol being searched
+   * @return negative log probability of an insert emission of the given symbol
+   */
+  public double getInsertEmission(int nodeIndex, int symbolIndex,
+          HiddenMarkovModel hmm)
+  {
+    double value = hmm.getNodes().get(nodeIndex).getInsertEmissions()
+            .get(symbolIndex);
+    return value;
+  }
+
+  /**
+   * gets the state transition at a node for a specific transition
+   * 
+   * @param nodeIndex
+   *          position of node in model
+   * @param transitionIndex
+   *          index of stransition being searched
+   * @return negative log probability of a state transition of the given type
+   */
+  public double getStateTransition(int nodeIndex, int transitionIndex,
+          HiddenMarkovModel hmm)
+  {
+    double value = hmm.getNodes().get(nodeIndex).getStateTransitions()
+            .get(transitionIndex);
+    return value;
+  }
+
 }
+