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