JAL-2616 add test class and test files for analyser
authortzvanaalten <tzvanaalten@LS30916.ad.lifesci.dundee.ac.uk>
Mon, 24 Jul 2017 12:40:28 +0000 (13:40 +0100)
committertzvanaalten <tzvanaalten@LS30916.ad.lifesci.dundee.ac.uk>
Mon, 24 Jul 2017 12:40:28 +0000 (13:40 +0100)
test/jalview/util/Binned.csv [new file with mode: 0644]
test/jalview/util/HMMProbabilityDistributionAnalyserTest.java
test/jalview/util/Raw.csv [new file with mode: 0644]
test/jalview/util/test_Fams_for_probability_analysis [new file with mode: 0644]
test/jalview/util/test_hmms_for_probability_analysis [new file with mode: 0644]

diff --git a/test/jalview/util/Binned.csv b/test/jalview/util/Binned.csv
new file mode 100644 (file)
index 0000000..f140646
--- /dev/null
@@ -0,0 +1,4 @@
+1.8, 4.53
+3.4, 2.65
+0, 5.4
+6.4, 10.8
\ No newline at end of file
index 60f6c89..815ea66 100644 (file)
@@ -1,13 +1,22 @@
 package jalview.util;
 
 import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
 
+import jalview.datamodel.HMMNode;
+import jalview.datamodel.HiddenMarkovModel;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceI;
+import jalview.io.DataSourceType;
+import jalview.io.FileParse;
 
 import java.io.BufferedReader;
 import java.io.FileReader;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
 
 import org.testng.annotations.Test;
 
@@ -20,8 +29,8 @@ public class HMMProbabilityDistributionAnalyserTest {
   {
 
     BufferedReader br = new BufferedReader(new FileReader(
-            "test/utils/test_Fams_for_probability_analysis.txt"));
-    analyser.moveLocationBy(2, br);
+            "test/jalview/util/test_Fams_for_probability_analysis"));
+    analyser.moveLocationBy(1, br);
 
     String line = br.readLine();
     assertEquals(line, "# STOCKHOLM 1.0");
@@ -35,14 +44,78 @@ public class HMMProbabilityDistributionAnalyserTest {
   @Test
   public void testCountValidResidues()
   {
+    analyser.sequences = new Vector<>();
+    analyser.hmm = new HiddenMarkovModel();
+    analyser.hmm.addFileProperty("LENG", "8");
+
+    List<HMMNode> nodes = new ArrayList<>();
+    nodes.add(new HMMNode());
+    for (int i = 1; i < 9; i++)
+    {
+      HMMNode node = new HMMNode();
+      node.setAlignmentColumn(i);
+      nodes.add(node);
+
+    }
+    analyser.hmm.setNodes(nodes);
+
     SequenceI[] sequence = new Sequence[] {
-        new Sequence("seq1", "ATGWWSCF"), new Sequence("seq1", "GGWMMKI"),
-        new Sequence("seq1", "--.ATccc") };
+        new Sequence("seq1", "ATGWWSCF"), new Sequence("seq2", "GGMKI"),
+        new Sequence("seq3", "--.ATccGc") };
     analyser.sequences.add(sequence[0]);
     analyser.sequences.add(sequence[1]);
     analyser.sequences.add(sequence[2]);
 
     int count = analyser.countValidResidues();
-    assertEquals(count, 17);
+    assertEquals(count, 16);
+  }
+
+  @Test(priority = 0)
+  public void testReadBinned() throws IOException
+  {
+    analyser.readBinned("test/jalview/util/");
+    Map<String, Double> map = analyser.binned;
+    assertEquals(map.get("1.8"), 4.53);
+    assertEquals(map.get("3.4"), 2.65);
+    assertEquals(map.get("6.4"), 10.8);
+    assertEquals(map.get("0"), 5.4);
+  }
+
+  @Test
+  public void testReadRaw() throws IOException
+  {
+    analyser.readRaw("test/jalview/util/");
+    List<ArrayList<Double>> list = analyser.raw;
+
+    assertEquals(list.get(0).get(0), 1.43);
+    assertNull(list.get(0).get(2));
+    assertEquals(list.get(1).get(1), 1.2);
+    assertEquals(list.get(2).get(0), 5.6);
+    assertEquals(list.get(2).get(2), 6.8);
+
+  }
+
+  @Test(priority = 1)
+  public void testProcessData() throws IOException
+  {
+    analyser.keepRaw = true;
+    BufferedReader brFam = new BufferedReader(new FileReader(
+            "test/jalview/util/test_Fams_for_probability_analysis"));
+    BufferedReader brHMM = new BufferedReader(new FileReader(
+            "test/jalview/util/test_HMMs_for_probability_analysis"));
+    FileParse parserFam = new FileParse(brFam, "", DataSourceType.FILE);
+    FileParse parserHMM = new FileParse(brHMM, "", DataSourceType.FILE);
+    analyser.readStockholm(parserFam);
+    analyser.readHMM(parserHMM);
+    analyser.processData(6);
+    Map<String, Double> map = analyser.binned;
+    List<ArrayList<Double>> list = analyser.raw;
+    assertEquals(map.get("1.8"), 4.863, 0.001d);
+    assertEquals(map.get("3.4"), 2.65);
+    assertEquals(map.get("0"), 5.4);
+    assertEquals(map.get("6.4"), 10.8);
+    assertEquals(map.get("1.4"), 0.166667, 0.00001d);
+    assertEquals(map.get("4.4"), 0.5);
+
   }
 }
diff --git a/test/jalview/util/Raw.csv b/test/jalview/util/Raw.csv
new file mode 100644 (file)
index 0000000..83d3452
--- /dev/null
@@ -0,0 +1,4 @@
+Seq1, Seq2, Seq3
+1.43, 2.34, 5.6,
+EMPTY, 1.2, 0.05,
+EMPTY, 5.4, 6.8,
\ No newline at end of file
diff --git a/test/jalview/util/test_Fams_for_probability_analysis b/test/jalview/util/test_Fams_for_probability_analysis
new file mode 100644 (file)
index 0000000..74fbab0
--- /dev/null
@@ -0,0 +1,13 @@
+# STOCKHOLM 1.0
+seq1 AW
+seq2 GW
+seq3 AW
+//
+# STOCKHOLM 1.0
+seq1 ATW
+seq2 ATI
+//
+# STOCKHOLM 1.0
+seq1 R-WW
+seq2 RAWW
+//
\ No newline at end of file
diff --git a/test/jalview/util/test_hmms_for_probability_analysis b/test/jalview/util/test_hmms_for_probability_analysis
new file mode 100644 (file)
index 0000000..b70d42b
--- /dev/null
@@ -0,0 +1,99 @@
+HMMER3/f [3.1b2 | February 2015]
+NAME  test1
+LENG  4
+ALPH  amino
+RF    no
+MM    no
+CONS  yes
+CS    no
+MAP   yes
+DATE  Fri Jul 21 06:35:06 2017
+NSEQ  3
+EFFN  3.000000
+CKSUM 657102310
+STATS LOCAL MSV       -5.0223  0.82341
+STATS LOCAL VITERBI   -4.9569  0.82341
+STATS LOCAL FORWARD   -2.0282  0.82341
+HMM          A        C        D        E        F        G        H        I        K        L        M        N        P        Q        R        S        T        V        W        Y   
+            m->m     m->i     m->d     i->m     i->i     d->m     d->d
+  COMPO   1.94296  5.20658  4.78882  4.52987  4.66525  2.54188  5.19553  2.25221  4.08549  3.87133  5.00250  4.55734  4.73106  4.65220  2.77287  3.67799  1.53923  3.75384  1.48526  4.84023
+          2.68618  4.42225  2.77519  2.73123  3.46354  2.40513  3.72494  3.29354  2.67741  2.69355  4.24690  2.90347  2.73739  3.18146  2.89801  2.37887  2.77519  2.98518  4.58477  3.61503
+          0.01083  4.92694  5.64929  0.61958  0.77255  0.00000        *
+      1   0.67027  4.79120  4.60974  4.51892  5.43734  1.28080  5.43621  4.90028  4.64310  4.61059  5.39837  4.28688  4.41468  4.80804  4.79047  3.08135  3.44468  4.10506  6.74908  5.67939      1 A - - -
+          2.68618  4.42225  2.77519  2.73123  3.46354  2.40513  3.72494  3.29354  2.67741  2.69355  4.24690  2.90347  2.73739  3.18146  2.89801  2.37887  2.77519  2.98518  4.58477  3.61503
+          0.01083  4.92694  5.64929  0.61958  0.77255  0.48576  0.95510
+      2   5.43405  6.34487  5.85697  5.84679  4.39288  5.10370  5.65594  5.70664  5.69821  4.87848  6.25251  5.89664  5.70261  6.00722  5.60902  5.64576  5.80049  5.59366  0.08910  4.36301      2 W - - -
+          2.68618  4.42225  2.77519  2.73123  3.46354  2.40513  3.72494  3.29354  2.67741  2.69355  4.24690  2.90347  2.73739  3.18146  2.89801  2.37887  2.77519  2.98518  4.58477  3.61503
+          0.01083  4.92694  5.64929  0.61958  0.77255  0.48576  0.95510
+      3   3.42384  5.23617  4.84601  4.77568  5.39247  4.01365  5.64153  4.72950  4.75585  4.52264  5.55782  4.69647  4.81267  5.08969  4.87301  3.64217  0.20934  4.25217  6.65833  5.63018      3 T - - -
+          2.68618  4.42225  2.77519  2.73123  3.46354  2.40513  3.72494  3.29354  2.67741  2.69355  4.24690  2.90347  2.73739  3.18146  2.89801  2.37887  2.77519  2.98518  4.58477  3.61503
+          0.01083  4.92694  5.64929  0.61958  0.77255  0.48576  0.95510
+      4   3.53954  5.09963  4.71395  4.06038  4.20429  4.44020  4.65482  0.90152  3.16536  2.96072  4.13056  4.31689  4.83725  3.95143  1.46549  3.86829  3.78084  2.85654  5.74911  4.54685      4 i - - -
+          2.68618  4.42225  2.77519  2.73123  3.46354  2.40513  3.72494  3.29354  2.67741  2.69355  4.24690  2.90347  2.73739  3.18146  2.89801  2.37887  2.77519  2.98518  4.58477  3.61503
+          0.00730  4.92341        *  0.61958  0.77255  0.00000        *
+//
+HMMER3/f [3.1b2 | February 2015]
+NAME  test2
+LENG  3
+ALPH  amino
+RF    no
+MM    no
+CONS  yes
+CS    no
+MAP   yes
+DATE  Fri Jul 21 06:36:50 2017
+NSEQ  2
+EFFN  2.000000
+CKSUM 777554360
+STATS LOCAL MSV       -5.2452  0.95763
+STATS LOCAL VITERBI   -5.2886  0.95763
+STATS LOCAL FORWARD   -1.5134  0.95763
+HMM          A        C        D        E        F        G        H        I        K        L        M        N        P        Q        R        S        T        V        W        Y   
+            m->m     m->i     m->d     i->m     i->i     d->m     d->d
+  COMPO   1.33364  4.79082  4.44132  4.24796  3.91456  3.75718  4.85762  2.23342  4.16821  3.09137  4.29744  4.25088  4.41741  4.46803  4.31080  3.33397  1.39376  3.21010  2.54819  4.14914
+          2.68618  4.42225  2.77519  2.73123  3.46354  2.40513  3.72494  3.29354  2.67741  2.69355  4.24690  2.90347  2.73739  3.18146  2.89801  2.37887  2.77519  2.98518  4.58477  3.61503
+          0.01467  4.62483  5.34718  0.61958  0.77255  0.00000        *
+      1   0.32372  4.76536  4.42980  4.32857  5.00499  3.55951  5.22620  4.27004  4.37081  4.10495  5.08789  4.22499  4.36948  4.63911  4.51684  3.12947  3.46009  3.76842  6.33337  5.25783      1 A - - -
+          2.68618  4.42225  2.77519  2.73123  3.46354  2.40513  3.72494  3.29354  2.67741  2.69355  4.24690  2.90347  2.73739  3.18146  2.89801  2.37887  2.77519  2.98518  4.58477  3.61503
+          0.01467  4.62483  5.34718  0.61958  0.77255  0.48576  0.95510
+      2   3.04414  4.87155  4.35068  4.21532  4.89213  3.66881  5.13994  4.14202  4.17893  3.96810  5.00600  4.23490  4.44590  4.53729  4.35178  3.25814  0.35496  3.73038  6.23308  5.12388      2 T - - -
+          2.68618  4.42225  2.77519  2.73123  3.46354  2.40513  3.72494  3.29354  2.67741  2.69355  4.24690  2.90347  2.73739  3.18146  2.89801  2.37887  2.77519  2.98518  4.58477  3.61503
+          0.01467  4.62483  5.34718  0.61958  0.77255  0.48576  0.95510
+      3   3.41901  4.77187  4.98694  4.49106  3.10447  4.49364  4.52024  1.21391  4.22709  2.30875  3.57865  4.53952  4.83367  4.43564  4.31127  3.88439  3.66452  2.61326  1.44329  3.34125      3 i - - -
+          2.68618  4.42225  2.77519  2.73123  3.46354  2.40513  3.72494  3.29354  2.67741  2.69355  4.24690  2.90347  2.73739  3.18146  2.89801  2.37887  2.77519  2.98518  4.58477  3.61503
+          0.00990  4.62006        *  0.61958  0.77255  0.00000        *
+//
+HMMER3/f [3.1b2 | February 2015]
+NAME  test3
+LENG  4
+ALPH  amino
+RF    no
+MM    no
+CONS  yes
+CS    no
+MAP   yes
+DATE  Fri Jul 21 06:37:01 2017
+NSEQ  2
+EFFN  2.000000
+CKSUM 986955970
+STATS LOCAL MSV       -5.4578  0.80004
+STATS LOCAL VITERBI   -5.2499  0.80004
+STATS LOCAL FORWARD   -2.1856  0.80004
+HMM          A        C        D        E        F        G        H        I        K        L        M        N        P        Q        R        S        T        V        W        Y   
+            m->m     m->i     m->d     i->m     i->i     d->m     d->d
+  COMPO   2.16700  5.33023  4.57707  4.32329  4.15728  4.03215  4.83242  4.49728  3.73978  4.00181  5.18156  4.45520  4.63709  4.41734  1.53081  3.84281  4.10073  4.20172  0.82417  4.15750
+          2.68618  4.42225  2.77519  2.73123  3.46354  2.40513  3.72494  3.29354  2.67741  2.69355  4.24690  2.90347  2.73739  3.18146  2.89801  2.37887  2.77519  2.98518  4.58477  3.61503
+          0.01467  4.62483  5.34718  0.61958  0.77255  0.00000        *
+      1   4.09153  5.75008  4.67229  4.09411  5.31638  4.34678  4.67762  4.97541  2.93879  4.35023  5.37643  4.37234  4.85576  3.90366  0.27042  4.17197  4.33362  4.67489  6.11461  5.14175      1 R - - -
+          2.68618  4.42225  2.77519  2.73123  3.46354  2.40513  3.72494  3.29354  2.67741  2.69355  4.24690  2.90347  2.73739  3.18146  2.89801  2.37887  2.77519  2.98518  4.58477  3.61503
+          0.39762  4.62483  1.14482  0.61958  0.77255  0.48576  0.95510
+      2   0.58385  4.42717  3.89187  3.72118  4.47383  3.23815  4.69159  3.65968  3.74862  3.52210  4.52478  3.76053  4.01438  4.05655  3.96007  2.78076  3.08518  3.24526  5.86063  4.71068      2 A - - -
+          2.68618  4.42225  2.77519  2.73123  3.46354  2.40513  3.72494  3.29354  2.67741  2.69355  4.24690  2.90347  2.73739  3.18146  2.89801  2.37887  2.77519  2.98518  4.58477  3.61503
+          0.02145  4.24866  4.97100  0.61958  0.77255  0.27360  1.42978
+      3   4.82318  5.87391  5.36844  5.28961  3.81117  4.70308  5.10523  4.98084  5.06729  4.21822  5.56037  5.33222  5.28501  5.40387  5.04111  5.02415  5.17266  4.88017  0.16601  3.78547      3 W - - -
+          2.68618  4.42225  2.77519  2.73123  3.46354  2.40513  3.72494  3.29354  2.67741  2.69355  4.24690  2.90347  2.73739  3.18146  2.89801  2.37887  2.77519  2.98518  4.58477  3.61503
+          0.01467  4.62483  5.34718  0.61958  0.77255  0.48576  0.95510
+      4   4.82318  5.87391  5.36844  5.28961  3.81117  4.70308  5.10523  4.98084  5.06729  4.21822  5.56037  5.33222  5.28501  5.40387  5.04111  5.02415  5.17266  4.88017  0.16601  3.78547      4 W - - -
+          2.68618  4.42225  2.77519  2.73123  3.46354  2.40513  3.72494  3.29354  2.67741  2.69355  4.24690  2.90347  2.73739  3.18146  2.89801  2.37887  2.77519  2.98518  4.58477  3.61503
+          0.00990  4.62006        *  0.61958  0.77255  0.00000        *
+//
\ No newline at end of file