| 1 |
|
package jalview.ws.ebi; |
| 2 |
|
|
| 3 |
|
import jalview.datamodel.AlignmentAnnotation; |
| 4 |
|
import jalview.datamodel.AlignmentI; |
| 5 |
|
import jalview.datamodel.Annotation; |
| 6 |
|
import jalview.datamodel.SequenceFeature; |
| 7 |
|
import jalview.datamodel.SequenceGroup; |
| 8 |
|
import jalview.datamodel.SequenceI; |
| 9 |
|
import jalview.io.FileParse; |
| 10 |
|
import jalview.viewmodel.AlignmentViewport; |
| 11 |
|
|
| 12 |
|
import java.io.IOException; |
| 13 |
|
import java.util.ArrayList; |
| 14 |
|
import java.util.HashMap; |
| 15 |
|
import java.util.List; |
| 16 |
|
import java.util.Map; |
| 17 |
|
|
| 18 |
|
import org.json.simple.JSONArray; |
| 19 |
|
import org.json.simple.JSONObject; |
| 20 |
|
import org.json.simple.parser.JSONParser; |
| 21 |
|
|
| |
|
| 77.4% |
Uncovered Elements: 35 (155) |
Complexity: 32 |
Complexity Density: 0.29 |
|
| 22 |
|
public class HmmerJSONProcessor |
| 23 |
|
{ |
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
AlignmentI resultAl; |
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
|
| 32 |
|
AlignmentViewport viewAl = null; |
| 33 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 34 |
2 |
public HmmerJSONProcessor(AlignmentI searchResult)... |
| 35 |
|
{ |
| 36 |
2 |
resultAl = searchResult; |
| 37 |
|
} |
| 38 |
|
|
| |
|
| 72.7% |
Uncovered Elements: 6 (22) |
Complexity: 5 |
Complexity Density: 0.28 |
|
| 39 |
1 |
public void parseFrom(FileParse jsonsource) throws IOException,... |
| 40 |
|
OutOfMemoryError |
| 41 |
|
{ |
| 42 |
1 |
JSONParser hmmerResultParser = new JSONParser(); |
| 43 |
1 |
Object jsonResults = null; |
| 44 |
1 |
try |
| 45 |
|
{ |
| 46 |
1 |
jsonResults = hmmerResultParser.parse(jsonsource.getReader()); |
| 47 |
|
} catch (Exception p) |
| 48 |
|
{ |
| 49 |
0 |
throw new IOException("While parsing from " + jsonsource.getInFile(), |
| 50 |
|
p); |
| 51 |
|
} |
| 52 |
1 |
if (jsonResults == null) |
| 53 |
|
{ |
| 54 |
0 |
throw new IOException("No data at" + jsonsource.getInFile()); |
| 55 |
|
} |
| 56 |
1 |
if (!(jsonResults instanceof JSONObject)) |
| 57 |
|
{ |
| 58 |
0 |
throw new IOException("Unexpected JSON model at " |
| 59 |
|
+ jsonsource.getInFile()); |
| 60 |
|
} |
| 61 |
1 |
try |
| 62 |
|
{ |
| 63 |
1 |
JSONObject hmmsearchr = (JSONObject) ((JSONObject) jsonResults) |
| 64 |
|
.get("results"); |
| 65 |
|
|
| 66 |
1 |
addStatistics((JSONObject) hmmsearchr.get("stats")); |
| 67 |
1 |
JSONArray jsonArray = (JSONArray) hmmsearchr.get("hits"); |
| 68 |
1 |
long p = 1; |
| 69 |
1 |
for (Object hit : jsonArray) |
| 70 |
|
{ |
| 71 |
543 |
JSONObject hmmhit = (JSONObject) hit; |
| 72 |
543 |
addHit(hmmhit, p++); |
| 73 |
|
} |
| 74 |
|
} catch (ClassCastException q) |
| 75 |
|
{ |
| 76 |
0 |
throw new IOException("Unexpected JSON model content at " |
| 77 |
|
+ jsonsource.getInFile(), q); |
| 78 |
|
} |
| 79 |
|
} |
| 80 |
|
|
| 81 |
|
|
| 82 |
|
|
| 83 |
|
@param |
| 84 |
|
|
| 85 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 86 |
1 |
public void addStatistics(JSONObject stats)... |
| 87 |
|
{ |
| 88 |
1 |
for (Object stat : stats.keySet()) |
| 89 |
|
{ |
| 90 |
17 |
String key = (String) stat; |
| 91 |
17 |
Object val = stats.get(key); |
| 92 |
17 |
resultAl.setProperty(key, "" + val); |
| 93 |
|
} |
| 94 |
|
} |
| 95 |
|
|
| 96 |
|
|
| 97 |
|
|
| 98 |
|
|
| 99 |
|
|
| 100 |
|
private String[] score = { "aliId", "ali_IdCount", "bitscore", "ievalue", |
| 101 |
|
"aliSim", "aliSimCount", "aliL", "aliSim", "ievalue", "cevalue" }; |
| 102 |
|
|
| 103 |
|
|
| 104 |
|
|
| 105 |
|
|
| 106 |
|
|
| 107 |
|
private String[] attrib = { "bias", "oasc", "is_included", "is_reported" }; |
| 108 |
|
|
| 109 |
|
|
| 110 |
|
|
| 111 |
|
|
| 112 |
|
private String[] label = { "alihmmname" |
| 113 |
|
}; |
| 114 |
|
|
| 115 |
|
|
| 116 |
|
|
| 117 |
|
|
| 118 |
|
private String[] ipos = { "alihmmfrom", "alihmmto" }, pos_l = { |
| 119 |
|
"alimline", "alimodel", "alirfline" }; |
| 120 |
|
|
| 121 |
|
|
| 122 |
|
|
| 123 |
|
|
| 124 |
|
private String[] pos_nscore = { "alippline" }; |
| 125 |
|
|
| 126 |
|
|
| 127 |
|
|
| 128 |
|
|
| |
|
| 91.1% |
Uncovered Elements: 4 (45) |
Complexity: 6 |
Complexity Density: 0.16 |
|
| 129 |
544 |
public void addHit(JSONObject hmmrhit, long p)... |
| 130 |
|
{ |
| 131 |
544 |
String sname = (String) hmmrhit.get("name"); |
| 132 |
544 |
SequenceI[] hits = resultAl.findSequenceMatch(sname); |
| 133 |
544 |
if (hits == null) |
| 134 |
|
{ |
| 135 |
0 |
System.err.println("No seq for " + sname); |
| 136 |
|
} |
| 137 |
544 |
double pvalue = (Double) hmmrhit.get("pvalue"); |
| 138 |
|
|
| 139 |
544 |
double evalue = Double.valueOf("" + hmmrhit.get("evalue")); |
| 140 |
544 |
for (Object domainhit : ((JSONArray) hmmrhit.get("domains"))) |
| 141 |
|
{ |
| 142 |
588 |
JSONObject dhit = (JSONObject) domainhit; |
| 143 |
|
|
| 144 |
|
|
| 145 |
|
|
| 146 |
588 |
long alihmmfrom = (long) dhit.get("alihmmfrom"), alihmmto = (long) dhit |
| 147 |
|
.get("alihmmto"), alisqfrom = (long) dhit.get("alisqfrom"), alisqto = (long) dhit |
| 148 |
|
.get("alisqto"); |
| 149 |
|
|
| 150 |
|
|
| 151 |
|
|
| 152 |
|
|
| 153 |
588 |
String aliaseq = (String) dhit.get("aliaseq"), alimodel = (String) dhit |
| 154 |
|
.get("alimodel"), ppline = (String) dhit.get("alippline"); |
| 155 |
|
|
| 156 |
588 |
int found = 0; |
| 157 |
588 |
SequenceI firsthit = null; |
| 158 |
588 |
for (SequenceI hitseq : hits) |
| 159 |
|
{ |
| 160 |
|
|
| 161 |
682 |
if (hitseq.getStart() == alisqfrom && hitseq.getEnd() == alisqto) |
| 162 |
|
{ |
| 163 |
588 |
if (found == 0) |
| 164 |
|
{ |
| 165 |
588 |
firsthit = hitseq; |
| 166 |
|
} |
| 167 |
588 |
found++; |
| 168 |
588 |
AlignmentAnnotation alipp = parsePosteriorProb(ppline); |
| 169 |
588 |
AlignmentAnnotation pval = new AlignmentAnnotation("p-value", |
| 170 |
|
"hmmer3 pvalue", pvalue); |
| 171 |
588 |
AlignmentAnnotation eval = new AlignmentAnnotation("e-value", |
| 172 |
|
"hmmer3 evalue", evalue); |
| 173 |
588 |
pval.setCalcId("HMMER3"); |
| 174 |
588 |
eval.setCalcId("HMMER3"); |
| 175 |
588 |
alipp.setCalcId("HMMER3"); |
| 176 |
588 |
hitseq.addAlignmentAnnotation(pval); |
| 177 |
588 |
hitseq.addAlignmentAnnotation(eval); |
| 178 |
588 |
alipp.createSequenceMapping(hitseq, hitseq.getStart(), false); |
| 179 |
588 |
hitseq.addAlignmentAnnotation(alipp); |
| 180 |
588 |
String arch; |
| 181 |
588 |
hitseq.addSequenceFeature(new SequenceFeature( |
| 182 |
|
"Pfam Domain Architecture", (hmmrhit.get("archindex")) |
| 183 |
|
+ " " + (arch = (String) hmmrhit.get("arch")), 0, |
| 184 |
|
0, |
| 185 |
588 |
(hmmrhit.get("archScore") != null ? Integer |
| 186 |
|
.valueOf((String) hmmrhit.get("archScore")) : 0f), |
| 187 |
|
"HMMER3")); |
| 188 |
588 |
addArchGroup(hitseq, arch); |
| 189 |
588 |
alipp.setScore(Double.valueOf("" + dhit.get("bitscore"))); |
| 190 |
588 |
alipp.adjustForAlignment(); |
| 191 |
588 |
resultAl.addAnnotation(pval); |
| 192 |
588 |
resultAl.addAnnotation(eval); |
| 193 |
588 |
resultAl.addAnnotation(alipp); |
| 194 |
588 |
alipp.validateRangeAndDisplay(); |
| 195 |
|
} |
| 196 |
|
} |
| 197 |
|
|
| 198 |
|
|
| 199 |
588 |
addRedundantSeqGroup(firsthit, alisqfrom, alisqto, |
| 200 |
|
(JSONArray) hmmrhit.get("seqs"), true); |
| 201 |
|
} |
| 202 |
|
} |
| 203 |
|
|
| 204 |
|
|
| 205 |
|
|
| 206 |
|
|
| 207 |
|
|
| 208 |
|
private List<Runnable> viewOps = new ArrayList<Runnable>(); |
| 209 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 210 |
0 |
public void updateView(AlignmentViewport view)... |
| 211 |
|
{ |
| 212 |
0 |
viewAl = view; |
| 213 |
0 |
for (Runnable op : viewOps) |
| 214 |
|
{ |
| 215 |
0 |
op.run(); |
| 216 |
|
} |
| 217 |
|
} |
| 218 |
|
|
| |
|
| 52.5% |
Uncovered Elements: 19 (40) |
Complexity: 10 |
Complexity Density: 0.38 |
|
| 219 |
588 |
private void addRedundantSeqGroup(final SequenceI firsthit,... |
| 220 |
|
long alisqfrom, long alisqto, JSONArray others, boolean justDelete) |
| 221 |
|
{ |
| 222 |
588 |
if (others != null) |
| 223 |
|
{ |
| 224 |
231 |
final SequenceGroup repgroup = new SequenceGroup(); |
| 225 |
231 |
repgroup.setSeqrep(firsthit); |
| 226 |
231 |
repgroup.addOrRemove(firsthit, false); |
| 227 |
231 |
repgroup.setStartRes(0); |
| 228 |
231 |
repgroup.setEndRes(resultAl.getWidth() - 1); |
| 229 |
231 |
for (Object otherseq : others.toArray(new JSONObject[0])) |
| 230 |
|
{ |
| 231 |
594 |
String repseq = (String) ((JSONObject) otherseq).get("dn"); |
| 232 |
594 |
SequenceI[] other = resultAl.findSequenceMatch(repseq); |
| 233 |
594 |
if (other != null && other.length > 0) |
| 234 |
|
{ |
| 235 |
573 |
if (justDelete) |
| 236 |
|
{ |
| 237 |
573 |
for (SequenceI oth : other) |
| 238 |
|
{ |
| 239 |
594 |
resultAl.deleteSequence(oth); |
| 240 |
|
} |
| 241 |
573 |
; |
| 242 |
|
} |
| 243 |
|
else |
| 244 |
|
{ |
| 245 |
0 |
int ofound = 0; |
| 246 |
0 |
for (SequenceI oth : other) |
| 247 |
|
{ |
| 248 |
0 |
if (oth.getStart() == alisqfrom && oth.getEnd() == alisqto) |
| 249 |
|
{ |
| 250 |
0 |
ofound++; |
| 251 |
0 |
repgroup.addSequence(oth, false); |
| 252 |
|
} |
| 253 |
|
} |
| 254 |
0 |
if (ofound == 0) |
| 255 |
|
{ |
| 256 |
0 |
System.err.println("Warn - no match for redundant hit " |
| 257 |
|
+ repseq + "/" + alisqfrom + "-" + alisqto); |
| 258 |
|
} |
| 259 |
0 |
if (ofound > 1) |
| 260 |
|
{ |
| 261 |
0 |
System.err |
| 262 |
|
.println("Warn - multiple matches for redundant hit " |
| 263 |
|
+ repseq + "/" + alisqfrom + "-" + alisqto); |
| 264 |
|
} |
| 265 |
|
} |
| 266 |
|
} |
| 267 |
|
} |
| 268 |
231 |
if (repgroup.getSequences().size() > 1) |
| 269 |
|
{ |
| 270 |
|
|
| 271 |
0 |
final HmmerJSONProcessor me = this; |
| 272 |
0 |
viewOps.add(new Runnable() |
| 273 |
|
{ |
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 274 |
0 |
@Override... |
| 275 |
|
public void run() |
| 276 |
|
{ |
| 277 |
0 |
me.viewAl.hideRepSequences(firsthit, repgroup); |
| 278 |
|
} |
| 279 |
|
}); |
| 280 |
|
} |
| 281 |
|
} |
| 282 |
|
} |
| 283 |
|
|
| 284 |
|
Map<String, SequenceGroup> groups = new HashMap<String, SequenceGroup>(); |
| 285 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
|
| 286 |
588 |
private void addArchGroup(SequenceI seqToAdd, String groupNam)... |
| 287 |
|
{ |
| 288 |
588 |
SequenceGroup sg = groups.get(groupNam); |
| 289 |
588 |
if (sg == null) |
| 290 |
|
{ |
| 291 |
52 |
sg = new SequenceGroup(); |
| 292 |
52 |
sg.setName(groupNam); |
| 293 |
52 |
sg.addSequence(seqToAdd, false); |
| 294 |
52 |
sg.setStartRes(0); |
| 295 |
52 |
sg.setEndRes(resultAl.getWidth() - 1); |
| 296 |
52 |
groups.put(groupNam, sg); |
| 297 |
52 |
resultAl.addGroup(sg); |
| 298 |
|
} |
| 299 |
|
else |
| 300 |
|
{ |
| 301 |
536 |
sg.addSequence(seqToAdd, false); |
| 302 |
|
} |
| 303 |
|
} |
| 304 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 5 |
Complexity Density: 0.42 |
|
| 305 |
588 |
private AlignmentAnnotation parsePosteriorProb(String ppline)... |
| 306 |
|
{ |
| 307 |
588 |
Annotation[] ae = new Annotation[ppline.length()]; |
| 308 |
588 |
int spos = 0; |
| 309 |
46572 |
for (int i = 0, iSize = ppline.length(); i < iSize; i++) |
| 310 |
|
{ |
| 311 |
45984 |
char pp = ppline.charAt(i); |
| 312 |
45984 |
if (pp == '*') |
| 313 |
|
{ |
| 314 |
35142 |
ae[spos++] = new Annotation(10f); |
| 315 |
|
} |
| 316 |
|
else |
| 317 |
|
{ |
| 318 |
10842 |
if (pp >= '0' && pp <= '9') |
| 319 |
|
{ |
| 320 |
10267 |
ae[spos++] = new Annotation(Integer.valueOf("" + pp)); |
| 321 |
|
} |
| 322 |
|
} |
| 323 |
|
} |
| 324 |
588 |
AlignmentAnnotation pprob = new AlignmentAnnotation( |
| 325 |
|
"Posterior Probability", |
| 326 |
|
"Likelihood of HMM fit at each hit position.", ae); |
| 327 |
588 |
pprob.graph = AlignmentAnnotation.BAR_GRAPH; |
| 328 |
588 |
pprob.visible = false; |
| 329 |
588 |
return pprob; |
| 330 |
|
} |
| 331 |
|
} |