1 Clazz.declarePackage ("jalview.appletgui");
2 Clazz.load (["jalview.appletgui.EmbmenuFrame", "java.awt.event.ActionListener", "$.ItemListener", "awt2swing.Button", "$.CheckboxMenuItem", "$.Choice", "$.Label", "$.Menu", "$.MenuBar", "$.MenuItem", "$.Panel", "java.awt.BorderLayout", "$.FlowLayout"], "jalview.appletgui.PCAPanel", ["awt2swing.Frame", "jalview.appletgui.AlignFrame", "$.CutAndPasteTransfer", "$.RotatableCanvas", "jalview.bin.JalviewLite", "jalview.datamodel.Alignment", "jalview.util.MessageManager", "jalview.viewmodel.PCAModel", "java.awt.Color", "$.Font", "java.lang.Thread"], function () {
3 c$ = Clazz.decorateAsClass (function () {
12 this.xCombobox = null;
13 this.yCombobox = null;
14 this.zCombobox = null;
15 this.resetButton = null;
16 this.flowLayout1 = null;
17 this.borderLayout1 = null;
21 this.calcSettings = null;
23 this.protSetting = null;
24 this.nuclSetting = null;
26 this.inputData = null;
27 Clazz.instantialize (this, arguments);
28 }, jalview.appletgui, "PCAPanel", jalview.appletgui.EmbmenuFrame, [Runnable, java.awt.event.ActionListener, java.awt.event.ItemListener]);
29 Clazz.prepareFields (c$, function () {
30 this.jPanel2 = new awt2swing.Panel ();
31 this.jLabel1 = new awt2swing.Label ();
32 this.jLabel2 = new awt2swing.Label ();
33 this.jLabel3 = new awt2swing.Label ();
34 this.xCombobox = new awt2swing.Choice ();
35 this.yCombobox = new awt2swing.Choice ();
36 this.zCombobox = new awt2swing.Choice ();
37 this.resetButton = new awt2swing.Button ();
38 this.flowLayout1 = new java.awt.FlowLayout ();
39 this.borderLayout1 = new java.awt.BorderLayout ();
40 this.menuBar1 = new awt2swing.MenuBar ();
41 this.menu1 = new awt2swing.Menu ();
42 this.menu2 = new awt2swing.Menu ();
43 this.calcSettings = new awt2swing.Menu ();
44 this.labels = new awt2swing.CheckboxMenuItem ();
45 this.protSetting = new awt2swing.CheckboxMenuItem ();
46 this.nuclSetting = new awt2swing.CheckboxMenuItem ();
47 this.values = new awt2swing.MenuItem ();
48 this.inputData = new awt2swing.MenuItem ();
50 Clazz.makeConstructor (c$,
52 Clazz.superConstructor (this, jalview.appletgui.PCAPanel, []);
56 if (Clazz.exceptionOf (e, Exception)) {
62 for (var i = 1; i < 8; i++) {
63 this.xCombobox.addItem ("dim " + i);
64 this.yCombobox.addItem ("dim " + i);
65 this.zCombobox.addItem ("dim " + i);
68 var selected = av.getSelectionGroup () != null && av.getSelectionGroup ().getSize () > 0;
69 var seqstrings = av.getAlignmentView (selected);
70 var nucleotide = av.getAlignment ().isNucleotide ();
73 seqs = av.getAlignment ().getSequencesArray ();
75 seqs = av.getSelectionGroup ().getSequencesInOrder (av.getAlignment ());
76 }var sq = seqstrings.getSequences ();
77 var length = sq[0].getWidth ();
78 for (var i = 0; i < seqs.length; i++) {
79 if (sq[i].getWidth () != length) {
80 System.out.println ("Sequences must be equal length for PCA analysis");
83 this.pcaModel = new jalview.viewmodel.PCAModel (seqstrings, seqs, nucleotide);
84 this.rc = new jalview.appletgui.RotatableCanvas (av);
85 this.embedMenuIfNeeded (this.rc);
86 this.add (this.rc, "Center");
87 jalview.bin.JalviewLite.addFrame (this, jalview.util.MessageManager.getString ("label.principal_component_analysis"), 475, 400);
88 var worker = new Thread (this);
90 }, "jalview.appletgui.AlignViewport");
91 Clazz.overrideMethod (c$, "run",
93 this.calcSettings.setEnabled (false);
94 this.rc.setEnabled (false);
96 this.nuclSetting.setState (this.pcaModel.isNucleotide ());
97 this.protSetting.setState (!this.pcaModel.isNucleotide ());
99 this.xCombobox.select (new Integer (0));
100 this.yCombobox.select (new Integer (1));
101 this.zCombobox.select (new Integer (2));
102 this.pcaModel.updateRc (this.rc);
103 this.top = this.pcaModel.getTop ();
105 if (Clazz.exceptionOf (x, OutOfMemoryError)) {
106 System.err.println ("Out of memory when calculating PCA.");
112 this.calcSettings.setEnabled (true);
113 this.rc.setEnabled (true);
117 Clazz.defineMethod (c$, "doDimensionChange",
121 }var dim1 = this.top - this.xCombobox.getSelectedIndex ();
122 var dim2 = this.top - this.yCombobox.getSelectedIndex ();
123 var dim3 = this.top - this.zCombobox.getSelectedIndex ();
124 this.pcaModel.updateRcView (dim1, dim2, dim3);
126 this.rc.rotmat.setIdentity ();
128 this.rc.paint (this.rc.getGraphics ());
130 Clazz.overrideMethod (c$, "actionPerformed",
132 if (evt.getSource () === this.inputData) {
133 this.showOriginalData ();
134 }if (evt.getSource () === this.resetButton) {
135 this.xCombobox.select (new Integer (0));
136 this.yCombobox.select (new Integer (1));
137 this.zCombobox.select (new Integer (2));
138 this.doDimensionChange ();
139 }if (evt.getSource () === this.values) {
140 this.values_actionPerformed ();
141 }}, "java.awt.event.ActionEvent");
142 Clazz.overrideMethod (c$, "itemStateChanged",
144 if (evt.getSource () === this.xCombobox) {
145 this.xCombobox_actionPerformed ();
146 } else if (evt.getSource () === this.yCombobox) {
147 this.yCombobox_actionPerformed ();
148 } else if (evt.getSource () === this.zCombobox) {
149 this.zCombobox_actionPerformed ();
150 } else if (evt.getSource () === this.labels) {
151 this.labels_itemStateChanged (evt);
152 } else if (evt.getSource () === this.nuclSetting) {
153 if (!this.pcaModel.isNucleotide ()) {
154 this.pcaModel.setNucleotide (true);
155 new Thread (this).start ();
156 }} else if (evt.getSource () === this.protSetting) {
157 if (this.pcaModel.isNucleotide ()) {
158 this.pcaModel.setNucleotide (false);
159 new Thread (this).start ();
160 }}}, "java.awt.event.ItemEvent");
161 Clazz.defineMethod (c$, "xCombobox_actionPerformed",
163 this.doDimensionChange ();
165 Clazz.defineMethod (c$, "yCombobox_actionPerformed",
167 this.doDimensionChange ();
169 Clazz.defineMethod (c$, "zCombobox_actionPerformed",
171 this.doDimensionChange ();
173 Clazz.defineMethod (c$, "values_actionPerformed",
175 var cap = new jalview.appletgui.CutAndPasteTransfer (false, null);
176 var frame = new awt2swing.Frame ();
178 jalview.bin.JalviewLite.addFrame (frame, jalview.util.MessageManager.getString ("label.pca_details"), 500, 500);
179 cap.setText (this.pcaModel.getDetails ());
181 Clazz.defineMethod (c$, "showOriginalData",
185 gc = this.av.getGapCharacter ();
187 if (Clazz.exceptionOf (ex, Exception)) {
192 ;var alAndColsel = this.pcaModel.getSeqtrings ().getAlignmentAndColumnSelection (gc);
193 if (alAndColsel != null && alAndColsel[0] != null) {
194 var al = new jalview.datamodel.Alignment (alAndColsel[0]);
195 var af = new jalview.appletgui.AlignFrame (al, this.av.applet, "Original Data for PCA", false);
196 af.viewport.setHiddenColumns (alAndColsel[1]);
198 Clazz.defineMethod (c$, "labels_itemStateChanged",
199 function (itemEvent) {
200 this.rc.showLabels (this.labels.getState ());
201 }, "java.awt.event.ItemEvent");
202 Clazz.defineMethod (c$, "jbInit",
204 this.setLayout (this.borderLayout1);
205 this.jPanel2.setLayout (this.flowLayout1);
206 this.jLabel1.setFont ( new java.awt.Font ("Verdana", 0, 12));
207 this.jLabel1.setText ("x=");
208 this.jLabel2.setFont ( new java.awt.Font ("Verdana", 0, 12));
209 this.jLabel2.setText ("y=");
210 this.jLabel3.setFont ( new java.awt.Font ("Verdana", 0, 12));
211 this.jLabel3.setText ("z=");
212 this.jPanel2.setBackground (java.awt.Color.white);
213 this.zCombobox.setFont ( new java.awt.Font ("Verdana", 0, 12));
214 this.zCombobox.addItemListener (this);
215 this.yCombobox.setFont ( new java.awt.Font ("Verdana", 0, 12));
216 this.yCombobox.addItemListener (this);
217 this.xCombobox.setFont ( new java.awt.Font ("Verdana", 0, 12));
218 this.xCombobox.addItemListener (this);
219 this.resetButton.setFont ( new java.awt.Font ("Verdana", 0, 12));
220 this.resetButton.setLabel (jalview.util.MessageManager.getString ("action.reset"));
221 this.resetButton.addActionListener (this);
222 this.setMenuBar (this.menuBar1);
223 this.menu1.setLabel (jalview.util.MessageManager.getString ("action.file"));
224 this.menu2.setLabel (jalview.util.MessageManager.getString ("action.view"));
225 this.calcSettings.setLabel (jalview.util.MessageManager.getString ("action.change_params"));
226 this.labels.setLabel (jalview.util.MessageManager.getString ("label.labels"));
227 this.labels.addItemListener (this);
228 this.values.setLabel (jalview.util.MessageManager.getString ("label.output_values"));
229 this.values.addActionListener (this);
230 this.inputData.setLabel (jalview.util.MessageManager.getString ("label.input_data"));
231 this.nuclSetting.setLabel (jalview.util.MessageManager.getString ("label.nucleotide_matrix"));
232 this.nuclSetting.addItemListener (this);
233 this.protSetting.setLabel (jalview.util.MessageManager.getString ("label.protein_matrix"));
234 this.protSetting.addItemListener (this);
235 this.add (this.jPanel2, "South");
236 this.jPanel2.add (this.jLabel1, null);
237 this.jPanel2.add (this.xCombobox, null);
238 this.jPanel2.add (this.jLabel2, null);
239 this.jPanel2.add (this.yCombobox, null);
240 this.jPanel2.add (this.jLabel3, null);
241 this.jPanel2.add (this.zCombobox, null);
242 this.jPanel2.add (this.resetButton, null);
243 this.menuBar1.add (this.menu1);
244 this.menuBar1.add (this.menu2);
245 this.menuBar1.add (this.calcSettings);
246 this.menu2.add (this.labels);
247 this.menu1.add (this.values);
248 this.menu1.add (this.inputData);
249 this.calcSettings.add (this.nuclSetting);
250 this.calcSettings.add (this.protSetting);
251 this.inputData.addActionListener (this);
252 }, $fz.isPrivate = true, $fz));