3 import static org.testng.Assert.assertEquals;
4 import static org.testng.Assert.assertNull;
6 import jalview.datamodel.HMMNode;
7 import jalview.datamodel.HiddenMarkovModel;
8 import jalview.datamodel.Sequence;
9 import jalview.datamodel.SequenceI;
11 import java.io.BufferedReader;
12 import java.io.FileReader;
13 import java.io.IOException;
14 import java.util.ArrayList;
15 import java.util.List;
17 import java.util.Vector;
19 import org.testng.annotations.Test;
21 public class HMMProbabilityDistributionAnalyserTest {
23 HMMProbabilityDistributionAnalyser analyser = new HMMProbabilityDistributionAnalyser();
26 public void testMoveToFile() throws IOException
29 BufferedReader br = new BufferedReader(new FileReader(
30 "test/jalview/util/test_Fams_for_probability_analysis"));
31 analyser.moveLocationBy(1, br);
33 String line = br.readLine();
34 assertEquals(line, "# STOCKHOLM 1.0");
36 assertEquals(line, "seq1 ATW");
38 assertEquals(line, "seq2 ATI");
43 public void testCountValidResidues()
45 analyser.sequences = new Vector<>();
46 analyser.hmm = new HiddenMarkovModel();
47 analyser.hmm.addFileProperty("LENG", "8");
49 List<HMMNode> nodes = new ArrayList<>();
50 nodes.add(new HMMNode());
51 for (int i = 1; i < 9; i++)
53 HMMNode node = new HMMNode();
54 node.setAlignmentColumn(i - 1);
58 analyser.hmm.setNodes(nodes);
60 SequenceI[] sequence = new Sequence[] {
61 new Sequence("seq1", "ATGWWSCF"), new Sequence("seq2", "GGMKI"),
62 new Sequence("seq3", "--.ATccGc") };
63 analyser.sequences.add(sequence[0]);
64 analyser.sequences.add(sequence[1]);
65 analyser.sequences.add(sequence[2]);
67 int count = analyser.countValidResidues();
68 assertEquals(count, 16);
72 public void testReadBinned() throws IOException
74 analyser.readBinned("test/jalview/util/");
75 Map<String, Double> map = analyser.binned;
76 assertEquals(map.get("1.8"), 4.53);
77 assertEquals(map.get("3.4"), 2.65);
78 assertEquals(map.get("6.4"), 10.8);
79 assertEquals(map.get("0"), 5.4);
83 public void testReadRaw() throws IOException
85 analyser.readRaw("test/jalview/util/");
86 List<ArrayList<Double>> list = analyser.raw;
88 assertEquals(list.get(0).get(0), 1.43);
89 assertNull(list.get(0).get(2));
90 assertEquals(list.get(1).get(1), 1.2);
91 assertEquals(list.get(2).get(0), 5.6);
92 assertEquals(list.get(2).get(2), 6.8);
97 public void testProcessData() throws IOException
99 analyser.keepRaw = true;
100 BufferedReader brFam = new BufferedReader(new FileReader(
101 "test/jalview/util/test_Fams_for_probability_analysis"));
102 BufferedReader brHMM = new BufferedReader(new FileReader(
103 "test/jalview/util/test_HMMs_for_probability_analysis"));
104 analyser.readStockholm(brFam);
105 analyser.readHMM(brHMM);
106 analyser.processData(6);
107 Map<String, Double> map = analyser.binned;
108 List<ArrayList<Double>> list = analyser.raw;
109 assertEquals(map.get("1.8"), 4.863, 0.001d);
110 assertEquals(map.get("3.4"), 2.65);
111 assertEquals(map.get("0"), 5.4);
112 assertEquals(map.get("6.4"), 10.8);
113 assertEquals(map.get("1.4"), 0.166667, 0.00001d);
114 assertEquals(map.get("4.4"), 0.5);