1 package jalview.ws.ebi;
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;
13 import org.json.simple.JSONObject;
14 import org.json.simple.parser.JSONParser;
15 import org.testng.Assert;
16 import org.testng.annotations.Test;
18 public class HmmerJSONProcessTest {
19 public static File alignmentFragFile = new File(
20 "examples/testdata/hmmer3/alignment_frag.fa.gz");
22 private AlignmentI getSearchResultFragmentAlignment() throws Exception
24 AlignmentI alf = new FormatAdapter().readFile(
25 alignmentFragFile.getAbsolutePath(), DataSourceType.FILE,
31 public static File alignmentResultFile = new File(
32 "examples/testdata/hmmer3/alignment_res.fa.gz");
34 private AlignmentI getSearchResultAlignment() throws Exception
36 AlignmentI alf = new FormatAdapter().readFile(
37 alignmentResultFile.getAbsolutePath(), DataSourceType.FILE,
43 public static String hitTestFile = "examples/testdata/hmmer3/hit_fragment.json.gz",
44 hmmerResultFile = "examples/testdata/hmmer3/hmmeresult.json.gz";
47 @Test(groups = { "Functional" })
48 public void parseHitTest() throws Exception
51 Assert.assertTrue(new File(hitTestFile).exists(),
52 "Can't find test data.\n"
54 JSONParser jp = new JSONParser();
55 // read JSON in same way - via fileparse
56 Object hitfragment = jp.parse(new FileParse(hitTestFile,
57 DataSourceType.FILE).getReader());
58 Assert.assertTrue((hitfragment instanceof JSONObject),
59 "Didn't find a JSON object map in " + hitTestFile);
60 AlignmentI searchResult = getSearchResultFragmentAlignment();
62 Assert.assertTrue(searchResult != null && searchResult.getHeight() > 0,
63 "Didn't read search result alignment from " + alignmentFragFile);
65 HmmerJSONProcessor hjsp = new HmmerJSONProcessor(searchResult);
66 hjsp.addHit((JSONObject) hitfragment, 1);
68 // scores, posterior probabilities and stuff exist.
71 @Test(groups = { "Functional" })
72 public void parseJsonResultTest() throws Exception
75 Assert.assertTrue(new File(hmmerResultFile).exists(),
76 "Can't find test data.\n" + hmmerResultFile);
78 AlignmentI searchResult = getSearchResultAlignment();
80 Assert.assertTrue(searchResult != null && searchResult.getHeight() > 0,
81 "Didn't read search result alignment from " + alignmentFragFile);
83 HmmerJSONProcessor hjsp = new HmmerJSONProcessor(searchResult);
84 hjsp.parseFrom(new FileParse(hmmerResultFile, DataSourceType.FILE));
85 AlignmentAnnotation[] aa = searchResult.getSequenceAt(5)
87 Assert.assertNotNull(aa);
88 Assert.assertEquals(aa.length, 3,
89 "didn't get expected set of annotation.\n");
90 // DPTSERWFHGHLSGKEAEKLLTeKGKHGSFLVRESQSHPGDFVLSVRTgddkgesndgKSKVTHVMIR-CQELKYDVGGGERFDSLTDLVEHYKKNPmvet
92 // 5789*****************9799***********************999998888888********.99**************************9999
94 // AlignmentAnnotation
97 SequenceI s5 = searchResult.getSequenceAt(5);
99 s5.getSubSequence(s5.findIndex(225), s5.findIndex(229))
100 .getSequenceAsString(),
102 int pos = s5.findIndex(226);
103 for (AlignmentAnnotation an : aa)
105 if (an.label.startsWith("Posterior"))
107 Assert.assertEquals(an.annotations[pos].value, 8f);
113 // scores, posterior probabilities and stuff exist.
116 // def al = Jalview.getAlignFrames()[0].getViewport().getAlignment()
117 // def jproc = new jalview.ws.ebi.HmmerJSONProcessor(al)
118 // jproc.parseFrom(new
119 // jalview.io.FileParse("examples/testdata/hmmer3/hmmeresult.json.gz","File"))
120 // jproc.updateView(Jalview.getAlignFrames()[0].getViewport())