JAL-1807 includes ?j2sdebug flag and DebugJS._(msg)
[jalviewjs.git] / bin / jalview / appletgui / PairwiseAlignPanel.js
1 Clazz.declarePackage ("jalview.appletgui");
2 Clazz.load (["awt2swing.Panel", "java.awt.event.ActionListener", "awt2swing.Button", "$.ScrollPane", "$.TextArea", "java.awt.BorderLayout", "java.util.Vector"], "jalview.appletgui.PairwiseAlignPanel", ["jalview.analysis.AlignSeq", "jalview.appletgui.AlignFrame", "jalview.datamodel.Alignment", "jalview.util.Format", "$.MessageManager", "java.awt.Font"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.sequences = null;
5 this.ap = null;
6 this.scrollPane = null;
7 this.textarea = null;
8 this.viewInEditorButton = null;
9 this.jPanel1 = null;
10 this.borderLayout1 = null;
11 Clazz.instantialize (this, arguments);
12 }, jalview.appletgui, "PairwiseAlignPanel", awt2swing.Panel, java.awt.event.ActionListener);
13 Clazz.prepareFields (c$, function () {
14 this.sequences =  new java.util.Vector ();
15 this.scrollPane =  new awt2swing.ScrollPane ();
16 this.textarea =  new awt2swing.TextArea ();
17 this.viewInEditorButton =  new awt2swing.Button ();
18 this.jPanel1 =  new awt2swing.Panel ();
19 this.borderLayout1 =  new java.awt.BorderLayout ();
20 });
21 Clazz.makeConstructor (c$, 
22 function (ap) {
23 Clazz.superConstructor (this, jalview.appletgui.PairwiseAlignPanel, []);
24 try {
25 this.jbInit ();
26 } catch (e) {
27 if (Clazz.exceptionOf (e, Exception)) {
28 e.printStackTrace ();
29 } else {
30 throw e;
31 }
32 }
33 this.ap = ap;
34 this.sequences =  new java.util.Vector ();
35 var seqs;
36 var seqStrings = ap.av.getViewAsString (true);
37 if (ap.av.getSelectionGroup () == null) {
38 seqs = ap.av.getAlignment ().getSequencesArray ();
39 } else {
40 seqs = ap.av.getSelectionGroup ().getSequencesInOrder (ap.av.getAlignment ());
41 }var scores =  Clazz.newFloatArray (seqs.length, seqs.length, 0);
42 var totscore = 0;
43 var count = ap.av.getSelectionGroup ().getSize ();
44 var type = (ap.av.getAlignment ().isNucleotide ()) ? "dna" : "pep";
45 var seq;
46 for (var i = 1; i < count; i++) {
47 for (var j = 0; j < i; j++) {
48 var as =  new jalview.analysis.AlignSeq (seqs[i], seqStrings[i], seqs[j], seqStrings[j], type);
49 if (as.s1str.length == 0 || as.s2str.length == 0) {
50 continue;
51 }as.calcScoreMatrix ();
52 as.traceAlignment ();
53 as.printAlignment (System.out);
54 scores[i][j] = as.getMaxScore () / as.getASeq1 ().length;
55 totscore = totscore + scores[i][j];
56 this.textarea.append (as.getOutput ());
57 this.sequences.add (as.getAlignedSeq1 ());
58 this.sequences.add (as.getAlignedSeq1 ());
59 }
60 }
61 if (count > 2) {
62 System.out.println ("Pairwise alignment scaled similarity score matrix\n");
63 for (var i = 0; i < count; i++) {
64 jalview.util.Format.print (System.out, "%s \n", ("" + i) + " " + seqs[i].getName ());
65 }
66 System.out.println ("\n");
67 for (var i = 0; i < count; i++) {
68 for (var j = 0; j < i; j++) {
69 jalview.util.Format.printDouble (System.out, "%7.3f", scores[i][j] / totscore);
70 }
71 }
72 System.out.println ("\n");
73 }}, "jalview.appletgui.AlignmentPanel");
74 Clazz.overrideMethod (c$, "actionPerformed", 
75 function (evt) {
76 if (evt.getSource () === this.viewInEditorButton) {
77 this.viewInEditorButton_actionPerformed ();
78 }}, "java.awt.event.ActionEvent");
79 Clazz.defineMethod (c$, "viewInEditorButton_actionPerformed", 
80 function () {
81 var seq =  new Array (this.sequences.size ());
82 for (var i = 0; i < this.sequences.size (); i++) {
83 seq[i] = this.sequences.elementAt (i);
84 }
85  new jalview.appletgui.AlignFrame ( new jalview.datamodel.Alignment (seq), this.ap.av.applet, "Pairwise Aligned Sequences", false);
86 });
87 Clazz.defineMethod (c$, "jbInit", 
88 ($fz = function () {
89 this.setLayout (this.borderLayout1);
90 this.textarea.setFont ( new java.awt.Font ("Monospaced", 0, 12));
91 this.textarea.setText ("");
92 this.viewInEditorButton.setFont ( new java.awt.Font ("Verdana", 0, 12));
93 this.viewInEditorButton.setLabel (jalview.util.MessageManager.getString ("label.view_alignment_editor"));
94 this.viewInEditorButton.addActionListener (this);
95 this.add (this.scrollPane, "Center");
96 this.scrollPane.add (this.textarea);
97 this.add (this.jPanel1, "South");
98 this.jPanel1.add (this.viewInEditorButton, null);
99 }, $fz.isPrivate = true, $fz));
100 });