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 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; import junit.extensions.PA; public class HMMProbabilityDistributionAnalyserTest { HMMProbabilityDistributionAnalyser analyser = new HMMProbabilityDistributionAnalyser(); @Test public void testMoveToFile() throws IOException { BufferedReader br = new BufferedReader(new FileReader( "test/jalview/util/test_Fams_for_probability_analysis")); analyser.moveLocationBy(1, br); String line = br.readLine(); assertEquals(line, "# STOCKHOLM 1.0"); line = br.readLine(); assertEquals(line, "seq1 ATW"); line = br.readLine(); assertEquals(line, "seq2 ATI"); } @Test public void testCountValidResidues() { analyser.sequences = new Vector<>(); analyser.hmm = new HiddenMarkovModel(); analyser.hmm.setProperty("LENG", "8"); List nodes = new ArrayList<>(); nodes.add(new HMMNode()); for (int i = 1; i < 9; i++) { HMMNode node = new HMMNode(); node.setResidueNumber(i - 1); nodes.add(node); } PA.setValue(analyser.hmm, "nodes", nodes); SequenceI[] sequence = new Sequence[] { 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, 16); } @Test(priority = 0) public void testReadBinned() throws IOException { analyser.readBinned("test/jalview/util/"); Map 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> 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")); analyser.readStockholm(brFam); analyser.readHMM(brHMM); analyser.processData(6); Map map = analyser.binned; List> 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); } }