1 Clazz.declarePackage ("jalview.structure");
2 Clazz.load (["java.util.ArrayList", "$.HashMap", "$.LinkedHashSet", "$.Vector"], "jalview.structure.StructureSelectionManager", ["MCview.PDBfile", "jalview.analysis.AlignSeq", "jalview.commands.EditCommand", "$.OrderCommand", "jalview.datamodel.Mapping", "$.SearchResults", "jalview.io.AppletFormatAdapter", "jalview.structure.AtomSpec", "$.SecondaryStructureListener", "$.SequenceListener", "$.StructureListener", "$.StructureMapping", "$.VamsasListener", "jalview.util.MappingUtils", "$.MessageManager", "java.lang.Error", "$.NullPointerException", "$.StringBuilder", "java.util.Arrays", "$.Collections", "$.IdentityHashMap"], function () {
3 c$ = Clazz.decorateAsClass (function () {
5 this.processSecondaryStructure = false;
6 this.secStructServices = false;
7 this.addTempFacAnnot = false;
8 this.seqmappings = null;
9 this.seqMappingRefCounts = null;
10 this.commandListeners = null;
11 this.sel_listeners = null;
12 this.pdbIdFileName = null;
13 this.pdbFileNameId = null;
14 this.relaySeqMappings = true;
15 this.listeners = null;
16 this.handlingVamsasMo = false;
18 this.view_listeners = null;
19 Clazz.instantialize (this, arguments);
20 }, jalview.structure, "StructureSelectionManager");
21 Clazz.prepareFields (c$, function () {
22 this.mappings = new java.util.ArrayList ();
23 this.seqmappings = new java.util.LinkedHashSet ();
24 this.seqMappingRefCounts = new java.util.HashMap ();
25 this.commandListeners = new java.util.ArrayList ();
26 this.sel_listeners = new java.util.ArrayList ();
27 this.pdbIdFileName = new java.util.HashMap ();
28 this.pdbFileNameId = new java.util.HashMap ();
29 this.listeners = new java.util.Vector ();
30 this.view_listeners = new java.util.Vector ();
32 Clazz.defineMethod (c$, "isSecStructServices",
34 return this.secStructServices;
36 Clazz.defineMethod (c$, "setSecStructServices",
37 function (secStructServices) {
38 this.secStructServices = secStructServices;
40 Clazz.defineMethod (c$, "isAddTempFacAnnot",
42 return this.addTempFacAnnot;
44 Clazz.defineMethod (c$, "setAddTempFacAnnot",
45 function (addTempFacAnnot) {
46 this.addTempFacAnnot = addTempFacAnnot;
48 Clazz.defineMethod (c$, "isProcessSecondaryStructure",
50 return this.processSecondaryStructure;
52 Clazz.defineMethod (c$, "setProcessSecondaryStructure",
54 this.processSecondaryStructure = enable;
56 Clazz.defineMethod (c$, "reportMapping",
58 if (this.mappings.isEmpty ()) {
59 System.err.println ("reportMapping: No PDB/Sequence mappings.");
61 System.err.println ("reportMapping: There are " + this.mappings.size () + " mappings.");
63 for (var sm, $sm = this.mappings.iterator (); $sm.hasNext () && ((sm = $sm.next ()) || true);) {
64 System.err.println ("mapping " + i++ + " : " + sm.pdbfile);
67 Clazz.defineMethod (c$, "registerPDBFile",
68 function (idForFile, absoluteFile) {
69 this.pdbIdFileName.put (idForFile, absoluteFile);
70 this.pdbFileNameId.put (absoluteFile, idForFile);
72 Clazz.defineMethod (c$, "findIdForPDBFile",
74 var id = this.pdbFileNameId.get (idOrFile);
77 Clazz.defineMethod (c$, "findFileForPDBId",
79 var id = this.pdbIdFileName.get (idOrFile);
82 Clazz.defineMethod (c$, "isPDBFileRegistered",
84 return this.pdbFileNameId.containsKey (idOrFile) || this.pdbIdFileName.containsKey (idOrFile);
86 c$.getStructureSelectionManager = Clazz.defineMethod (c$, "getStructureSelectionManager",
88 if (context == null) {
89 if (jalview.structure.StructureSelectionManager.nullProvider == null) {
90 if (jalview.structure.StructureSelectionManager.instances != null) {
91 throw new Error (jalview.util.MessageManager.getString ("error.implementation_error_structure_selection_manager_null"), new NullPointerException (jalview.util.MessageManager.getString ("exception.ssm_context_is_null")));
93 jalview.structure.StructureSelectionManager.nullProvider = new jalview.structure.StructureSelectionManager ();
94 }return jalview.structure.StructureSelectionManager.nullProvider;
95 }}if (jalview.structure.StructureSelectionManager.instances == null) {
96 jalview.structure.StructureSelectionManager.instances = new java.util.IdentityHashMap ();
97 }var instance = jalview.structure.StructureSelectionManager.instances.get (context);
98 if (instance == null) {
99 if (jalview.structure.StructureSelectionManager.nullProvider != null) {
100 instance = jalview.structure.StructureSelectionManager.nullProvider;
102 instance = new jalview.structure.StructureSelectionManager ();
103 }jalview.structure.StructureSelectionManager.instances.put (context, instance);
105 }, "jalview.api.StructureSelectionManagerProvider");
106 Clazz.defineMethod (c$, "setRelaySeqMappings",
108 this.relaySeqMappings = relay;
110 Clazz.defineMethod (c$, "isRelaySeqMappingsEnabled",
112 return this.relaySeqMappings;
114 Clazz.defineMethod (c$, "addStructureViewerListener",
116 if (!this.listeners.contains (svl)) {
117 this.listeners.addElement (svl);
119 Clazz.defineMethod (c$, "alreadyMappedToFile",
121 for (var sm, $sm = this.mappings.iterator (); $sm.hasNext () && ((sm = $sm.next ()) || true);) {
122 if (sm.getPdbId ().equals (pdbid)) {
127 Clazz.defineMethod (c$, "setMapping",
128 function (sequence, targetChains, pdbFile, protocol) {
129 return this.setMapping (true, sequence, targetChains, pdbFile, protocol);
131 Clazz.defineMethod (c$, "setMapping",
132 function (forStructureView, sequence, targetChains, pdbFile, protocol) {
133 var parseSecStr = this.processSecondaryStructure;
134 if (this.isPDBFileRegistered (pdbFile)) {
135 for (var sq, $sq = 0, $$sq = sequence; $sq < $$sq.length && ((sq = $$sq[$sq]) || true); $sq++) {
137 while (ds.getDatasetSequence () != null) {
138 ds = ds.getDatasetSequence ();
140 ;if (ds.getAnnotation () != null) {
141 for (var ala, $ala = 0, $$ala = ds.getAnnotation (); $ala < $$ala.length && ((ala = $$ala[$ala]) || true); $ala++) {
142 if (MCview.PDBfile.isCalcIdForFile (ala, this.findIdForPDBFile (pdbFile))) {
148 pdb = new MCview.PDBfile (this.addTempFacAnnot, parseSecStr, this.secStructServices, pdbFile, protocol);
149 if (pdb.id != null && pdb.id.trim ().length > 0 && jalview.io.AppletFormatAdapter.FILE.equals (protocol)) {
150 this.registerPDBFile (pdb.id.trim (), pdbFile);
152 if (Clazz.exceptionOf (ex, Exception)) {
153 ex.printStackTrace ();
160 for (var s = 0; s < sequence.length; s++) {
162 var seq = sequence[s];
163 if (targetChains != null && targetChains[s] != null) {
165 targetChain = targetChains[s];
166 } else if (seq.getName ().indexOf ("|") > -1) {
167 targetChain = seq.getName ().substring (seq.getName ().lastIndexOf ("|") + 1);
168 if (targetChain.length > 1) {
169 if (targetChain.trim ().length == 0) {
176 var maxAlignseq = null;
177 var maxChainId = " ";
180 for (var chain, $chain = pdb.chains.iterator (); $chain.hasNext () && ((chain = $chain.next ()) || true);) {
181 if (targetChain.length > 0 && !targetChain.equals (chain.id) && !infChain) {
183 }var type = chain.isNa ? "dna" : "pep";
184 var as = jalview.analysis.AlignSeq.doGlobalNWAlignment (seq, chain.sequence, type);
185 if (first || as.maxscore > max || (as.maxscore == max && chain.id.equals (targetChain))) {
190 maxChainId = chain.id;
192 if (maxChain == null) {
194 }var mappingDetails = new StringBuilder (128);
195 mappingDetails.append (jalview.structure.StructureSelectionManager.NEWLINE).append ("PDB Sequence is :").append (jalview.structure.StructureSelectionManager.NEWLINE).append ("Sequence = ").append (maxChain.sequence.getSequenceAsString ());
196 mappingDetails.append (jalview.structure.StructureSelectionManager.NEWLINE).append ("No of residues = ").append (maxChain.residues.size ()).append (jalview.structure.StructureSelectionManager.NEWLINE).append (jalview.structure.StructureSelectionManager.NEWLINE);
197 var ps = ((Clazz.isClassDefined ("jalview.structure.StructureSelectionManager$1") ? 0 : jalview.structure.StructureSelectionManager.$StructureSelectionManager$1$ ()), Clazz.innerTypeInstance (jalview.structure.StructureSelectionManager$1, this, Clazz.cloneFinals ("mappingDetails", mappingDetails), System.out));
198 maxAlignseq.printAlignment (ps);
199 mappingDetails.append (jalview.structure.StructureSelectionManager.NEWLINE).append ("PDB start/end ");
200 mappingDetails.append (String.valueOf (maxAlignseq.seq2start)).append (" ");
201 mappingDetails.append (String.valueOf (maxAlignseq.seq2end));
202 mappingDetails.append (jalview.structure.StructureSelectionManager.NEWLINE).append ("SEQ start/end ");
203 mappingDetails.append (String.valueOf (maxAlignseq.seq1start + seq.getStart () - 1)).append (" ");
204 mappingDetails.append (String.valueOf (maxAlignseq.seq1end + seq.getEnd () - 1));
205 maxChain.makeExactMapping (maxAlignseq, seq);
206 var sqmpping = maxAlignseq.getMappingFromS1 (false);
207 var omap = new jalview.datamodel.Mapping (sqmpping.getMap ().getInverse ());
208 maxChain.transferRESNUMFeatures (seq, null);
209 var mapping = Clazz.newIntArray (seq.findPosition (seq.getLength ()) + 2, 2, 0);
213 var tmp = maxChain.atoms.elementAt (index);
214 if (resNum != tmp.resNumber && tmp.alignmentMapping != -1) {
215 resNum = tmp.resNumber;
216 mapping[tmp.alignmentMapping + 1][0] = tmp.resNumber;
217 mapping[tmp.alignmentMapping + 1][1] = tmp.atomIndex;
219 } while (index < maxChain.atoms.size ());
220 if (protocol.equals (jalview.io.AppletFormatAdapter.PASTE)) {
221 pdbFile = "INLINE" + pdb.id;
222 }var newMapping = new jalview.structure.StructureMapping (seq, pdbFile, pdb.id, maxChainId, mapping, mappingDetails.toString ());
223 if (forStructureView) {
224 this.mappings.add (newMapping);
225 }maxChain.transferResidueAnnotation (newMapping, sqmpping);
228 }, "~B,~A,~A,~S,~S");
229 Clazz.defineMethod (c$, "removeStructureViewerListener",
230 function (svl, pdbfiles) {
231 this.listeners.removeElement (svl);
232 if (Clazz.instanceOf (svl, jalview.structure.SequenceListener)) {
233 for (var i = 0; i < this.listeners.size (); i++) {
234 if (Clazz.instanceOf (this.listeners.elementAt (i), jalview.structure.StructureListener)) {
235 (this.listeners.elementAt (i)).releaseReferences (svl);
237 }if (pdbfiles == null) {
239 }var pdbs = new java.util.ArrayList (java.util.Arrays.asList (pdbfiles));
241 for (var i = 0; i < this.listeners.size (); i++) {
242 if (Clazz.instanceOf (this.listeners.elementAt (i), jalview.structure.StructureListener)) {
243 sl = this.listeners.elementAt (i);
244 for (var pdbfile, $pdbfile = 0, $$pdbfile = sl.getPdbFile (); $pdbfile < $$pdbfile.length && ((pdbfile = $$pdbfile[$pdbfile]) || true); $pdbfile++) {
245 pdbs.remove (pdbfile);
248 if (pdbs.size () > 0) {
249 var tmp = new java.util.ArrayList ();
250 for (var sm, $sm = this.mappings.iterator (); $sm.hasNext () && ((sm = $sm.next ()) || true);) {
251 if (!pdbs.contains (sm.pdbfile)) {
256 Clazz.defineMethod (c$, "mouseOverStructure",
257 function (pdbResNum, chain, pdbfile) {
258 var atomSpec = new jalview.structure.AtomSpec (pdbfile, chain, pdbResNum, 0);
259 var atoms = java.util.Collections.singletonList (atomSpec);
260 this.mouseOverStructure (atoms);
262 Clazz.defineMethod (c$, "mouseOverStructure",
264 if (this.listeners == null) {
266 }var hasSequenceListener = false;
267 for (var i = 0; i < this.listeners.size (); i++) {
268 if (Clazz.instanceOf (this.listeners.elementAt (i), jalview.structure.SequenceListener)) {
269 hasSequenceListener = true;
271 if (!hasSequenceListener) {
273 }var results = new jalview.datamodel.SearchResults ();
274 for (var atom, $atom = atoms.iterator (); $atom.hasNext () && ((atom = $atom.next ()) || true);) {
277 for (var sm, $sm = this.mappings.iterator (); $sm.hasNext () && ((sm = $sm.next ()) || true);) {
278 if (sm.pdbfile.equals (atom.getPdbFile ()) && sm.pdbchain.equals (atom.getChain ())) {
279 var indexpos = sm.getSeqPos (atom.getPdbResNum ());
280 if (lastipos != indexpos && lastseq !== sm.sequence) {
281 results.addResult (sm.sequence, indexpos, indexpos);
283 lastseq = sm.sequence;
284 for (var acf, $acf = this.seqmappings.iterator (); $acf.hasNext () && ((acf = $acf.next ()) || true);) {
285 acf.markMappedRegion (sm.sequence, indexpos, results);
289 for (var li, $li = this.listeners.iterator (); $li.hasNext () && ((li = $li.next ()) || true);) {
290 if (Clazz.instanceOf (li, jalview.structure.SequenceListener)) {
291 (li).highlightSequence (results);
293 }, "java.util.List");
294 Clazz.defineMethod (c$, "mouseOverSequence",
295 function (seq, indexpos, index, source) {
296 var hasSequenceListeners = this.handlingVamsasMo || !this.seqmappings.isEmpty ();
299 index = seq.findPosition (indexpos);
300 }for (var i = 0; i < this.listeners.size (); i++) {
301 var listener = this.listeners.elementAt (i);
302 if (listener === source) {
304 }if (Clazz.instanceOf (listener, jalview.structure.StructureListener)) {
305 this.highlightStructure (listener, seq, index);
307 if (Clazz.instanceOf (listener, jalview.structure.SequenceListener)) {
308 var seqListener = listener;
309 if (hasSequenceListeners && seqListener.getVamsasSource () !== source) {
310 if (this.relaySeqMappings) {
311 if (results == null) {
312 results = jalview.util.MappingUtils.buildSearchResults (seq, index, this.seqmappings);
313 }if (this.handlingVamsasMo) {
314 results.addResult (seq, index, index);
315 }seqListener.highlightSequence (results);
316 }}} else if (Clazz.instanceOf (listener, jalview.structure.VamsasListener) && !this.handlingVamsasMo) {
317 (listener).mouseOverSequence (seq, indexpos, source);
318 } else if (Clazz.instanceOf (listener, jalview.structure.SecondaryStructureListener)) {
319 (listener).mouseOverSequence (seq, indexpos, index);
321 }, "jalview.datamodel.SequenceI,~N,~N,jalview.structure.VamsasSource");
322 Clazz.defineMethod (c$, "highlightStructure",
323 function (sl, seq, index) {
324 if (!sl.isListeningFor (seq)) {
327 var atoms = new java.util.ArrayList ();
328 for (var sm, $sm = this.mappings.iterator (); $sm.hasNext () && ((sm = $sm.next ()) || true);) {
329 if (sm.sequence === seq || sm.sequence === seq.getDatasetSequence ()) {
330 atomNo = sm.getAtomNum (index);
332 atoms.add ( new jalview.structure.AtomSpec (sm.pdbfile, sm.pdbchain, sm.getPDBResNum (index), atomNo));
334 sl.highlightAtoms (atoms);
335 }, "jalview.structure.StructureListener,jalview.datamodel.SequenceI,~N");
336 Clazz.defineMethod (c$, "mouseOverVamsasSequence",
337 function (sequenceI, position, source) {
338 this.handlingVamsasMo = true;
339 var msg = sequenceI.hashCode () * (1 + position);
340 if (this.lastmsg != msg) {
342 this.mouseOverSequence (sequenceI, position, -1, source);
343 }this.handlingVamsasMo = false;
344 }, "jalview.datamodel.SequenceI,~N,jalview.structure.VamsasSource");
345 Clazz.defineMethod (c$, "colourSequenceFromStructure",
346 function (seq, pdbid) {
348 }, "jalview.datamodel.SequenceI,~S");
349 Clazz.defineMethod (c$, "structureSelectionChanged",
352 Clazz.defineMethod (c$, "sequenceSelectionChanged",
355 Clazz.defineMethod (c$, "sequenceColoursChanged",
358 for (var i = 0; i < this.listeners.size (); i++) {
359 if (Clazz.instanceOf (this.listeners.elementAt (i), jalview.structure.StructureListener)) {
360 sl = this.listeners.elementAt (i);
361 sl.updateColours (source);
364 Clazz.defineMethod (c$, "getMapping",
366 var tmp = new java.util.ArrayList ();
367 for (var sm, $sm = this.mappings.iterator (); $sm.hasNext () && ((sm = $sm.next ()) || true);) {
368 if (sm.pdbfile.equals (pdbfile)) {
371 return tmp.toArray ( new Array (tmp.size ()));
373 Clazz.defineMethod (c$, "printMappings",
374 function (pdbfile, seqs) {
375 if (pdbfile == null || seqs == null || seqs.isEmpty ()) {
377 }var sb = new StringBuilder (64);
378 for (var sm, $sm = this.mappings.iterator (); $sm.hasNext () && ((sm = $sm.next ()) || true);) {
379 if (sm.pdbfile.equals (pdbfile) && seqs.contains (sm.sequence)) {
380 sb.append (sm.mappingDetails);
381 sb.append (jalview.structure.StructureSelectionManager.NEWLINE);
382 sb.append ("=====================");
383 sb.append (jalview.structure.StructureSelectionManager.NEWLINE);
385 sb.append (jalview.structure.StructureSelectionManager.NEWLINE);
386 return sb.toString ();
387 }, "~S,java.util.List");
388 Clazz.defineMethod (c$, "removeMappings",
391 for (var acf, $acf = set.iterator (); $acf.hasNext () && ((acf = $acf.next ()) || true);) {
392 this.removeMapping (acf);
394 }}, "java.util.Set");
395 Clazz.defineMethod (c$, "removeMapping",
397 if (acf != null && this.seqmappings.contains (acf)) {
398 var count = (this.seqMappingRefCounts.get (acf)).intValue ();
401 this.seqMappingRefCounts.put (acf, new Integer (count));
403 this.seqmappings.remove (acf);
404 this.seqMappingRefCounts.remove (acf);
405 }}}, "jalview.datamodel.AlignedCodonFrame");
406 Clazz.defineMethod (c$, "addMappings",
409 for (var acf, $acf = set.iterator (); $acf.hasNext () && ((acf = $acf.next ()) || true);) {
410 this.addMapping (acf);
412 }}, "java.util.Set");
413 Clazz.defineMethod (c$, "addMapping",
416 if (this.seqmappings.contains (acf)) {
417 this.seqMappingRefCounts.put (acf, new Integer ((this.seqMappingRefCounts.get (acf)).intValue () + 1));
419 this.seqmappings.add (acf);
420 this.seqMappingRefCounts.put (acf, new Integer (1));
421 }}}, "jalview.datamodel.AlignedCodonFrame");
422 Clazz.defineMethod (c$, "addSelectionListener",
423 function (selecter) {
424 if (!this.sel_listeners.contains (selecter)) {
425 this.sel_listeners.add (selecter);
426 }}, "jalview.structure.SelectionListener");
427 Clazz.defineMethod (c$, "removeSelectionListener",
428 function (toremove) {
429 if (this.sel_listeners.contains (toremove)) {
430 this.sel_listeners.remove (toremove);
431 }}, "jalview.structure.SelectionListener");
432 Clazz.defineMethod (c$, "sendSelection",
433 function (selection, colsel, source) {
434 for (var slis, $slis = this.sel_listeners.iterator (); $slis.hasNext () && ((slis = $slis.next ()) || true);) {
435 if (slis !== source) {
436 slis.selection (selection, colsel, source);
438 }, "jalview.datamodel.SequenceGroup,jalview.datamodel.ColumnSelection,jalview.structure.SelectionSource");
439 Clazz.defineMethod (c$, "sendViewPosition",
440 function (source, startRes, endRes, startSeq, endSeq) {
441 if (this.view_listeners != null && this.view_listeners.size () > 0) {
442 var listeners = this.view_listeners.elements ();
443 while (listeners.hasMoreElements ()) {
444 var slis = listeners.nextElement ();
445 if (slis !== source) {
446 slis.viewPosition (startRes, endRes, startSeq, endSeq, source);
448 }}, "jalview.api.AlignmentViewPanel,~N,~N,~N,~N");
449 c$.release = Clazz.defineMethod (c$, "release",
450 function (jalviewLite) {
452 if (jalview.structure.StructureSelectionManager.instances == null) {
454 }var mnger = (jalview.structure.StructureSelectionManager.instances.get (jalviewLite));
456 jalview.structure.StructureSelectionManager.instances.remove (jalviewLite);
461 }}}, "jalview.api.StructureSelectionManagerProvider");
462 Clazz.defineMethod (c$, "registerPDBEntry",
463 function (pdbentry) {
464 if (pdbentry.getFile () != null && pdbentry.getFile ().trim ().length > 0) {
465 this.registerPDBFile (pdbentry.getId (), pdbentry.getFile ());
466 }}, "jalview.datamodel.PDBEntry");
467 Clazz.defineMethod (c$, "addCommandListener",
469 if (!this.commandListeners.contains (cl)) {
470 this.commandListeners.add (cl);
471 }}, "jalview.structure.CommandListener");
472 Clazz.defineMethod (c$, "hasCommandListener",
474 return this.commandListeners.contains (cl);
475 }, "jalview.structure.CommandListener");
476 Clazz.defineMethod (c$, "removeCommandListener",
478 return this.commandListeners.remove (l);
479 }, "jalview.structure.CommandListener");
480 Clazz.defineMethod (c$, "commandPerformed",
481 function (command, undo, source) {
482 for (var listener, $listener = this.commandListeners.iterator (); $listener.hasNext () && ((listener = $listener.next ()) || true);) {
483 listener.mirrorCommand (command, undo, this, source);
485 }, "jalview.commands.CommandI,~B,jalview.structure.VamsasSource");
486 Clazz.defineMethod (c$, "mapCommand",
487 function (command, undo, mapTo, gapChar) {
488 if (Clazz.instanceOf (command, jalview.commands.EditCommand)) {
489 return jalview.util.MappingUtils.mapEditCommand (command, undo, mapTo, gapChar, this.seqmappings);
490 } else if (Clazz.instanceOf (command, jalview.commands.OrderCommand)) {
491 return jalview.util.MappingUtils.mapOrderCommand (command, undo, mapTo, this.seqmappings);
493 }, "jalview.commands.CommandI,~B,jalview.datamodel.AlignmentI,~S");
494 c$.$StructureSelectionManager$1$ = function () {
496 c$ = Clazz.declareAnonymous (jalview.structure, "StructureSelectionManager$1", java.io.PrintStream);
497 Clazz.defineMethod (c$, "print",
499 this.f$.mappingDetails.append (x);
501 Clazz.defineMethod (c$, "println",
503 this.f$.mappingDetails.append (jalview.structure.StructureSelectionManager.NEWLINE);
507 c$.NEWLINE = c$.prototype.NEWLINE = System.lineSeparator ();
508 Clazz.defineStatics (c$,
510 "nullProvider", null);