| 1 |
|
package jalview.ws.ebi; |
| 2 |
|
|
| 3 |
|
import jalview.datamodel.AlignmentAnnotation; |
| 4 |
|
import jalview.datamodel.AlignmentI; |
| 5 |
|
import jalview.datamodel.SequenceI; |
| 6 |
|
import jalview.io.DataSourceType; |
| 7 |
|
import jalview.io.FileFormat; |
| 8 |
|
import jalview.io.FileParse; |
| 9 |
|
import jalview.io.FormatAdapter; |
| 10 |
|
|
| 11 |
|
import java.io.File; |
| 12 |
|
|
| 13 |
|
import org.json.simple.JSONObject; |
| 14 |
|
import org.json.simple.parser.JSONParser; |
| 15 |
|
import org.testng.Assert; |
| 16 |
|
import org.testng.annotations.Test; |
| 17 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (34) |
Complexity: 5 |
Complexity Density: 0.18 |
|
| 18 |
|
public class HmmerJSONProcessTest { |
| 19 |
|
public static File alignmentFragFile = new File( |
| 20 |
|
"examples/testdata/hmmer3/alignment_frag.fa.gz"); |
| 21 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 22 |
1 |
private AlignmentI getSearchResultFragmentAlignment() throws Exception... |
| 23 |
|
{ |
| 24 |
1 |
AlignmentI alf = new FormatAdapter().readFile( |
| 25 |
|
alignmentFragFile.getAbsolutePath(), DataSourceType.FILE, |
| 26 |
|
FileFormat.Fasta); |
| 27 |
|
|
| 28 |
1 |
return alf; |
| 29 |
|
} |
| 30 |
|
|
| 31 |
|
public static File alignmentResultFile = new File( |
| 32 |
|
"examples/testdata/hmmer3/alignment_res.fa.gz"); |
| 33 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 34 |
1 |
private AlignmentI getSearchResultAlignment() throws Exception... |
| 35 |
|
{ |
| 36 |
1 |
AlignmentI alf = new FormatAdapter().readFile( |
| 37 |
|
alignmentResultFile.getAbsolutePath(), DataSourceType.FILE, |
| 38 |
|
FileFormat.Fasta); |
| 39 |
|
|
| 40 |
1 |
return alf; |
| 41 |
|
} |
| 42 |
|
|
| 43 |
|
public static String hitTestFile = "examples/testdata/hmmer3/hit_fragment.json.gz", |
| 44 |
|
hmmerResultFile = "examples/testdata/hmmer3/hmmeresult.json.gz"; |
| 45 |
|
|
| 46 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
| 47 |
1 |
@Test(groups = { "Functional" })... |
| 48 |
|
public void parseHitTest() throws Exception |
| 49 |
|
{ |
| 50 |
|
|
| 51 |
1 |
Assert.assertTrue(new File(hitTestFile).exists(), |
| 52 |
|
"Can't find test data.\n" |
| 53 |
|
+ hitTestFile); |
| 54 |
1 |
JSONParser jp = new JSONParser(); |
| 55 |
|
|
| 56 |
1 |
Object hitfragment = jp.parse(new FileParse(hitTestFile, |
| 57 |
|
DataSourceType.FILE).getReader()); |
| 58 |
1 |
Assert.assertTrue((hitfragment instanceof JSONObject), |
| 59 |
|
"Didn't find a JSON object map in " + hitTestFile); |
| 60 |
1 |
AlignmentI searchResult = getSearchResultFragmentAlignment(); |
| 61 |
|
|
| 62 |
1 |
Assert.assertTrue(searchResult != null && searchResult.getHeight() > 0, |
| 63 |
|
"Didn't read search result alignment from " + alignmentFragFile); |
| 64 |
|
|
| 65 |
1 |
HmmerJSONProcessor hjsp = new HmmerJSONProcessor(searchResult); |
| 66 |
1 |
hjsp.addHit((JSONObject) hitfragment, 1); |
| 67 |
|
|
| 68 |
|
|
| 69 |
|
} |
| 70 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 2 |
Complexity Density: 0.12 |
1PASS
|
|
| 71 |
1 |
@Test(groups = { "Functional" })... |
| 72 |
|
public void parseJsonResultTest() throws Exception |
| 73 |
|
{ |
| 74 |
|
|
| 75 |
1 |
Assert.assertTrue(new File(hmmerResultFile).exists(), |
| 76 |
|
"Can't find test data.\n" + hmmerResultFile); |
| 77 |
|
|
| 78 |
1 |
AlignmentI searchResult = getSearchResultAlignment(); |
| 79 |
|
|
| 80 |
1 |
Assert.assertTrue(searchResult != null && searchResult.getHeight() > 0, |
| 81 |
|
"Didn't read search result alignment from " + alignmentFragFile); |
| 82 |
|
|
| 83 |
1 |
HmmerJSONProcessor hjsp = new HmmerJSONProcessor(searchResult); |
| 84 |
1 |
hjsp.parseFrom(new FileParse(hmmerResultFile, DataSourceType.FILE)); |
| 85 |
1 |
AlignmentAnnotation[] aa = searchResult.getSequenceAt(5) |
| 86 |
|
.getAnnotation(); |
| 87 |
1 |
Assert.assertNotNull(aa); |
| 88 |
1 |
Assert.assertEquals(aa.length, 3, |
| 89 |
|
"didn't get expected set of annotation.\n"); |
| 90 |
|
|
| 91 |
|
|
| 92 |
|
|
| 93 |
|
|
| 94 |
|
|
| 95 |
|
|
| 96 |
1 |
String seq = "tLGT"; |
| 97 |
1 |
SequenceI s5 = searchResult.getSequenceAt(5); |
| 98 |
1 |
Assert.assertEquals( |
| 99 |
|
s5.getSubSequence(s5.findIndex(225), s5.findIndex(229)) |
| 100 |
|
.getSequenceAsString(), |
| 101 |
|
seq); |
| 102 |
1 |
int pos = s5.findIndex(226); |
| 103 |
1 |
for (AlignmentAnnotation an : aa) |
| 104 |
|
{ |
| 105 |
3 |
if (an.label.startsWith("Posterior")) |
| 106 |
|
{ |
| 107 |
1 |
Assert.assertEquals(an.annotations[pos].value, 8f); |
| 108 |
|
|
| 109 |
|
} |
| 110 |
|
} |
| 111 |
1 |
; |
| 112 |
|
|
| 113 |
|
|
| 114 |
|
} |
| 115 |
|
|
| 116 |
|
|
| 117 |
|
|
| 118 |
|
|
| 119 |
|
|
| 120 |
|
|
| 121 |
|
|
| 122 |
|
} |