--- /dev/null
+package jalview.hmmer;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+import jalview.bin.Jalview;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.HiddenMarkovModel;
+import jalview.datamodel.SequenceI;
+import jalview.gui.AlignFrame;
+import jalview.gui.Desktop;
+import jalview.io.HMMFile;
+import jalview.util.MessageManager;
+import jalview.ws.params.ArgumentI;
+import jalview.ws.params.simple.Option;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public class HMMERTest {
+
+ AlignFrame frame;
+
+ @BeforeClass(alwaysRun = true)
+ public void setUpBeforeClass() throws Exception
+ {
+ /*
+ * NB: check HMMER_PATH in testProps.jvprops is valid for
+ * the machine on which this runs
+ */
+ Jalview.main(
+ new String[]
+ { "-noquestionnaire", "-nonews", "-props",
+ "test/jalview/hmmer/testProps.jvprops", "-open",
+ "examples/uniref50.fa" });
+ frame = Desktop.getAlignFrames()[0];
+ }
+
+ @AfterClass(alwaysRun = true)
+ public static void tearDownAfterClass() throws Exception
+ {
+ Desktop.instance.closeAll_actionPerformed(null);
+ }
+
+ /**
+ * Test with a dependency on locally installed hmmbuild binaries
+ *
+ * @throws MalformedURLException
+ * @throws IOException
+ */
+ @Test(groups = "External")
+ public void testHMMBuildThenHMMAlign()
+ throws MalformedURLException, IOException
+ {
+ /*
+ * run hmmbuild
+ */
+ testHMMBuild();
+ List<SequenceI> hmms = frame.getViewport().getAlignment()
+ .getHmmSequences();
+ assertFalse(hmms.isEmpty());
+
+ /*
+ * now run hmmalign - by default with respect to the added HMM profile
+ */
+ testHMMAlign();
+ }
+
+ public void testHMMBuild()
+ {
+ /*
+ * set up argument to run hmmbuild for the alignment
+ */
+ ArrayList<ArgumentI> params = new ArrayList<>();
+ String argName = MessageManager.getString("label.hmmbuild_for");
+ String argValue = MessageManager.getString("label.alignment");
+ params.add(
+ new Option(argName, null, false, null, argValue, null, null));
+
+ HMMBuild builder = new HMMBuild(frame, params);
+ builder.run();
+
+ SequenceI seq = frame.getViewport().getAlignment().getSequenceAt(0);
+ HiddenMarkovModel hmm = seq.getHMM();
+ assertNotNull(hmm);
+
+ assertEquals(hmm.getLength(), 148);
+ assertEquals(hmm.getAlphabetType(), "amino");
+ assertEquals(hmm.getName(), "Alignment_HMM");
+ assertEquals(hmm.getProperty(HMMFile.EFF_NUMBER_OF_SEQUENCES),
+ "0.648193");
+ }
+
+ public void testHMMAlign()
+ {
+ HmmerCommand thread = new HMMAlign(frame,
+ new ArrayList<ArgumentI>());
+ thread.run();
+
+ AlignFrame[] alignFrames = Desktop.getAlignFrames();
+ if (alignFrames == null)
+ {
+ fail("No align frame loaded");
+ }
+
+ /*
+ * now have the original align frame, and another for realigned sequences
+ */
+ assertEquals(alignFrames.length, 2);
+ AlignmentI original = alignFrames[0].getViewport().getAlignment();
+ assertNotNull(original);
+ AlignmentI realigned = alignFrames[1].getViewport().getAlignment();
+ assertNotNull(realigned);
+ assertFalse(original.getHmmSequences().isEmpty());
+ assertFalse(realigned.getHmmSequences().isEmpty());
+
+ SequenceI ferCapan = original.findName("FER_CAPAN");
+ assertTrue(ferCapan.getSequenceAsString().startsWith("MA------SVSAT"));
+
+ SequenceI ferCapanRealigned = realigned.findName("FER_CAPAN");
+ assertTrue(ferCapanRealigned.getSequenceAsString()
+ .startsWith("-------m-A----SVSAT"));
+ }
+}
+