JAL-4241 Test sequences prepared for annotation job
authorMateusz Warowny <mmzwarowny@dundee.ac.uk>
Thu, 3 Aug 2023 15:47:42 +0000 (17:47 +0200)
committerMateusz Warowny <mmzwarowny@dundee.ac.uk>
Fri, 4 Aug 2023 10:38:39 +0000 (12:38 +0200)
test/jalview/testutils/Matchers.java [new file with mode: 0644]
test/jalview/testutils/SequenceStringMatcher.java [new file with mode: 0644]
test/jalview/ws2/actions/alignment/AlignmentActionTest.java
test/jalview/ws2/actions/annotation/AnnotationJobTest.java [new file with mode: 0644]

diff --git a/test/jalview/testutils/Matchers.java b/test/jalview/testutils/Matchers.java
new file mode 100644 (file)
index 0000000..ceb07a0
--- /dev/null
@@ -0,0 +1,13 @@
+package jalview.testutils;
+
+import org.hamcrest.Matcher;
+
+import jalview.datamodel.SequenceI;
+
+public class Matchers
+{
+  public static Matcher<SequenceI> matchesSequenceString(String sequence)
+  {
+    return new SequenceStringMatcher(sequence);
+  }
+}
diff --git a/test/jalview/testutils/SequenceStringMatcher.java b/test/jalview/testutils/SequenceStringMatcher.java
new file mode 100644 (file)
index 0000000..c1f8fb7
--- /dev/null
@@ -0,0 +1,34 @@
+package jalview.testutils;
+
+import org.hamcrest.Description;
+import org.hamcrest.TypeSafeMatcher;
+
+import jalview.datamodel.SequenceI;
+
+public class SequenceStringMatcher extends TypeSafeMatcher<SequenceI>
+{
+  final String sequence;
+
+  public SequenceStringMatcher(String sequence)
+  {
+    this.sequence = sequence;
+  }
+
+  @Override
+  public boolean matchesSafely(SequenceI obj)
+  {
+    return obj.getSequenceAsString().equals(sequence);
+  }
+
+  @Override
+  public void describeTo(Description description)
+  {
+    description.appendText("a sequence ").appendValue(sequence);
+  }
+
+  @Override
+  public void describeMismatchSafely(SequenceI item, Description description)
+  {
+    description.appendText("was ").appendValue(item.getSequenceAsString());
+  }
+}
index bc43070..b4a1388 100644 (file)
@@ -1,5 +1,20 @@
 package jalview.ws2.actions.alignment;
 
+import static jalview.testutils.Matchers.matchesSequenceString;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.hasProperty;
+import static org.hamcrest.Matchers.is;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyList;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.inOrder;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
 import java.io.IOException;
 import java.net.URL;
 import java.util.List;
@@ -8,24 +23,18 @@ import java.util.concurrent.TimeUnit;
 
 import javax.help.UnsupportedOperationException;
 
-import org.hamcrest.BaseMatcher;
-import org.hamcrest.Description;
-import org.hamcrest.Matcher;
-import org.hamcrest.TypeSafeMatcher;
 import org.mockito.ArgumentCaptor;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 
 import jalview.datamodel.Alignment;
-import jalview.datamodel.AlignmentI;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceI;
 import jalview.gui.AlignViewport;
 import jalview.viewmodel.AlignmentViewport;
 import jalview.ws.params.ParamDatastoreI;
 import jalview.ws2.actions.PollingTaskExecutor;
-import jalview.ws2.actions.api.JobI;
 import jalview.ws2.actions.api.TaskEventListener;
 import jalview.ws2.api.Credentials;
 import jalview.ws2.api.JobStatus;
@@ -33,13 +42,6 @@ import jalview.ws2.api.WebService;
 import jalview.ws2.api.WebServiceJobHandle;
 import jalview.ws2.client.api.AlignmentWebServiceClientI;
 
-import org.mockito.hamcrest.MockitoHamcrest;
-import org.mockito.internal.hamcrest.HamcrestArgumentMatcher;
-
-import static org.mockito.Mockito.*;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.*;
-
 public class AlignmentActionTest
 {
   protected AlignmentWebServiceClientI mockClient;
@@ -134,9 +136,9 @@ public class AlignmentActionTest
     verify(mockClient).submit(argument.capture(), eq(List.of()), eq(Credentials.empty()));
     assertThat(argument.getValue(),
         contains(
-            matchesSequence("ASTVLITOPDCMMQEGGST"),
-            matchesSequence("ASCGLITOMMQEGGST"),
-            matchesSequence("ASTVLOPDTMMQEL")));
+            matchesSequenceString("ASTVLITOPDCMMQEGGST"),
+            matchesSequenceString("ASCGLITOMMQEGGST"),
+            matchesSequenceString("ASTVLOPDTMMQEL")));
   }
 
   @Test(
@@ -155,9 +157,9 @@ public class AlignmentActionTest
     verify(mockClient).submit(argument.capture(), eq(List.of()), eq(Credentials.empty()));
     assertThat(argument.getValue(),
         contains(
-            matchesSequence("----ASTVLITOPDCMMQEGGST-"),
-            matchesSequence("-ASCGLITO------MMQEGGST-"),
-            matchesSequence("AS--TVL--OPDTMMQEL------")));
+            matchesSequenceString("----ASTVLITOPDCMMQEGGST-"),
+            matchesSequenceString("-ASCGLITO------MMQEGGST-"),
+            matchesSequenceString("AS--TVL--OPDTMMQEL------")));
   }
 
   @Test(
@@ -176,36 +178,9 @@ public class AlignmentActionTest
     verify(mockListener).taskCompleted(any(), argument.capture());
     var alignmentResult = argument.getValue().getAlignment();
     assertThat(alignmentResult, hasProperty("sequences", contains(
-        matchesSequence("ASTV-LITOPDCMMQEGGST----"),
-        matchesSequence("ASC-GLITO---MMQEGGST----"),
-        matchesSequence("ASTV-L--OPDTMMQE--L-----"))));
-  }
-
-  protected static Matcher<SequenceI> matchesSequence(String sequence)
-  {
-    return new TypeSafeMatcher<SequenceI>()
-    {
-      @Override
-      public boolean matchesSafely(SequenceI obj)
-      {
-        if (!(obj instanceof SequenceI))
-          return false;
-        var seq = (SequenceI) obj;
-        return seq.getSequenceAsString().equals(sequence);
-      }
-
-      @Override
-      public void describeTo(Description description)
-      {
-        description.appendText("a sequence ").appendValue(sequence);
-      }
-
-      @Override
-      public void describeMismatchSafely(SequenceI item, Description description)
-      {
-        description.appendText("was ").appendValue(item.getSequenceAsString());
-      }
-    };
+        matchesSequenceString("ASTV-LITOPDCMMQEGGST----"),
+        matchesSequenceString("ASC-GLITO---MMQEGGST----"),
+        matchesSequenceString("ASTV-L--OPDTMMQE--L-----"))));
   }
 
   protected TaskEventListener<AlignmentResult> performAction(
diff --git a/test/jalview/ws2/actions/annotation/AnnotationJobTest.java b/test/jalview/ws2/actions/annotation/AnnotationJobTest.java
new file mode 100644 (file)
index 0000000..4e3767f
--- /dev/null
@@ -0,0 +1,264 @@
+package jalview.ws2.actions.annotation;
+
+import static jalview.testutils.Matchers.matchesSequenceString;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.hasSize;
+
+import java.util.List;
+
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import jalview.datamodel.Alignment;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceGroup;
+
+public class AnnotationJobTest
+{
+  @Test(groups = { "Functional" })
+  public void testCreate_EqualLengthNoGapsSubmitGaps()
+  {
+    var alignment = new Alignment(new Sequence[] {
+       new Sequence("test1", "ACACACACACA"),
+       new Sequence("test2", "AVAVAVAVAVA"),
+       new Sequence("test3", "AVWVAVWVAVW")
+    });
+    var annotJob = AnnotationJob.create(alignment, true, false, false, false, 0);
+    assertThat(annotJob.getInputSequences(), contains(
+            matchesSequenceString("ACACACACACA"),
+            matchesSequenceString("AVAVAVAVAVA"),
+            matchesSequenceString("AVWVAVWVAVW")
+    ));
+  }
+
+  @Test(groups = { "Functional" })
+  public void testCreate_EqualLengthNoGapsNoSubmitGaps()
+  {
+    var alignment = new Alignment(new Sequence[] {
+        new Sequence("test1", "ACACACACACA"),
+        new Sequence("test2", "AVAVAVAVAVA"),
+        new Sequence("test3", "AVWVAVWVAVW")
+    });
+    var annotJob = AnnotationJob.create(alignment, true, true, false, false, 0);
+    assertThat(annotJob.getInputSequences(), contains(
+            matchesSequenceString("ACACACACACA"),
+            matchesSequenceString("AVAVAVAVAVA"),
+            matchesSequenceString("AVWVAVWVAVW")
+    ));
+  }
+
+  @Test(groups = { "Functional" })
+  public void testCreate_UnequalLengthNoGapsNoSubmitGaps()
+  {
+    var alignment = new Alignment(new Sequence[] {
+       new Sequence("test1", "ACACACACACA"),
+       new Sequence("test2", "AVAVAVAVAVAVA"),
+       new Sequence("test3", "AVWVAVWVAVWV")
+    });
+    var annotJob = AnnotationJob.create(alignment, true, false, false, false, 0);
+    assertThat(annotJob.getInputSequences(), contains(
+            matchesSequenceString("ACACACACACA"),
+            matchesSequenceString("AVAVAVAVAVAVA"),
+            matchesSequenceString("AVWVAVWVAVWV")
+    ));
+  }
+
+  @Test(groups = { "Functional" })
+  public void testCreate_UnequalLengthNoGapsSubmitGaps()
+  {
+    var alignment = new Alignment(new Sequence[] {
+        new Sequence("test1", "ACACACACACA"),
+        new Sequence("test2", "AVAVAVAVAVAVA"),
+        new Sequence("test3", "AVWVAVWVAVWV")
+     });
+     var annotJob = AnnotationJob.create(alignment, true, true, false, false, 0);
+     assertThat(annotJob.getInputSequences(), contains(
+             matchesSequenceString("ACACACACACA"),
+             matchesSequenceString("AVAVAVAVAVAVA"),
+             matchesSequenceString("AVWVAVWVAVWV")
+     ));
+  }
+
+  @Test(groups = { "Functional" })
+  public void testCreate_UnequalLengthNoGapsSubmitGapsRequireAligned()
+  {
+    var alignment = new Alignment(new Sequence[] {
+        new Sequence("test1", "ACACACACACA"),
+        new Sequence("test2", "AVAVAVAVAVAVA"),
+        new Sequence("test3", "AVWVAVWVAVWV")
+     });
+     var annotJob = AnnotationJob.create(alignment, true, true, true, false, 0);
+     assertThat(annotJob.getInputSequences(), contains(
+             matchesSequenceString("ACACACACACA--"),
+             matchesSequenceString("AVAVAVAVAVAVA"),
+             matchesSequenceString("AVWVAVWVAVWV-")
+     ));
+  }
+
+  @DataProvider
+  public Object[] alignmentWithShortSequences()
+  {
+    return new Object[] {
+        new Alignment(new Sequence[] {
+            new Sequence("test1", "AAAAA"),
+            new Sequence("test2", "ACAACAAACAAC"),
+            new Sequence("test3", "ACA")
+        }),
+        new Alignment(new Sequence[] {
+            new Sequence("test1", "----AAAAA---"),
+            new Sequence("test2", "ACAACAAACAAC"),
+            new Sequence("test3", "-----ACA----")
+        }),
+        new Alignment(new Sequence[] {
+            new Sequence("test1", "--AAA---AA--"),
+            new Sequence("test2", "ACAACAAACAAC"),
+            new Sequence("test3", "-------ACA--")
+        }),
+    };
+  }
+
+  @Test(groups = { "Functional" }, dataProvider = "alignmentWithShortSequences")
+  public void testCreate_TooShortSequence_ShortSequenceRemoved(Alignment aln)
+  {
+    var annotJob = AnnotationJob.create(aln, true, false, false, false, 0);
+    assertThat(annotJob.getInputSequences(), hasSize(1));
+  }
+
+  @Test(groups = { "Functional" }, dataProvider = "alignmentWithShortSequences")
+  public void testCreate_TooShortSequenceAndSubmitGaps_ShortSeqRemoved(Alignment aln)
+  {
+    var annotJob = AnnotationJob.create(aln, true, true, false, false, 0);
+    assertThat(annotJob.getInputSequences(), hasSize(1));
+  }
+
+  @Test(groups = { "Functional" }, dataProvider = "alignmentWithShortSequences")
+  public void testCreate_TooShortSequenceAndRequireAligned_ShortSeqRemoved(Alignment aln)
+  {
+    var annotJob = AnnotationJob.create(aln, true, true, true, false, 0);
+    assertThat(annotJob.getInputSequences(), hasSize(1));
+  }
+
+  @Test(groups = { "Functional" })
+  public void testCreate_EmptyColumnAndSubmitGaps_ColumnExtruded()
+  {
+    var alignment = new Alignment(new Sequence[] {
+        new Sequence("test1", "ACA-ACAA--CACA"),
+        new Sequence("test2", "AVA-AVAA-AVAVA"),
+        new Sequence("test3", "AVAWAVAA-AVWVA")
+    });
+    var annotJob = AnnotationJob.create(alignment, true, true, false, false, 0);
+    assertThat(annotJob.getInputSequences(), contains(
+            matchesSequenceString("ACA-ACAA-CACA"),
+            matchesSequenceString("AVA-AVAAAVAVA"),
+            matchesSequenceString("AVAWAVAAAVWVA")
+    ));
+  }
+
+  @Test(groups = { "Functional" })
+  public void testCreate_EmptyColumnAndRequireAligned_ColumnExtruded()
+  {
+    var alignment = new Alignment(new Sequence[] {
+        new Sequence("test1", "ACA-ACAA--CACA"),
+        new Sequence("test2", "AVA-AVAA-AVAVA"),
+        new Sequence("test3", "AVAWAVAA-AVWVA")
+    });
+    var annotJob = AnnotationJob.create(alignment, true, true, true, false, 0);
+    assertThat(annotJob.getInputSequences(), contains(
+            matchesSequenceString("ACA-ACAA-CACA"),
+            matchesSequenceString("AVA-AVAAAVAVA"),
+            matchesSequenceString("AVAWAVAAAVWVA")
+    ));
+  }
+
+  @Test(groups = { "Functional"} )
+  public void testCreate_ContainsNonStandardAndNoFilterNonStandard_NonStandardToGap()
+  {
+    var alignment = new Alignment(new Sequence[] {
+        new Sequence("test1", "ACACAOACACAC"),
+        new Sequence("test2", "ABAVAVAVABAV")
+    });
+    var annotJob = AnnotationJob.create(alignment, true, true, true, false, 0);
+    assertThat(annotJob.getInputSequences(), contains(
+            matchesSequenceString("ACACA-ACACAC"),
+            matchesSequenceString("A-AVAVAVA-AV")
+    ));
+  }
+
+  @DataProvider
+  public Object[] alignmentWithNonStandardInColumns()
+  {
+    return new Object[] {
+        new Alignment(new Sequence[] {
+            new Sequence("test1", "A-AAAOAAAAAAAA"),
+            new Sequence("test2", "ABAAA-AAAAAAAA")
+        }),
+        new Alignment(new Sequence[] {
+            new Sequence("test1", "ABAAAOAAAAAAAA"),
+            new Sequence("test2", "ABAAABAAAAAAAA")
+        }),
+        new Alignment(new Sequence[] {
+            new Sequence("test1", "A-AAAOAAAAAAAA"),
+            new Sequence("test2", "A-AAA-AAAAAAAA")
+        })
+    };
+  }
+
+  @Test(groups = { "Functional" }, dataProvider = "alignmentWithNonStandardInColumns")
+  public void testCreate_NonStandardInColumnsAndFilterNonStandard_ColumnsExtruded(Alignment aln)
+  {
+    var annotJob = AnnotationJob.create(aln, true, true, true, true, 0);
+    assertThat(annotJob.getInputSequences(), contains(
+            matchesSequenceString("AAAAAAAAAAAA"),
+            matchesSequenceString("AAAAAAAAAAAA")
+    ));
+  }
+
+  @Test(groups = { "Functional" })
+  public void testCreate_SequenceGroup_RegionSubmitted()
+  {
+    var group = new SequenceGroup(List.of(
+       new Sequence("test1", "CCCCAAATAAATAAATCCC"),
+       new Sequence("test2", "----AAATAAATAAAT---")
+    ));
+    group.setStartRes(4);
+    group.setEndRes(15);
+    var annotJob = AnnotationJob.create(group, true, false, false, false, 0);
+    assertThat(annotJob.getInputSequences(), contains(
+            matchesSequenceString("AAATAAATAAAT"),
+            matchesSequenceString("AAATAAATAAAT")
+    ));
+  }
+
+  @Test(groups = { "Functional" })
+  public void testCreate_RegionIncludingGaps_RegionSubmittedWithoutGaps()
+  {
+    var group = new SequenceGroup(List.of(
+       new Sequence("test1", "CCCC-AAATAAATAAAT--CCC"),
+       new Sequence("test2", "-----AAATAAATAAAT-----")
+    ));
+    group.setStartRes(4);
+    group.setEndRes(18);
+    var annotJob = AnnotationJob.create(group, true, false, false, false, 0);
+    assertThat(annotJob.getInputSequences(), contains(
+            matchesSequenceString("AAATAAATAAAT"),
+            matchesSequenceString("AAATAAATAAAT")
+    ));
+  }
+
+  @Test(groups = { "Functional" })
+  public void testCreate_RegionIncludingGapsAndSubmitGaps_RegionSubmittedGapsExtruded()
+  {
+    var group = new SequenceGroup(List.of(
+       new Sequence("test1", "CCCC-AAATAAATAAAT--CCC"),
+       new Sequence("test2", "-----AAATAAATAAAT-----")
+    ));
+    group.setStartRes(4);
+    group.setEndRes(18);
+    var annotJob = AnnotationJob.create(group, true, true, false, false, 0);
+    assertThat(annotJob.getInputSequences(), contains(
+            matchesSequenceString("AAATAAATAAAT"),
+            matchesSequenceString("AAATAAATAAAT")
+    ));
+  }
+}