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