JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / bin / jalview / io / JnetAnnotationMaker.js
1 Clazz.declarePackage ("jalview.io");\r
2 Clazz.load (null, "jalview.io.JnetAnnotationMaker", ["jalview.datamodel.AlignmentAnnotation", "$.Annotation", "jalview.util.MessageManager", "java.lang.Exception", "$.Float"], function () {\r
3 c$ = Clazz.declareType (jalview.io, "JnetAnnotationMaker");\r
4 c$.add_annotation = Clazz.defineMethod (c$, "add_annotation", \r
5 function (prediction, al, firstSeq, noMsa) {\r
6 jalview.io.JnetAnnotationMaker.add_annotation (prediction, al, firstSeq, noMsa, Clazz.castNullAs ("Array"));\r
7 }, "jalview.io.AlignFile,jalview.datamodel.AlignmentI,~N,~B");\r
8 c$.add_annotation = Clazz.defineMethod (c$, "add_annotation", \r
9 function (prediction, al, firstSeq, noMsa, delMap) {\r
10 var i = 0;\r
11 var preds = prediction.getSeqsAsArray ();\r
12 var seqRef = al.getSequenceAt (firstSeq);\r
13 var width = preds[0].getSequence ().length;\r
14 var gapmap = al.getSequenceAt (firstSeq).gapMap ();\r
15 if ((delMap != null && delMap.length > width) || (delMap == null && gapmap.length != width)) {\r
16 throw ( new Exception (jalview.util.MessageManager.formatMessage ("exception.number_of_residues_in_query_sequence_differ_from_prediction",  Clazz.newArray (-1, [(delMap == null ? "" : jalview.util.MessageManager.getString ("label.mapped")), al.getSequenceAt (firstSeq).getName (), al.getSequenceAt (firstSeq).getSequenceAsString (), Integer.$valueOf (width).toString ()]))));\r
17 }var annot;\r
18 var annotations = null;\r
19 var existingAnnotations = 0;\r
20 if (al.getAlignmentAnnotation () != null) {\r
21 existingAnnotations = al.getAlignmentAnnotation ().length;\r
22 }var sol =  new Array (al.getWidth ());\r
23 var firstsol = true;\r
24 while (i < preds.length) {\r
25 var id = preds[i].getName ().toUpperCase ();\r
26 if (id.startsWith ("LUPAS") || id.startsWith ("JNET") || id.startsWith ("JPRED")) {\r
27 if (id.startsWith ("JNETSOL")) {\r
28 var amnt = (id.endsWith ("25") ? 3 : id.endsWith ("5") ? 6 : 9);\r
29 for (var spos = 0; spos < width; spos++) {\r
30 var sposw = (delMap == null) ? gapmap[spos] : gapmap[delMap[spos]];\r
31 if (firstsol) {\r
32 sol[sposw] =  new jalview.datamodel.Annotation (0);\r
33 }if (preds[i].getCharAt (spos) == 'B' && (sol[sposw].value == 0 || sol[sposw].value < amnt)) {\r
34 sol[sposw].value = amnt;\r
35 }}\r
36 firstsol = false;\r
37 } else {\r
38 annotations =  new Array (al.getWidth ());\r
39 if (id.equals ("JNETPRED") || id.equals ("JNETPSSM") || id.equals ("JNETFREQ") || id.equals ("JNETHMM") || id.equals ("JNETALIGN") || id.equals ("JPRED")) {\r
40 if (delMap == null) {\r
41 for (var j = 0; j < width; j++) {\r
42 annotations[gapmap[j]] =  new jalview.datamodel.Annotation ("", "", preds[i].getCharAt (j), 0);\r
43 }\r
44 } else {\r
45 for (var j = 0; j < width; j++) {\r
46 annotations[gapmap[delMap[j]]] =  new jalview.datamodel.Annotation ("", "", preds[i].getCharAt (j), 0);\r
47 }\r
48 }} else if (id.equals ("JNETCONF")) {\r
49 if (delMap == null) {\r
50 for (var j = 0; j < width; j++) {\r
51 var value =  new Float (preds[i].getCharAt (j) + "").floatValue ();\r
52 annotations[gapmap[j]] =  new jalview.datamodel.Annotation (preds[i].getCharAt (j) + "", "", preds[i].getCharAt (j), value);\r
53 }\r
54 } else {\r
55 for (var j = 0; j < width; j++) {\r
56 var value =  new Float (preds[i].getCharAt (j) + "").floatValue ();\r
57 annotations[gapmap[delMap[j]]] =  new jalview.datamodel.Annotation (preds[i].getCharAt (j) + "", "", preds[i].getCharAt (j), value);\r
58 }\r
59 }} else {\r
60 if (delMap == null) {\r
61 for (var j = 0; j < width; j++) {\r
62 annotations[gapmap[j]] =  new jalview.datamodel.Annotation (preds[i].getCharAt (j) + "", "", ' ', 0);\r
63 }\r
64 } else {\r
65 for (var j = 0; j < width; j++) {\r
66 annotations[gapmap[delMap[j]]] =  new jalview.datamodel.Annotation (preds[i].getCharAt (j) + "", "", ' ', 0);\r
67 }\r
68 }}if (id.equals ("JNETCONF")) {\r
69 annot =  new jalview.datamodel.AlignmentAnnotation (preds[i].getName (), "JNet Output", annotations, 0, 10, 1);\r
70 } else {\r
71 annot =  new jalview.datamodel.AlignmentAnnotation (preds[i].getName (), "JNet Output", annotations);\r
72 }if (seqRef != null) {\r
73 annot.createSequenceMapping (seqRef, 1, true);\r
74 seqRef.addAlignmentAnnotation (annot);\r
75 }al.addAnnotation (annot);\r
76 al.setAnnotationIndex (annot, al.getAlignmentAnnotation ().length - existingAnnotations - 1);\r
77 }if (noMsa) {\r
78 al.deleteSequence (preds[i]);\r
79 }}i++;\r
80 }\r
81 if (!firstsol) {\r
82 annot =  new jalview.datamodel.AlignmentAnnotation ("Jnet Burial", "<html>Prediction of Solvent Accessibility<br/>levels are<ul><li>0 - Exposed</li><li>3 - 25% or more S.A. accessible</li><li>6 - 5% or more S.A. accessible</li><li>9 - Buried (<5% exposed)</li></ul>", sol, 0, 9, 1);\r
83 annot.validateRangeAndDisplay ();\r
84 if (seqRef != null) {\r
85 annot.createSequenceMapping (seqRef, 1, true);\r
86 seqRef.addAlignmentAnnotation (annot);\r
87 }al.addAnnotation (annot);\r
88 al.setAnnotationIndex (annot, al.getAlignmentAnnotation ().length - existingAnnotations - 1);\r
89 }}, "jalview.io.AlignFile,jalview.datamodel.AlignmentI,~N,~B,~A");\r
90 });\r