Clover icon

Coverage Report

  1. Project Clover database Tue Mar 10 2026 14:58:44 GMT
  2. Package jalview.ws.ebi

File HmmerJSONProcessTest.java

 

Code metrics

2
28
4
1
122
83
5
0.18
7
4
1.25

Classes

Class Line # Actions
HmmerJSONProcessTest 18 28 5
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

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   
 
18    public class HmmerJSONProcessTest {
19    public static File alignmentFragFile = new File(
20    "examples/testdata/hmmer3/alignment_frag.fa.gz");
21   
 
22  0 toggle private AlignmentI getSearchResultFragmentAlignment() throws Exception
23    {
24  0 AlignmentI alf = new FormatAdapter().readFile(
25    alignmentFragFile.getAbsolutePath(), DataSourceType.FILE,
26    FileFormat.Fasta);
27   
28  0 return alf;
29    }
30   
31    public static File alignmentResultFile = new File(
32    "examples/testdata/hmmer3/alignment_res.fa.gz");
33   
 
34  0 toggle private AlignmentI getSearchResultAlignment() throws Exception
35    {
36  0 AlignmentI alf = new FormatAdapter().readFile(
37    alignmentResultFile.getAbsolutePath(), DataSourceType.FILE,
38    FileFormat.Fasta);
39   
40  0 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   
 
47  0 toggle @Test(groups = { "Functional" })
48    public void parseHitTest() throws Exception
49    {
50   
51  0 Assert.assertTrue(new File(hitTestFile).exists(),
52    "Can't find test data.\n"
53    + hitTestFile);
54  0 JSONParser jp = new JSONParser();
55    // read JSON in same way - via fileparse
56  0 Object hitfragment = jp.parse(new FileParse(hitTestFile,
57    DataSourceType.FILE).getReader());
58  0 Assert.assertTrue((hitfragment instanceof JSONObject),
59    "Didn't find a JSON object map in " + hitTestFile);
60  0 AlignmentI searchResult = getSearchResultFragmentAlignment();
61   
62  0 Assert.assertTrue(searchResult != null && searchResult.getHeight() > 0,
63    "Didn't read search result alignment from " + alignmentFragFile);
64   
65  0 HmmerJSONProcessor hjsp = new HmmerJSONProcessor(searchResult);
66  0 hjsp.addHit((JSONObject) hitfragment, 1);
67    // check that
68    // scores, posterior probabilities and stuff exist.
69    }
70   
 
71  0 toggle @Test(groups = { "Functional" })
72    public void parseJsonResultTest() throws Exception
73    {
74   
75  0 Assert.assertTrue(new File(hmmerResultFile).exists(),
76    "Can't find test data.\n" + hmmerResultFile);
77   
78  0 AlignmentI searchResult = getSearchResultAlignment();
79   
80  0 Assert.assertTrue(searchResult != null && searchResult.getHeight() > 0,
81    "Didn't read search result alignment from " + alignmentFragFile);
82   
83  0 HmmerJSONProcessor hjsp = new HmmerJSONProcessor(searchResult);
84  0 hjsp.parseFrom(new FileParse(hmmerResultFile, DataSourceType.FILE));
85  0 AlignmentAnnotation[] aa = searchResult.getSequenceAt(5)
86    .getAnnotation();
87  0 Assert.assertNotNull(aa);
88  0 Assert.assertEquals(aa.length, 3,
89    "didn't get expected set of annotation.\n");
90    // DPTSERWFHGHLSGKEAEKLLTeKGKHGSFLVRESQSHPGDFVLSVRTgddkgesndgKSKVTHVMIR-CQELKYDVGGGERFDSLTDLVEHYKKNPmvet
91    // LGTVLQLKQP
92    // 5789*****************9799***********************999998888888********.99**************************9999
93    // 899999*999
94    // AlignmentAnnotation
95    // 101 == 8
96  0 String seq = "tLGT";
97  0 SequenceI s5 = searchResult.getSequenceAt(5);
98  0 Assert.assertEquals(
99    s5.getSubSequence(s5.findIndex(225), s5.findIndex(229))
100    .getSequenceAsString(),
101    seq);
102  0 int pos = s5.findIndex(226);
103  0 for (AlignmentAnnotation an : aa)
104    {
105  0 if (an.label.startsWith("Posterior"))
106    {
107  0 Assert.assertEquals(an.annotations[pos].value, 8f);
108   
109    }
110    }
111  0 ;
112    // check that
113    // scores, posterior probabilities and stuff exist.
114    }
115    // Groovy test
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())
121   
122    }