1 package jalview.ws.ebi;
3 import jalview.datamodel.AlignmentAnnotation;
4 import jalview.datamodel.AlignmentI;
5 import jalview.datamodel.SequenceI;
6 import jalview.io.FileParse;
7 import jalview.io.FormatAdapter;
11 import org.json.simple.JSONObject;
12 import org.json.simple.parser.JSONParser;
13 import org.testng.Assert;
14 import org.testng.annotations.Test;
16 public class HmmerJSONProcessTest {
17 public static File alignmentFragFile = new File(
18 "examples/testdata/hmmer3/alignment_frag.fa.gz");
20 private AlignmentI getSearchResultFragmentAlignment() throws Exception
22 AlignmentI alf = new FormatAdapter().readFile(
23 alignmentFragFile.getAbsolutePath(), FormatAdapter.FILE,
29 public static File alignmentResultFile = new File(
30 "examples/testdata/hmmer3/alignment_res.fa.gz");
32 private AlignmentI getSearchResultAlignment() throws Exception
34 AlignmentI alf = new FormatAdapter().readFile(
35 alignmentResultFile.getAbsolutePath(), FormatAdapter.FILE,
41 public static String hitTestFile = "examples/testdata/hmmer3/hit_fragment.json.gz",
42 hmmerResultFile = "examples/testdata/hmmer3/hmmeresult.json.gz";
45 @Test(groups = { "Functional" })
46 public void parseHitTest() throws Exception
49 Assert.assertTrue(new File(hitTestFile).exists(),
50 "Can't find test data.\n"
52 JSONParser jp = new JSONParser();
53 // read JSON in same way - via fileparse
54 Object hitfragment = jp.parse(new FileParse(hitTestFile,
55 FormatAdapter.FILE).getReader());
56 Assert.assertTrue((hitfragment instanceof JSONObject),
57 "Didn't find a JSON object map in " + hitTestFile);
58 AlignmentI searchResult = getSearchResultFragmentAlignment();
60 Assert.assertTrue(searchResult != null && searchResult.getHeight() > 0,
61 "Didn't read search result alignment from " + alignmentFragFile);
63 HmmerJSONProcessor hjsp = new HmmerJSONProcessor(searchResult);
64 hjsp.addHit((JSONObject) hitfragment, 1);
66 // scores, posterior probabilities and stuff exist.
69 @Test(groups = { "Functional" })
70 public void parseJsonResultTest() throws Exception
73 Assert.assertTrue(new File(hmmerResultFile).exists(),
74 "Can't find test data.\n" + hmmerResultFile);
76 AlignmentI searchResult = getSearchResultAlignment();
78 Assert.assertTrue(searchResult != null && searchResult.getHeight() > 0,
79 "Didn't read search result alignment from " + alignmentFragFile);
81 HmmerJSONProcessor hjsp = new HmmerJSONProcessor(searchResult);
82 hjsp.parseFrom(new FileParse(hmmerResultFile, FormatAdapter.FILE));
83 AlignmentAnnotation[] aa = searchResult.getSequenceAt(5)
85 Assert.assertNotNull(aa);
86 Assert.assertEquals(aa.length, 3,
87 "didn't get expected set of annotation.\n");
88 // DPTSERWFHGHLSGKEAEKLLTeKGKHGSFLVRESQSHPGDFVLSVRTgddkgesndgKSKVTHVMIR-CQELKYDVGGGERFDSLTDLVEHYKKNPmvet
90 // 5789*****************9799***********************999998888888********.99**************************9999
92 // AlignmentAnnotation
95 SequenceI s5 = searchResult.getSequenceAt(5);
97 s5.getSubSequence(s5.findIndex(225), s5.findIndex(229))
98 .getSequenceAsString(),
100 int pos = s5.findIndex(226);
101 for (AlignmentAnnotation an : aa)
103 if (an.label.startsWith("Posterior"))
105 Assert.assertEquals(an.annotations[pos].value, 8f);
111 // scores, posterior probabilities and stuff exist.
114 // def al = Jalview.getAlignFrames()[0].getViewport().getAlignment()
115 // new jalview.ws.ebi.HmmerJSONProcessor(al).parseFrom(new
116 // jalview.io.FileParse("examples/testdata/hmmer3/hmmeresult.json.gz","File"))