| 1 |
|
package jalview.ws2.actions.secstructpred; |
| 2 |
|
|
| 3 |
|
import jalview.datamodel.Alignment; |
| 4 |
|
import jalview.datamodel.AlignmentAnnotation; |
| 5 |
|
import jalview.datamodel.AlignmentI; |
| 6 |
|
import jalview.datamodel.HiddenColumns; |
| 7 |
|
import jalview.datamodel.Sequence; |
| 8 |
|
import jalview.datamodel.SequenceI; |
| 9 |
|
import jalview.gui.AlignViewport; |
| 10 |
|
import jalview.io.DataSourceType; |
| 11 |
|
import jalview.io.FastaFile; |
| 12 |
|
import jalview.io.JPredFile; |
| 13 |
|
import jalview.ws2.api.Credentials; |
| 14 |
|
import jalview.ws2.api.JobStatus; |
| 15 |
|
import jalview.ws2.api.WebServiceJobHandle; |
| 16 |
|
import jalview.ws2.client.api.SecStructPredWebServiceClientI; |
| 17 |
|
import org.hamcrest.Matcher; |
| 18 |
|
import org.hamcrest.Matchers; |
| 19 |
|
import org.testng.annotations.BeforeMethod; |
| 20 |
|
import org.testng.annotations.DataProvider; |
| 21 |
|
import org.testng.annotations.Test; |
| 22 |
|
|
| 23 |
|
import java.io.IOException; |
| 24 |
|
import java.util.ArrayList; |
| 25 |
|
import java.util.List; |
| 26 |
|
|
| 27 |
|
import static jalview.testutils.Matchers.matchesAnnotations; |
| 28 |
|
import static jalview.testutils.Matchers.matchesSequenceString; |
| 29 |
|
import static jalview.testutils.ScopeFunctions.apply; |
| 30 |
|
import static java.lang.String.format; |
| 31 |
|
import static org.hamcrest.MatcherAssert.assertThat; |
| 32 |
|
import static org.hamcrest.Matchers.allOf; |
| 33 |
|
import static org.hamcrest.Matchers.containsInAnyOrder; |
| 34 |
|
import static org.hamcrest.Matchers.equalTo; |
| 35 |
|
import static org.hamcrest.Matchers.hasProperty; |
| 36 |
|
import static org.mockito.ArgumentMatchers.any; |
| 37 |
|
import static org.mockito.Mockito.mock; |
| 38 |
|
import static org.mockito.Mockito.when; |
| 39 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (58) |
Complexity: 7 |
Complexity Density: 0.14 |
|
| 40 |
|
public class SecStructPredMsaTaskTest |
| 41 |
|
{ |
| 42 |
|
protected SecStructPredWebServiceClientI mockClient; |
| 43 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
| 44 |
10 |
@BeforeMethod(alwaysRun = true)... |
| 45 |
|
public void setupMockClient() throws IOException |
| 46 |
|
{ |
| 47 |
10 |
mockClient = mock(SecStructPredWebServiceClientI.class); |
| 48 |
10 |
when(mockClient.getUrl()).thenReturn("http://example.org"); |
| 49 |
10 |
when(mockClient.getClientName()).thenReturn("mock"); |
| 50 |
10 |
when(mockClient.submit(any(), any(), any())) |
| 51 |
|
.thenReturn(new WebServiceJobHandle("mock", "mock", |
| 52 |
|
"http://example.org", "0")); |
| 53 |
10 |
when(mockClient.getLog(any())).thenReturn(""); |
| 54 |
10 |
when(mockClient.getErrorLog(any())).thenReturn(""); |
| 55 |
10 |
when(mockClient.getStatus(any())).thenReturn(JobStatus.COMPLETED); |
| 56 |
|
} |
| 57 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 58 |
1 |
@DataProvider... |
| 59 |
|
public Object[][] alignmentWithExpectedInput() |
| 60 |
|
{ |
| 61 |
1 |
return new Object[][] { { |
| 62 |
|
new AlignViewport(createAlignment("AAAAAAAAAAAA", "AAAAAAAAAAAA", |
| 63 |
|
"AAAAAAAAAAAA")), |
| 64 |
|
List.of("AAAAAAAAAAAA", "AAAAAAAAAAAA", "AAAAAAAAAAAA") }, |
| 65 |
|
{ new AlignViewport(createAlignment("AAAA--NNNNAAAA", |
| 66 |
|
"AA--AANNNNAAAA", "AA--AARRRRAAAA")), |
| 67 |
|
List.of("AAAA--NNNNAAAA", "AA--AANNNNAAAA", "AA--AARRRRAAAA") }, |
| 68 |
|
{ new AlignViewport(createAlignment("AAAANNNNAAAA--", |
| 69 |
|
"AAAARRRRAAAA--", "AAAARRRRAAAA--")), |
| 70 |
|
List.of("AAAANNNNAAAA--", "AAAARRRRAAAA--", "AAAARRRRAAAA--") }, |
| 71 |
|
{ new AlignViewport(createAlignment("AAAA--NNNNAAAA", |
| 72 |
|
"AAAA--NNNNAAAA", "AAAA--NNNNAAAA")), |
| 73 |
|
List.of("AAAA--NNNNAAAA", "AAAA--NNNNAAAA", "AAAA--NNNNAAAA") }, |
| 74 |
|
{ new AlignViewport(createAlignment("AAAACCCCNNNN", "------------", |
| 75 |
|
"AAAADDDDNNNN")), |
| 76 |
|
List.of("AAAACCCCNNNN", "AAAADDDDNNNN") }, |
| 77 |
|
{ new AlignViewport(createAlignment("AAAACC--NNNN", "AAAACCDDNNNN"), |
| 78 |
|
apply(new HiddenColumns(), it -> it.hideColumns(6, 7))), |
| 79 |
|
List.of("AAAACCNNNN", "AAAACCNNNN") }, |
| 80 |
|
{ new AlignViewport( |
| 81 |
|
createAlignment("CCAAAACC--MMMM", "--AAAAGGGGMMMM"), |
| 82 |
|
apply(new HiddenColumns(), it -> { |
| 83 |
1 |
it.hideColumns(0, 1); |
| 84 |
1 |
it.hideColumns(8, 9); |
| 85 |
|
})), |
| 86 |
|
List.of("AAAACCMMMM", "AAAAGGMMMM") }, |
| 87 |
|
{ new AlignViewport( |
| 88 |
|
createAlignment("CCAAAACC--MMMM", "CCAAAACC--MMMM"), |
| 89 |
|
apply(new HiddenColumns(), it -> it.hideColumns(2, 5))), |
| 90 |
|
List.of("CCCC--MMMM", "CCCC--MMMM") } }; |
| 91 |
|
} |
| 92 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 93 |
8 |
public static AlignmentI createAlignment(String... sequences)... |
| 94 |
|
{ |
| 95 |
8 |
var seqArray = new Sequence[sequences.length]; |
| 96 |
29 |
for (int i = 0; i < sequences.length; i++) |
| 97 |
21 |
seqArray[i] = new Sequence(format("Seq%d", i), sequences[i]); |
| 98 |
8 |
return new Alignment(seqArray); |
| 99 |
|
} |
| 100 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
| 101 |
8 |
@Test(... |
| 102 |
|
groups = |
| 103 |
|
{ "Functional" }, |
| 104 |
|
dataProvider = "alignmentWithExpectedInput") |
| 105 |
|
public void testPrepareJobs_checkInputSequences(AlignViewport viewport, |
| 106 |
|
List<String> expectedInput) throws Exception |
| 107 |
|
{ |
| 108 |
8 |
var task = new SecStructPredMsaTask(mockClient, List.of(), |
| 109 |
|
Credentials.empty(), viewport); |
| 110 |
8 |
var jobs = task.prepareJobs(); |
| 111 |
8 |
List<Matcher<? super SequenceI>> seqMatchers = new ArrayList<>( |
| 112 |
|
expectedInput.size()); |
| 113 |
8 |
for (var seqStr : expectedInput) |
| 114 |
20 |
seqMatchers.add(matchesSequenceString(seqStr)); |
| 115 |
8 |
assertThat(jobs.get(0).getInputSequences(), |
| 116 |
|
Matchers.<SequenceI> contains(seqMatchers)); |
| 117 |
|
} |
| 118 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 119 |
1 |
@DataProvider... |
| 120 |
|
public Object[][] viewportWithServiceOutput() throws IOException |
| 121 |
|
{ |
| 122 |
|
|
| 123 |
1 |
return new Object[][] { |
| 124 |
|
{ |
| 125 |
|
new AlignViewport(new Alignment(new FastaFile( |
| 126 |
|
"examples/testdata/secstrpred/alignment0_aln.fa", |
| 127 |
|
DataSourceType.FILE).getSeqsAsArray())), |
| 128 |
|
"examples/testdata/secstrpred/alignment0.fa", |
| 129 |
|
"examples/testdata/secstrpred/alignment0.concise" |
| 130 |
|
}, |
| 131 |
|
{ |
| 132 |
|
new AlignViewport(new Alignment(new FastaFile( |
| 133 |
|
"examples/testdata/secstrpred/alignment0a_aln.fa", |
| 134 |
|
DataSourceType.FILE).getSeqsAsArray()), |
| 135 |
|
apply(new HiddenColumns(), it -> it.hideColumns(3, 7))), |
| 136 |
|
"examples/testdata/secstrpred/alignment0.fa", |
| 137 |
|
"examples/testdata/secstrpred/alignment0.concise" |
| 138 |
|
} |
| 139 |
|
}; |
| 140 |
|
} |
| 141 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (29) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
| 142 |
2 |
@Test(groups = "Functional", dataProvider = "viewportWithServiceOutput")... |
| 143 |
|
public void testCollectResults(AlignViewport viewport, String alnFileName, String predFileName) throws Exception |
| 144 |
|
{ |
| 145 |
2 |
var alnFile = new FastaFile(alnFileName, DataSourceType.FILE); |
| 146 |
2 |
var predFile = new JPredFile(predFileName, DataSourceType.FILE); |
| 147 |
2 |
when(mockClient.getPredictionFile(any())).thenReturn(predFile); |
| 148 |
2 |
when(mockClient.getAlignmentFile(any())).thenReturn(alnFile); |
| 149 |
|
|
| 150 |
2 |
var task = new SecStructPredMsaTask(mockClient, List.of(), |
| 151 |
|
Credentials.empty(), viewport); |
| 152 |
2 |
task.init(); |
| 153 |
2 |
task.poll(); |
| 154 |
2 |
task.complete(); |
| 155 |
2 |
var resultAlignment = task.getResult(); |
| 156 |
2 |
var sequences = resultAlignment.getSequences(); |
| 157 |
|
|
| 158 |
|
|
| 159 |
|
{ |
| 160 |
2 |
List<Matcher<? super SequenceI>> matchers = new ArrayList<>(); |
| 161 |
2 |
for (var seq : viewport.getAlignment().getSequences()) |
| 162 |
6 |
matchers.add(matchesSequenceString(seq)); |
| 163 |
2 |
assertThat(sequences, Matchers.contains(matchers)); |
| 164 |
|
} |
| 165 |
|
|
| 166 |
|
{ |
| 167 |
2 |
List<Matcher<? super SequenceI>> matchers = new ArrayList<>(); |
| 168 |
2 |
for (var seq : viewport.getAlignment().getSequences()) |
| 169 |
6 |
matchers.add(hasProperty("name", equalTo(seq.getName()))); |
| 170 |
2 |
assertThat(sequences, Matchers.contains(matchers)); |
| 171 |
|
} |
| 172 |
|
|
| 173 |
|
{ |
| 174 |
2 |
var originalHidden = viewport.getAlignment().getHiddenColumns(); |
| 175 |
2 |
var resultHidden = resultAlignment.getHiddenColumns(); |
| 176 |
2 |
assertThat(resultHidden, equalTo(originalHidden)); |
| 177 |
|
} |
| 178 |
|
|
| 179 |
|
{ |
| 180 |
2 |
var hiddenColumns = viewport.getAlignment().getHiddenColumns(); |
| 181 |
2 |
List<Matcher<? super AlignmentAnnotation>> matchers = new ArrayList<>(); |
| 182 |
2 |
for (var annot : predFile.getAnnotations()) |
| 183 |
18 |
matchers.add(allOf( |
| 184 |
|
hasProperty("label", equalTo(annot.label)), |
| 185 |
|
hasProperty("annotations", matchesAnnotations(annot.annotations)) |
| 186 |
|
)); |
| 187 |
2 |
List<AlignmentAnnotation> annotations = new ArrayList<>(); |
| 188 |
2 |
for (var annot : resultAlignment.getAlignmentAnnotation()) |
| 189 |
18 |
annotations.add(new AlignmentAnnotation(annot, hiddenColumns)); |
| 190 |
2 |
assertThat(annotations, containsInAnyOrder(matchers)); |
| 191 |
|
} |
| 192 |
|
|
| 193 |
|
} |
| 194 |
|
} |