From: Mateusz Warowny Date: Fri, 19 Jan 2024 14:43:05 +0000 (+0100) Subject: JAL-1601 Patch JPred4 service tests. X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=c56d4ccb5d054775cff8bc0f518cd51cc2dc1513;p=jalview.git JAL-1601 Patch JPred4 service tests. --- diff --git a/src/jalview/ws2/actions/secstructpred/SecStructPredPDBSearchTask.java b/src/jalview/ws2/actions/secstructpred/SecStructPredPDBSearchTask.java index 0cb5150..fc7a772 100644 --- a/src/jalview/ws2/actions/secstructpred/SecStructPredPDBSearchTask.java +++ b/src/jalview/ws2/actions/secstructpred/SecStructPredPDBSearchTask.java @@ -53,11 +53,13 @@ public class SecStructPredPDBSearchTask extends throws ServiceInputInvalidException { SeqCigar[] msf = alignmentView.getSequences(); - SequenceI seq = msf[0].getSeq('-'); - int[] delMap = alignmentView.getVisibleContigMapFor(seq.gapMap()); if (msf.length > 1) throw new ServiceInputInvalidException(MessageManager.getString( "error.implementation_error_multiple_single_sequence_prediction_jobs_not_supported")); + SequenceI seq = msf[0].getSeq('-'); + if (seq == null) + throw new ServiceInputInvalidException("Missing sequence."); + int[] delMap = alignmentView.getVisibleContigMapFor(seq.gapMap()); var seqInfo = SeqsetUtils.SeqCharacterHash(seq); seq.setSequence(AlignSeq.extractGaps(Comparison.GapChars, alignmentView.getASequenceString('-', 0))); diff --git a/src/jalview/ws2/client/jpred4/JPred4WSClient.java b/src/jalview/ws2/client/jpred4/JPred4WSClient.java index db1a6e4..3782723 100644 --- a/src/jalview/ws2/client/jpred4/JPred4WSClient.java +++ b/src/jalview/ws2/client/jpred4/JPred4WSClient.java @@ -53,7 +53,7 @@ public class JPred4WSClient implements SecStructPredWebServiceClientI var input = mode == JPredRequest.Mode.MSA ? FileFormat.Fasta .getWriter(null) - .print(sequences.toArray(SequenceI[]::new), false) + .print(sequences.toArray(new SequenceI[sequences.size()]), false) : sequences.get(0).getSequenceAsString(); JPredRequest request = JPredRequest diff --git a/test/jalview/ws2/actions/secstructpred/SecStructPredPDBSearchTaskTest.java b/test/jalview/ws2/actions/secstructpred/SecStructPredPDBSearchTaskTest.java index 2f9cc3b..ca88cf3 100644 --- a/test/jalview/ws2/actions/secstructpred/SecStructPredPDBSearchTaskTest.java +++ b/test/jalview/ws2/actions/secstructpred/SecStructPredPDBSearchTaskTest.java @@ -2,8 +2,10 @@ package jalview.ws2.actions.secstructpred; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.equalTo; import java.io.IOException; +import java.util.ArrayList; import java.util.List; import static org.mockito.Mockito.mock; @@ -15,6 +17,9 @@ import static jalview.testutils.Matchers.matchesSequenceString; import jalview.io.DataSourceType; import jalview.io.FastaFile; import jalview.io.JPredFile; + +import org.hamcrest.Matcher; +import org.hamcrest.Matchers; import org.testng.annotations.BeforeMethod; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -23,9 +28,12 @@ import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; import jalview.datamodel.HiddenColumns; import jalview.datamodel.Sequence; +import jalview.datamodel.SequenceI; import jalview.gui.AlignViewport; import jalview.ws2.actions.ServiceInputInvalidException; import jalview.ws2.api.Credentials; +import jalview.ws2.api.JobStatus; +import jalview.ws2.api.WebServiceJobHandle; import jalview.ws2.client.api.SecStructPredWebServiceClientI; import static java.lang.String.format; @@ -87,7 +95,8 @@ public class SecStructPredPDBSearchTaskTest @DataProvider public Object[][] viewportWithTooShortSequence() { - return new Object[][] { { new AlignViewport(createAlignment("")) }, + return new Object[][] { + { new AlignViewport(createAlignment("")) }, { new AlignViewport(createAlignment("A")) }, { new AlignViewport(createAlignment("AAAAAAAAAAAAAAAAAAA")) }, { new AlignViewport(createAlignment("AAAAACCCCCAAAAA-----CC")) }, @@ -125,12 +134,38 @@ public class SecStructPredPDBSearchTaskTest }; } - @Test( - groups = { "Functional" } - ) - public void testCollectResult(AlignViewport viewport, String alnFileName, String predFileName) throws Exception + @Test(groups = { "Functional" }, dataProvider = "collectResultDataset") + public void testCollectResult(AlignViewport viewport, String alnFileName, + String predFileName) throws Exception { var alnFile = new FastaFile(alnFileName, DataSourceType.FILE); var predFile = new JPredFile(predFileName, DataSourceType.FILE); + when(mockClient.getPredictionFile(any())).thenReturn(predFile); + when(mockClient.getAlignmentFile(any())).thenReturn(alnFile); + when(mockClient.getStatus(any())).thenReturn(JobStatus.COMPLETED); + when(mockClient.submit(any(), any(), any())) + .thenReturn(new WebServiceJobHandle("mock", "mock", + "http://example.org", "0")); + + var task = new SecStructPredPDBSearchTask(mockClient, List.of(), + Credentials.empty(), viewport); + task.init(); + task.poll(); + task.complete(); + var resultAlignment = task.getResult(); + var sequences = resultAlignment.getSequences(); + + { + List> matchers = new ArrayList<>(); + for (var seq : alnFile.getSeqs()) + matchers.add(matchesSequenceString(seq)); + assertThat(sequences, Matchers.contains(matchers)); + } + + { + var originalHidden = viewport.getAlignment().getHiddenColumns(); + var resultHidden = resultAlignment.getHiddenColumns(); + assertThat(resultHidden, equalTo(originalHidden)); + } } }