JAL-2937 working Cygwin bash execution of hmmbuild on Windows
[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.assertNotNull;
5 import static org.testng.Assert.assertTrue;
6 import static org.testng.Assert.fail;
7
8 import jalview.bin.Jalview;
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.HMMFile;
15 import jalview.util.MessageManager;
16 import jalview.ws.params.ArgumentI;
17 import jalview.ws.params.simple.Option;
18
19 import java.io.IOException;
20 import java.net.MalformedURLException;
21 import java.util.ArrayList;
22
23 import org.testng.annotations.AfterClass;
24 import org.testng.annotations.BeforeClass;
25 import org.testng.annotations.Test;
26
27 public class HMMERTest {
28
29   AlignFrame frame;
30
31   @BeforeClass(alwaysRun = true)
32   public void setUpBeforeClass() throws Exception
33   {
34     /*
35      * NB: check HMMER_PATH in testProps.jvprops is valid for
36      * the machine on which this runs
37      */
38     Jalview.main(
39             new String[]
40     { "-noquestionnaire", "-nonews", "-props",
41                 "test/jalview/hmmer/testProps.jvprops", "-open",
42                 "examples/uniref50.fa" });
43     frame = Desktop.getAlignFrames()[0];
44   }
45
46   @AfterClass(alwaysRun = true)
47   public static void tearDownAfterClass() throws Exception
48   {
49     Desktop.instance.closeAll_actionPerformed(null);
50   }
51
52   /**
53    * Test with a dependency on locally installed hmmbuild binaries
54    * 
55    * @throws MalformedURLException
56    * @throws IOException
57    */
58   @Test(groups = "External")
59   public void testHMMBuildThenHMMAlign()
60           throws MalformedURLException, IOException
61   {
62     /*
63      * run hmmbuild - note the side-effect of selecting the HMM
64      * sequence that gets added to the alignment
65      */
66     testHMMBuild();
67     HiddenMarkovModel hmm = frame.getSelectedHMM();
68     assertNotNull(hmm);
69
70     /*
71      * now run hmmalign - with respect to the select HMM profile
72      */
73     testHMMAlign();
74   }
75
76   public void testHMMBuild()
77   {
78     /*
79      * set up argument to run hmmbuild for the alignment
80      */
81     ArrayList<ArgumentI> params = new ArrayList<>();
82     String argName = MessageManager.getString("label.hmmbuild_for");
83     String argValue = MessageManager.getString("label.alignment");
84     params.add(
85             new Option(argName, null, false, null, argValue, null, null));
86
87     HMMBuild builder = new HMMBuild(frame, params);
88     builder.run();
89
90     SequenceI seq = frame.getViewport().getAlignment().getSequenceAt(0);
91     HiddenMarkovModel hmm = seq.getHMM();
92     assertNotNull(hmm);
93
94     assertEquals(hmm.getLength(), 148);
95     assertEquals(hmm.getAlphabetType(), "amino");
96     assertEquals(hmm.getName(), "Alignment_HMM");
97     assertEquals(hmm.getProperty(HMMFile.EFF_NUMBER_OF_SEQUENCES),
98             "0.648193");
99   }
100
101   public void testHMMAlign()
102   {
103     HmmerCommand thread = new HMMAlign(frame,
104             new ArrayList<ArgumentI>());
105     thread.run();
106
107     AlignFrame[] alignFrames = Desktop.getAlignFrames();
108     if (alignFrames == null)
109     {
110       fail("No align frame loaded");
111     }
112
113     /*
114      * now have the original align frame, and another for realigned sequences
115      */
116     assertEquals(alignFrames.length, 2);
117     AlignmentI original = alignFrames[0].getViewport().getAlignment();
118     assertNotNull(original);
119     AlignmentI realigned = alignFrames[1].getViewport().getAlignment();
120     assertNotNull(realigned);
121     assertNotNull(original.getHmmConsensus());
122     assertNotNull(realigned.getHmmConsensus());
123
124     SequenceI ferCapan = original.findName("FER_CAPAN");
125     assertTrue(ferCapan.getSequenceAsString().startsWith("MA------SVSAT"));
126
127     SequenceI ferCapanRealigned = realigned.findName("FER_CAPAN");
128     assertTrue(ferCapanRealigned.getSequenceAsString()
129             .startsWith("-------m-A----SVSAT"));
130   }
131 }
132