JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / site / j2s / jalview / structures / models / AAStructureBindingModel.js
1 Clazz.declarePackage ("jalview.structures.models");\r
2 Clazz.load (["jalview.api.StructureSelectionManagerProvider", "jalview.structure.StructureListener", "jalview.structures.models.SequenceStructureBindingModel"], "jalview.structures.models.AAStructureBindingModel", ["jalview.util.Comparison", "$.MessageManager", "java.lang.Error", "$.StringBuilder", "java.util.ArrayList", "$.Arrays"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.ssm = null;\r
5 this.pdbEntry = null;\r
6 this.sequence = null;\r
7 this.chains = null;\r
8 this.protocol = null;\r
9 this.colourBySequence = true;\r
10 this.nucleotide = false;\r
11 if (!Clazz.isClassDefined ("jalview.structures.models.AAStructureBindingModel.SuperposeData")) {\r
12 jalview.structures.models.AAStructureBindingModel.$AAStructureBindingModel$SuperposeData$ ();\r
13 }\r
14 Clazz.instantialize (this, arguments);\r
15 }, jalview.structures.models, "AAStructureBindingModel", jalview.structures.models.SequenceStructureBindingModel, [jalview.structure.StructureListener, jalview.api.StructureSelectionManagerProvider]);\r
16 Clazz.makeConstructor (c$, \r
17 function (ssm, seqs) {\r
18 Clazz.superConstructor (this, jalview.structures.models.AAStructureBindingModel, []);\r
19 this.ssm = ssm;\r
20 this.sequence = seqs;\r
21 }, "jalview.structure.StructureSelectionManager,~A");\r
22 Clazz.makeConstructor (c$, \r
23 function (ssm, pdbentry, sequenceIs, chains, protocol) {\r
24 Clazz.superConstructor (this, jalview.structures.models.AAStructureBindingModel, []);\r
25 this.ssm = ssm;\r
26 this.sequence = sequenceIs;\r
27 this.nucleotide = jalview.util.Comparison.isNucleotide2 (sequenceIs);\r
28 this.chains = chains;\r
29 this.pdbEntry = pdbentry;\r
30 this.protocol = protocol;\r
31 if (chains == null) {\r
32 this.chains =  new Array (pdbentry.length);\r
33 }}, "jalview.structure.StructureSelectionManager,~A,~A,~A,~S");\r
34 Clazz.defineMethod (c$, "getSsm", \r
35 function () {\r
36 return this.ssm;\r
37 });\r
38 Clazz.defineMethod (c$, "getPdbEntry", \r
39 function (i) {\r
40 return (this.pdbEntry != null && this.pdbEntry.length > i) ? this.pdbEntry[i] : null;\r
41 }, "~N");\r
42 Clazz.defineMethod (c$, "hasPdbId", \r
43 function (pdbId) {\r
44 if (this.pdbEntry != null) {\r
45 for (var pdb, $pdb = 0, $$pdb = this.pdbEntry; $pdb < $$pdb.length && ((pdb = $$pdb[$pdb]) || true); $pdb++) {\r
46 if (pdb.getId ().equals (pdbId)) {\r
47 return true;\r
48 }}\r
49 }return false;\r
50 }, "~S");\r
51 Clazz.defineMethod (c$, "getPdbCount", \r
52 function () {\r
53 return this.pdbEntry == null ? 0 : this.pdbEntry.length;\r
54 });\r
55 Clazz.defineMethod (c$, "getSequence", \r
56 function () {\r
57 return this.sequence;\r
58 });\r
59 Clazz.defineMethod (c$, "getChains", \r
60 function () {\r
61 return this.chains;\r
62 });\r
63 Clazz.defineMethod (c$, "getProtocol", \r
64 function () {\r
65 return this.protocol;\r
66 });\r
67 Clazz.defineMethod (c$, "setPdbentry", \r
68 function (pdbentry) {\r
69 this.pdbEntry = pdbentry;\r
70 }, "~A");\r
71 Clazz.defineMethod (c$, "setSequence", \r
72 function (sequence) {\r
73 this.sequence = sequence;\r
74 }, "~A");\r
75 Clazz.defineMethod (c$, "setChains", \r
76 function (chains) {\r
77 this.chains = chains;\r
78 }, "~A");\r
79 Clazz.defineMethod (c$, "getViewerTitle", \r
80 function (viewerName, verbose) {\r
81 if (this.getSequence () == null || this.getSequence ().length < 1 || this.getPdbCount () < 1 || this.getSequence ()[0].length < 1) {\r
82 return ("Jalview " + viewerName + " Window");\r
83 }var title =  new StringBuilder (64);\r
84 var pdbEntry = this.getPdbEntry (0);\r
85 title.append (viewerName + " view for " + this.getSequence ()[0][0].getName () + ":" + pdbEntry.getId ());\r
86 if (verbose) {\r
87 if (pdbEntry.getProperty () != null) {\r
88 if (pdbEntry.getProperty ().get ("method") != null) {\r
89 title.append (" Method: ");\r
90 title.append (pdbEntry.getProperty ().get ("method"));\r
91 }if (pdbEntry.getProperty ().get ("chains") != null) {\r
92 title.append (" Chain:");\r
93 title.append (pdbEntry.getProperty ().get ("chains"));\r
94 }}}return title.toString ();\r
95 }, "~S,~B");\r
96 Clazz.defineMethod (c$, "releaseUIResources", \r
97 function () {\r
98 });\r
99 Clazz.defineMethod (c$, "isColourBySequence", \r
100 function () {\r
101 return this.colourBySequence;\r
102 });\r
103 Clazz.defineMethod (c$, "setColourBySequence", \r
104 function (colourBySequence) {\r
105 this.colourBySequence = colourBySequence;\r
106 }, "~B");\r
107 Clazz.defineMethod (c$, "addSequenceAndChain", \r
108 function (pe, seq, tchain) {\r
109 if (pe < 0 || pe >= this.getPdbCount ()) {\r
110 throw  new Error (jalview.util.MessageManager.formatMessage ("error.implementation_error_no_pdbentry_from_index",  Clazz.newArray (-1, [Integer.$valueOf (pe).toString ()])));\r
111 }var nullChain = "TheNullChain";\r
112 var s =  new java.util.ArrayList ();\r
113 var c =  new java.util.ArrayList ();\r
114 if (this.getChains () == null) {\r
115 this.setChains ( new Array (this.getPdbCount ()));\r
116 }if (this.getSequence ()[pe] != null) {\r
117 for (var i = 0; i < this.getSequence ()[pe].length; i++) {\r
118 s.add (this.getSequence ()[pe][i]);\r
119 if (this.getChains ()[pe] != null) {\r
120 if (i < this.getChains ()[pe].length) {\r
121 c.add (this.getChains ()[pe][i]);\r
122 } else {\r
123 c.add ("TheNullChain");\r
124 }} else {\r
125 if (tchain != null && tchain.length > 0) {\r
126 c.add ("TheNullChain");\r
127 }}}\r
128 }for (var i = 0; i < seq.length; i++) {\r
129 if (!s.contains (seq[i])) {\r
130 s.add (seq[i]);\r
131 if (tchain != null && i < tchain.length) {\r
132 c.add (tchain[i] == null ? "TheNullChain" : tchain[i]);\r
133 }}}\r
134 var tmp = s.toArray ( new Array (s.size ()));\r
135 this.getSequence ()[pe] = tmp;\r
136 if (c.size () > 0) {\r
137 var tch = c.toArray ( new Array (c.size ()));\r
138 for (var i = 0; i < tch.length; i++) {\r
139 if (tch[i] === "TheNullChain") {\r
140 tch[i] = null;\r
141 }}\r
142 this.getChains ()[pe] = tch;\r
143 } else {\r
144 this.getChains ()[pe] = null;\r
145 }}, "~N,~A,~A");\r
146 Clazz.defineMethod (c$, "addSequenceAndChain", \r
147 function (pdbe, seq, chns) {\r
148 var v =  new java.util.ArrayList ();\r
149 var rtn =  new java.util.ArrayList ();\r
150 for (var i = 0; i < this.getPdbCount (); i++) {\r
151 v.add (this.getPdbEntry (i));\r
152 }\r
153 for (var i = 0; i < pdbe.length; i++) {\r
154 var r = v.indexOf (pdbe[i]);\r
155 if (r == -1 || r >= this.getPdbCount ()) {\r
156 rtn.add ( Clazz.newIntArray (-1, [v.size (), i]));\r
157 v.add (pdbe[i]);\r
158 } else {\r
159 this.addSequenceAndChain (r, seq[i], chns[i]);\r
160 }}\r
161 pdbe = v.toArray ( new Array (v.size ()));\r
162 this.setPdbentry (pdbe);\r
163 if (rtn.size () > 0) {\r
164 var sqs =  new Array (this.getPdbCount ());\r
165 var sch =  new Array (this.getPdbCount ());\r
166 System.arraycopy (this.getSequence (), 0, sqs, 0, this.getSequence ().length);\r
167 System.arraycopy (this.getChains (), 0, sch, 0, this.getChains ().length);\r
168 this.setSequence (sqs);\r
169 this.setChains (sch);\r
170 pdbe =  new Array (rtn.size ());\r
171 for (var r = 0; r < pdbe.length; r++) {\r
172 var stri = (rtn.get (r));\r
173 pdbe[r] = this.getPdbEntry (stri[0]);\r
174 this.addSequenceAndChain (stri[0], seq[stri[1]], chns[stri[1]]);\r
175 }\r
176 } else {\r
177 pdbe = null;\r
178 }return pdbe;\r
179 }, "~A,~A,~A");\r
180 Clazz.defineMethod (c$, "addSequence", \r
181 function (pe, seq) {\r
182 this.addSequenceAndChain (pe, seq, null);\r
183 }, "~N,~A");\r
184 Clazz.defineMethod (c$, "addSequenceForStructFile", \r
185 function (pdbFile, seq) {\r
186 for (var pe = 0; pe < this.getPdbCount (); pe++) {\r
187 if (this.getPdbEntry (pe).getFile ().equals (pdbFile)) {\r
188 this.addSequence (pe, seq);\r
189 }}\r
190 }, "~S,~A");\r
191 Clazz.defineMethod (c$, "isNucleotide", \r
192 function () {\r
193 return this.nucleotide;\r
194 });\r
195 Clazz.defineMethod (c$, "printMappings", \r
196 function () {\r
197 if (this.pdbEntry == null) {\r
198 return "";\r
199 }var sb =  new StringBuilder (128);\r
200 for (var pdbe = 0; pdbe < this.getPdbCount (); pdbe++) {\r
201 var pdbfile = this.getPdbEntry (pdbe).getFile ();\r
202 var seqs = java.util.Arrays.asList (this.getSequence ()[pdbe]);\r
203 sb.append (this.getSsm ().printMappings (pdbfile, seqs));\r
204 }\r
205 return sb.toString ();\r
206 });\r
207 Clazz.defineMethod (c$, "getMappedPosition", \r
208 function (seq, alignedPos, mapping) {\r
209 if (alignedPos >= seq.getLength ()) {\r
210 return -1;\r
211 }if (jalview.util.Comparison.isGap (seq.getCharAt (alignedPos))) {\r
212 return -1;\r
213 }var seqPos = seq.findPosition (alignedPos);\r
214 var pos = mapping.getPDBResNum (seqPos);\r
215 return pos;\r
216 }, "jalview.datamodel.SequenceI,~N,jalview.structure.StructureMapping");\r
217 Clazz.defineMethod (c$, "findSuperposableResidues", \r
218 function (alignment, matched, structures) {\r
219 var refStructure = -1;\r
220 var files = this.getPdbFile ();\r
221 for (var pdbfnum = 0; pdbfnum < files.length; pdbfnum++) {\r
222 var mappings = this.getSsm ().getMapping (files[pdbfnum]);\r
223 var lastPos = -1;\r
224 var seqCountForPdbFile = this.getSequence ()[pdbfnum].length;\r
225 for (var s = 0; s < seqCountForPdbFile; s++) {\r
226 for (var mapping, $mapping = 0, $$mapping = mappings; $mapping < $$mapping.length && ((mapping = $$mapping[$mapping]) || true); $mapping++) {\r
227 var theSequence = this.getSequence ()[pdbfnum][s];\r
228 if (mapping.getSequence () === theSequence && alignment.findIndex (theSequence) > -1) {\r
229 if (refStructure < 0) {\r
230 refStructure = pdbfnum;\r
231 }for (var r = 0; r < matched.length; r++) {\r
232 if (!matched[r]) {\r
233 continue;\r
234 }var pos = this.getMappedPosition (theSequence, r, mapping);\r
235 if (pos < 1 || pos == lastPos) {\r
236 matched[r] = false;\r
237 continue;\r
238 }lastPos = pos;\r
239 structures[pdbfnum].pdbResNo[r] = pos;\r
240 }\r
241 var chain = mapping.getChain ();\r
242 if (chain != null && chain.trim ().length > 0) {\r
243 structures[pdbfnum].chain = chain;\r
244 }structures[pdbfnum].pdbId = mapping.getPdbId ();\r
245 structures[pdbfnum].isRna = theSequence.getRNA () != null;\r
246 s = seqCountForPdbFile;\r
247 break;\r
248 }}\r
249 }\r
250 }\r
251 return refStructure;\r
252 }, "jalview.datamodel.AlignmentI,~A,~A");\r
253 Clazz.defineMethod (c$, "waitForFileLoad", \r
254 function (files) {\r
255 var starttime = System.currentTimeMillis ();\r
256 var endTime = 10000 + 1000 * files.length + starttime;\r
257 var notLoaded = null;\r
258 var waiting = true;\r
259 while (waiting && System.currentTimeMillis () < endTime) {\r
260 waiting = false;\r
261 for (var file, $file = 0, $$file = files; $file < $$file.length && ((file = $$file[$file]) || true); $file++) {\r
262 notLoaded = file;\r
263 try {\r
264 var sm = this.getSsm ().getMapping (file);\r
265 if (sm == null || sm.length == 0) {\r
266 waiting = true;\r
267 }} catch (x) {\r
268 waiting = true;\r
269 }\r
270 }\r
271 }\r
272 if (waiting) {\r
273 System.err.println ("Timed out waiting for structure viewer to load file " + notLoaded);\r
274 return false;\r
275 }return true;\r
276 }, "~A");\r
277 Clazz.overrideMethod (c$, "isListeningFor", \r
278 function (seq) {\r
279 if (this.sequence != null) {\r
280 for (var seqs, $seqs = 0, $$seqs = this.sequence; $seqs < $$seqs.length && ((seqs = $$seqs[$seqs]) || true); $seqs++) {\r
281 if (seqs != null) {\r
282 for (var s, $s = 0, $$s = seqs; $s < $$s.length && ((s = $$s[$s]) || true); $s++) {\r
283 if (s === seq) {\r
284 return true;\r
285 }}\r
286 }}\r
287 }return false;\r
288 }, "jalview.datamodel.SequenceI");\r
289 c$.$AAStructureBindingModel$SuperposeData$ = function () {\r
290 Clazz.pu$h(self.c$);\r
291 c$ = Clazz.decorateAsClass (function () {\r
292 Clazz.prepareCallback (this, arguments);\r
293 this.filename = null;\r
294 this.pdbId = null;\r
295 this.chain = "";\r
296 this.isRna = false;\r
297 this.pdbResNo = null;\r
298 Clazz.instantialize (this, arguments);\r
299 }, jalview.structures.models.AAStructureBindingModel, "SuperposeData");\r
300 Clazz.makeConstructor (c$, \r
301 function (a) {\r
302 this.pdbResNo =  Clazz.newIntArray (a, 0);\r
303 }, "~N");\r
304 c$ = Clazz.p0p ();\r
305 };\r
306 });\r