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;
8 import java.io.IOException;
10 import org.json.simple.JSONArray;
11 import org.json.simple.JSONObject;
12 import org.json.simple.parser.JSONParser;
14 public class HmmerJSONProcessor
18 public HmmerJSONProcessor(AlignmentI searchResult)
20 resultAl = searchResult;
23 public void parseFrom(FileParse jsonsource) throws IOException,
26 JSONParser hmmerResultParser = new JSONParser();
27 Object jsonResults = null;
30 jsonResults = hmmerResultParser.parse(jsonsource.getReader());
33 throw new IOException("While parsing from " + jsonsource.getInFile(),
36 if (jsonResults == null)
38 throw new IOException("No data at" + jsonsource.getInFile());
40 if (!(jsonResults instanceof JSONObject))
42 throw new IOException("Unexpected JSON model at "
43 + jsonsource.getInFile());
47 JSONObject hmmsearchr = (JSONObject) ((JSONObject) jsonResults)
49 // now process the hits
50 addStatistics((JSONObject) hmmsearchr.get("stats"));
51 JSONArray jsonArray = (JSONArray) hmmsearchr.get("hits");
53 for (Object hit : jsonArray)
55 JSONObject hmmhit = (JSONObject) hit;
58 } catch (ClassCastException q)
60 throw new IOException("Unexpected JSON model content at "
61 + jsonsource.getInFile(), q);
68 * - actually a JSONObject key value set of search statistics.
70 public void addStatistics(JSONObject stats)
72 for (Object stat : stats.keySet())
74 String key = (String) stat;
75 Object val = stats.get(key);
76 resultAl.setProperty(key, "" + val);
80 // encodings for JSON keys
82 * score becomes sequence associated AlignmentAnnotation
84 private String[] score = { "aliId", "ali_IdCount", "bitscore", "ievalue",
85 "aliSim", "aliSimCount", "aliL", "aliSim", "ievalue", "cevalue" };
88 * attrib becomes numeric or binary attribute for sequence with respect to
91 private String[] attrib = { "bias", "oasc", "is_included", "is_reported" };
94 * name of the hmmsearch query
96 private String[] label = { "alihmmname" // (query label?)},
100 * integer attributes for each
102 private String[] ipos = { "alihmmfrom", "alihmmto" }, pos_l = {
103 "alimline", "alimodel", "alirfline" };
106 * positional quantitative annotation encoded as strings.
108 private String[] pos_nscore = { "alippline" };
111 // mapping of keys to types of property on sequence
113 public void addHit(JSONObject hmmrhit, long p)
115 String sname = (String) hmmrhit.get("name");
116 SequenceI[] hits = resultAl.findSequenceMatch(sname);
119 System.err.println("No seq for " + sname);
121 double pvalue = (Double) hmmrhit.get("pvalue");
123 double evalue = Double.valueOf("" + hmmrhit.get("evalue"));
124 for (Object domainhit : ((JSONArray) hmmrhit.get("domains")))
126 JSONObject dhit=(JSONObject) domainhit;
129 // alihmmfrom,alihmmto alimodel
130 // alisqfrom,alisqto,aliaseq
133 for (SequenceI hitseq : hits)
135 // match alisqfrom,alisqto,seq
136 // overlay ppline as seqannotation
141 AlignmentAnnotation pval = new AlignmentAnnotation("p-value",
142 "hmmer3 pvalue", pvalue);
143 AlignmentAnnotation eval = new AlignmentAnnotation("e-value",
144 "hmmer3 evalue", evalue);
145 hitseq.addAlignmentAnnotation(pval);
146 hitseq.addAlignmentAnnotation(eval);