JAL-1950 first stab at Hmmer3 JSON parser and alignment decorator
[jalview.git] / test / jalview / ws / ebi / HmmerJSONProcessTest.java
1 package jalview.ws.ebi;
2
3 import jalview.datamodel.AlignmentI;
4 import jalview.io.FileParse;
5 import jalview.io.FormatAdapter;
6
7 import java.io.File;
8
9 import org.json.simple.JSONObject;
10 import org.json.simple.parser.JSONParser;
11 import org.testng.Assert;
12 import org.testng.annotations.Test;
13
14 public class HmmerJSONProcessTest {
15   public static File alignmentFragFile = new File(
16           "examples/testdata/hmmer3/alignment_frag.fa.gz");
17
18   private AlignmentI getSearchResultFragmentAlignment() throws Exception
19   {
20     AlignmentI alf = new FormatAdapter().readFile(
21             alignmentFragFile.getAbsolutePath(), FormatAdapter.FILE,
22             "FASTA");
23
24     return alf;
25   }
26
27   public static File alignmentResultFile = new File(
28           "examples/testdata/hmmer3/alignment_res.fa.gz");
29
30   private AlignmentI getSearchResultAlignment() throws Exception
31   {
32     AlignmentI alf = new FormatAdapter().readFile(
33             alignmentResultFile.getAbsolutePath(), FormatAdapter.FILE,
34             "FASTA");
35
36     return alf;
37   }
38
39   public static String hitTestFile = "examples/testdata/hmmer3/hit_fragment.json.gz",
40           hmmerResultFile = "examples/testdata/hmmer3/hmmeresult.json.gz";
41
42
43   @Test(groups = { "Functional" })
44   public void parseHitTest() throws Exception
45   {
46
47     Assert.assertTrue(new File(hitTestFile).exists(),
48             "Can't find test data.\n"
49             + hitTestFile);
50     JSONParser jp = new JSONParser();
51     // read JSON in same way - via fileparse
52     Object hitfragment = jp.parse(new FileParse(hitTestFile,
53             FormatAdapter.FILE).getReader());
54     Assert.assertTrue((hitfragment instanceof JSONObject),
55             "Didn't find a JSON object map in " + hitTestFile);
56     AlignmentI searchResult = getSearchResultFragmentAlignment();
57
58     Assert.assertTrue(searchResult != null && searchResult.getHeight() > 0,
59             "Didn't read search result alignment from " + alignmentFragFile);
60
61     HmmerJSONProcessor hjsp = new HmmerJSONProcessor(searchResult);
62     hjsp.addHit((JSONObject) hitfragment, 1);
63     // check that
64     // scores, posterior probabilities and stuff exist.
65   }
66
67   @Test(groups = { "Functional" })
68   public void parseJsonResultTest() throws Exception
69   {
70
71     Assert.assertTrue(new File(hmmerResultFile).exists(),
72             "Can't find test data.\n" + hmmerResultFile);
73
74     AlignmentI searchResult = getSearchResultAlignment();
75
76     Assert.assertTrue(searchResult != null && searchResult.getHeight() > 0,
77             "Didn't read search result alignment from " + alignmentFragFile);
78
79     HmmerJSONProcessor hjsp = new HmmerJSONProcessor(searchResult);
80     hjsp.parseFrom(new FileParse(hmmerResultFile, FormatAdapter.FILE));
81     // check that
82     // scores, posterior probabilities and stuff exist.
83   }
84   // Groovy test
85   // def al = Jalview.getAlignFrames()[0].getViewport().getAlignment()
86   // new jalview.ws.ebi.HmmerJSONProcessor(al).parseFrom(new
87   // jalview.io.FileParse("examples/testdata/hmmer3/hmmeresult.json.gz","File"))
88
89 }