Clover icon

Coverage Report

  1. Project Clover database Wed Dec 3 2025 17:03:17 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
1.0100%
 

Contributing tests

This file is covered by 2 tests. .

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  1 toggle 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   
 
34  1 toggle 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   
 
47  1 toggle @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    // read JSON in same way - via fileparse
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    // check that
68    // scores, posterior probabilities and stuff exist.
69    }
70   
 
71  1 toggle @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    // DPTSERWFHGHLSGKEAEKLLTeKGKHGSFLVRESQSHPGDFVLSVRTgddkgesndgKSKVTHVMIR-CQELKYDVGGGERFDSLTDLVEHYKKNPmvet
91    // LGTVLQLKQP
92    // 5789*****************9799***********************999998888888********.99**************************9999
93    // 899999*999
94    // AlignmentAnnotation
95    // 101 == 8
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    // 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    }