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);
81 // mapping of keys to types of property on sequence
83 public void addHit(JSONObject hmmrhit, long p)
85 String sname = (String) hmmrhit.get("name");
86 SequenceI[] hits = resultAl.findSequenceMatch(sname);
89 System.err.println("No seq for " + sname);
91 double pvalue = (Double) hmmrhit.get("pvalue");
93 double evalue = Double.valueOf("" + hmmrhit.get("evalue"));
94 for (Object domainhit : ((JSONArray) hmmrhit.get("domains")))
96 JSONObject dhit=(JSONObject) domainhit;
99 // alihmmfrom,alihmmto alimodel
100 // alisqfrom,alisqto,aliaseq
103 for (SequenceI hitseq : hits)
105 // match alisqfrom,alisqto,seq
106 // overlay ppline as seqannotation
111 AlignmentAnnotation pval = new AlignmentAnnotation("p-value",
112 "hmmer3 pvalue", pvalue);
113 AlignmentAnnotation eval = new AlignmentAnnotation("e-value",
114 "hmmer3 evalue", evalue);
115 hitseq.addAlignmentAnnotation(pval);
116 hitseq.addAlignmentAnnotation(eval);