| 1 |
|
package jalview.ws2.actions.secstructpred; |
| 2 |
|
|
| 3 |
|
import static org.hamcrest.MatcherAssert.assertThat; |
| 4 |
|
import static org.hamcrest.Matchers.contains; |
| 5 |
|
import static org.hamcrest.Matchers.equalTo; |
| 6 |
|
|
| 7 |
|
import java.io.IOException; |
| 8 |
|
import java.util.ArrayList; |
| 9 |
|
import java.util.List; |
| 10 |
|
|
| 11 |
|
import static org.mockito.Mockito.mock; |
| 12 |
|
import static org.mockito.Mockito.when; |
| 13 |
|
import static org.mockito.ArgumentMatchers.any; |
| 14 |
|
import static jalview.testutils.ScopeFunctions.apply; |
| 15 |
|
import static jalview.testutils.Matchers.matchesSequenceString; |
| 16 |
|
|
| 17 |
|
import jalview.io.DataSourceType; |
| 18 |
|
import jalview.io.FastaFile; |
| 19 |
|
import jalview.io.JPredFile; |
| 20 |
|
|
| 21 |
|
import org.hamcrest.Matcher; |
| 22 |
|
import org.hamcrest.Matchers; |
| 23 |
|
import org.testng.annotations.BeforeMethod; |
| 24 |
|
import org.testng.annotations.DataProvider; |
| 25 |
|
import org.testng.annotations.Test; |
| 26 |
|
|
| 27 |
|
import jalview.datamodel.Alignment; |
| 28 |
|
import jalview.datamodel.AlignmentI; |
| 29 |
|
import jalview.datamodel.HiddenColumns; |
| 30 |
|
import jalview.datamodel.Sequence; |
| 31 |
|
import jalview.datamodel.SequenceI; |
| 32 |
|
import jalview.gui.AlignViewport; |
| 33 |
|
import jalview.ws2.actions.ServiceInputInvalidException; |
| 34 |
|
import jalview.ws2.api.Credentials; |
| 35 |
|
import jalview.ws2.api.JobStatus; |
| 36 |
|
import jalview.ws2.api.WebServiceJobHandle; |
| 37 |
|
import jalview.ws2.client.api.SecStructPredWebServiceClientI; |
| 38 |
|
import static java.lang.String.format; |
| 39 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (48) |
Complexity: 9 |
Complexity Density: 0.24 |
|
| 40 |
|
public class SecStructPredPDBSearchTaskTest |
| 41 |
|
{ |
| 42 |
|
protected SecStructPredWebServiceClientI mockClient; |
| 43 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
| 44 |
12 |
@BeforeMethod(alwaysRun = true)... |
| 45 |
|
public void setupMockClient() throws IOException |
| 46 |
|
{ |
| 47 |
12 |
mockClient = mock(SecStructPredWebServiceClientI.class); |
| 48 |
12 |
when(mockClient.getUrl()).thenReturn("http://example.org"); |
| 49 |
12 |
when(mockClient.getClientName()).thenReturn("mock"); |
| 50 |
12 |
when(mockClient.getLog(any())).thenReturn(""); |
| 51 |
12 |
when(mockClient.getErrorLog(any())).thenReturn(""); |
| 52 |
|
} |
| 53 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 54 |
1 |
@DataProvider... |
| 55 |
|
public Object[][] viewportAndExpectedInputSeq() |
| 56 |
|
{ |
| 57 |
1 |
return new Object[][] { |
| 58 |
|
{ new AlignViewport(createAlignment("AAAAAAAAAAAAAAAAAAAA")), |
| 59 |
|
"AAAAAAAAAAAAAAAAAAAA", }, |
| 60 |
|
{ new AlignViewport(createAlignment("--AAGGAGAG-AGGA----MMMMMMMM")), |
| 61 |
|
"AAGGAGAGAGGAMMMMMMMM" }, |
| 62 |
|
{ new AlignViewport(createAlignment("AAAANNNCCCCCCCCCCAAAAAA"), |
| 63 |
|
apply(new HiddenColumns(), it -> it.hideColumns(4, 6))), |
| 64 |
|
"AAAACCCCCCCCCCAAAAAA" }, |
| 65 |
|
{ new AlignViewport( |
| 66 |
|
createAlignment("NNNNGGGGVVVVVAAAAAAACCMMMMMMMM"), |
| 67 |
|
apply(new HiddenColumns(), it -> { |
| 68 |
1 |
it.hideColumns(4, 7); |
| 69 |
1 |
it.hideColumns(20, 21); |
| 70 |
|
})), |
| 71 |
|
"NNNNVVVVVAAAAAAAMMMMMMMM" } }; |
| 72 |
|
} |
| 73 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 74 |
11 |
public static AlignmentI createAlignment(String... sequences)... |
| 75 |
|
{ |
| 76 |
11 |
var seqArray = new Sequence[sequences.length]; |
| 77 |
22 |
for (int i = 0; i < sequences.length; i++) |
| 78 |
11 |
seqArray[i] = new Sequence(format("Seq%d", i), sequences[i]); |
| 79 |
11 |
return new Alignment(seqArray); |
| 80 |
|
} |
| 81 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
| 82 |
4 |
@Test(... |
| 83 |
|
groups = { "Functional" }, |
| 84 |
|
dataProvider = "viewportAndExpectedInputSeq") |
| 85 |
|
public void testPrepareJobs_checkInputSequences(AlignViewport viewport, |
| 86 |
|
String expectedSeq) throws Exception |
| 87 |
|
{ |
| 88 |
4 |
var task = new SecStructPredPDBSearchTask(mockClient, List.of(), |
| 89 |
|
Credentials.empty(), viewport); |
| 90 |
4 |
var jobs = task.prepareJobs(); |
| 91 |
4 |
assertThat(jobs.get(0).getInputSequences(), |
| 92 |
|
contains(matchesSequenceString(expectedSeq))); |
| 93 |
|
} |
| 94 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 95 |
1 |
@DataProvider... |
| 96 |
|
public Object[][] viewportWithTooShortSequence() |
| 97 |
|
{ |
| 98 |
1 |
return new Object[][] { |
| 99 |
|
{ new AlignViewport(createAlignment("")) }, |
| 100 |
|
{ new AlignViewport(createAlignment("A")) }, |
| 101 |
|
{ new AlignViewport(createAlignment("AAAAAAAAAAAAAAAAAAA")) }, |
| 102 |
|
{ new AlignViewport(createAlignment("AAAAACCCCCAAAAA-----CC")) }, |
| 103 |
|
{ new AlignViewport(createAlignment("-------------------------")) }, |
| 104 |
|
{ new AlignViewport(createAlignment("AAAAAAAAAAAAAAAAAAAAAAAAA"), |
| 105 |
|
apply(new HiddenColumns(), it -> it.hideColumns(0, 24))) }, |
| 106 |
|
{ new AlignViewport(createAlignment("AAAAACCCCCAAAAACCCCCAAAAA"), |
| 107 |
|
apply(new HiddenColumns(), it -> it.hideColumns(0, 10))) } }; |
| 108 |
|
} |
| 109 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
| 110 |
7 |
@Test(... |
| 111 |
|
groups = { "Functional" }, |
| 112 |
|
dataProvider = "viewportWithTooShortSequence", |
| 113 |
|
expectedExceptions = ServiceInputInvalidException.class) |
| 114 |
|
public void testPrepareJobs_SequenceTooShort_InputInvalidException( |
| 115 |
|
AlignViewport viewport) throws ServiceInputInvalidException |
| 116 |
|
{ |
| 117 |
7 |
var task = new SecStructPredPDBSearchTask(mockClient, List.of(), |
| 118 |
|
Credentials.empty(), viewport); |
| 119 |
7 |
task.prepareJobs(); |
| 120 |
|
} |
| 121 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 122 |
1 |
@DataProvider... |
| 123 |
|
public Object[][] collectResultDataset() throws IOException |
| 124 |
|
{ |
| 125 |
1 |
return new Object[][] { |
| 126 |
|
{ |
| 127 |
|
new AlignViewport(new Alignment(new FastaFile( |
| 128 |
|
"examples/testdata/secstrpred/sequence0_input.fa", |
| 129 |
|
DataSourceType.FILE).getSeqsAsArray() |
| 130 |
|
)), |
| 131 |
|
"examples/testdata/secstrpred/sequence0.align", |
| 132 |
|
"examples/testdata/secstrpred/sequence0.concise" |
| 133 |
|
}, |
| 134 |
|
}; |
| 135 |
|
} |
| 136 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
| 137 |
1 |
@Test(groups = { "Functional" }, dataProvider = "collectResultDataset")... |
| 138 |
|
public void testCollectResult(AlignViewport viewport, String alnFileName, |
| 139 |
|
String predFileName) throws Exception |
| 140 |
|
{ |
| 141 |
1 |
var alnFile = new FastaFile(alnFileName, DataSourceType.FILE); |
| 142 |
1 |
var predFile = new JPredFile(predFileName, DataSourceType.FILE); |
| 143 |
1 |
when(mockClient.getPredictionFile(any())).thenReturn(predFile); |
| 144 |
1 |
when(mockClient.getAlignmentFile(any())).thenReturn(alnFile); |
| 145 |
1 |
when(mockClient.getStatus(any())).thenReturn(JobStatus.COMPLETED); |
| 146 |
1 |
when(mockClient.submit(any(), any(), any())) |
| 147 |
|
.thenReturn(new WebServiceJobHandle("mock", "mock", |
| 148 |
|
"http://example.org", "0")); |
| 149 |
|
|
| 150 |
1 |
var task = new SecStructPredPDBSearchTask(mockClient, List.of(), |
| 151 |
|
Credentials.empty(), viewport); |
| 152 |
1 |
task.init(); |
| 153 |
1 |
task.poll(); |
| 154 |
1 |
task.complete(); |
| 155 |
1 |
var resultAlignment = task.getResult(); |
| 156 |
1 |
var sequences = resultAlignment.getSequences(); |
| 157 |
|
|
| 158 |
|
{ |
| 159 |
1 |
List<Matcher<? super SequenceI>> matchers = new ArrayList<>(); |
| 160 |
1 |
for (var seq : alnFile.getSeqs()) |
| 161 |
812 |
matchers.add(matchesSequenceString(seq)); |
| 162 |
1 |
assertThat(sequences, Matchers.contains(matchers)); |
| 163 |
|
} |
| 164 |
|
|
| 165 |
|
{ |
| 166 |
1 |
var originalHidden = viewport.getAlignment().getHiddenColumns(); |
| 167 |
1 |
var resultHidden = resultAlignment.getHiddenColumns(); |
| 168 |
1 |
assertThat(resultHidden, equalTo(originalHidden)); |
| 169 |
|
} |
| 170 |
|
} |
| 171 |
|
} |