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