c92213305699eb4dfcc6986fab555832f8df05c1
[jalview.git] / test / jalview / hmmer / HMMERTest.java
1 package jalview.hmmer;
2
3 import static org.testng.Assert.assertEquals;
4 import static org.testng.Assert.assertNotEquals;
5 import static org.testng.Assert.assertNotNull;
6 import static org.testng.Assert.fail;
7
8 import jalview.bin.Jalview;
9 import jalview.datamodel.Alignment;
10 import jalview.datamodel.AlignmentI;
11 import jalview.datamodel.HiddenMarkovModel;
12 import jalview.datamodel.SequenceI;
13 import jalview.gui.AlignFrame;
14 import jalview.gui.Desktop;
15 import jalview.io.DataSourceType;
16 import jalview.io.FastaFile;
17 import jalview.io.FileParse;
18 import jalview.ws.params.ArgumentI;
19
20 import java.io.IOException;
21 import java.net.MalformedURLException;
22 import java.util.ArrayList;
23 import java.util.List;
24
25 import org.testng.annotations.AfterClass;
26 import org.testng.annotations.BeforeClass;
27 import org.testng.annotations.Test;
28
29
30 public class HMMERTest {
31
32   AlignFrame frame;
33
34   @BeforeClass(alwaysRun = true)
35   public static void setUpBeforeClass() throws Exception
36   {
37     Jalview.main(
38             new String[]
39     { "-noquestionnaire", "-nonews", "-props",
40         "test/jalview/hmmer/testProps.jvprops" });
41   }
42
43   @AfterClass(alwaysRun = true)
44   public static void tearDownAfterClass() throws Exception
45   {
46     Desktop.instance.closeAll_actionPerformed(null);
47   }
48
49   @Test(priority = 0)
50   public void testHMMBuild() throws MalformedURLException, IOException
51   {
52     FastaFile file = null;
53     try
54     {
55       file = new FastaFile(
56               new FileParse("examples/uniref50.fa", DataSourceType.FILE));
57     } catch (IOException e)
58     {
59       e.printStackTrace();
60       fail();
61     }
62     SequenceI[] seqs = file.getSeqsAsArray();
63     AlignmentI al = new Alignment(seqs);
64     frame = new AlignFrame(al, 150, 20);
65
66     HMMBuildThread thread = new HMMBuildThread(frame,
67             new ArrayList<ArgumentI>());
68     thread.hmmbuildWaitTillComplete();
69
70     SequenceI seq = frame.getViewport().getAlignment().getSequenceAt(0);
71     HiddenMarkovModel hmm = seq.getHMM();
72     if (hmm == null)
73     {
74       fail();
75     }
76
77     assertEquals(hmm.getLength().intValue(), 148);
78     assertEquals(hmm.getAlphabetType(), "amino");
79     assertEquals(hmm.getName(), "Alignment");
80     assertEquals(hmm.getEffectiveNumberOfSequences(), 0.648193, 0.0001);
81     assertEquals(hmm.getConsensusAtAlignColumn(15), 's');
82   }
83
84   @Test(priority = 1)
85   public void testHMMAlign() throws MalformedURLException, IOException
86   {
87     HMMAlignThread thread = new HMMAlignThread(frame, true,
88             new ArrayList<ArgumentI>());
89     try
90     {
91       thread.hmmalignWaitTillComplete();
92     } catch (Exception e)
93     {
94       e.printStackTrace();
95       fail();
96     }
97
98     if (Desktop.getAlignFrames() == null)
99     {
100       fail();
101     }
102
103     AlignFrame fr = Desktop.getAlignFrames()[0];
104     AlignmentI al = fr.getViewport().getAlignment();
105     assertNotEquals(al, null);
106     List<SequenceI> hmmSeqs = al.getHMMConsensusSequences();
107     assertNotNull(hmmSeqs);
108   }
109 }
110