2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
20 package jalview.appletgui;
\r
25 import java.awt.event.*;
\r
27 import jalview.analysis.*;
\r
28 import jalview.datamodel.*;
\r
29 import jalview.jbappletgui.*;
\r
31 public class PCAPanel
\r
32 extends GPCAPanel implements Runnable
\r
44 public PCAPanel(AlignViewport av, SequenceI[] s)
\r
48 if (av.getSelectionGroup().getSize() > 3)
\r
50 s = new Sequence[av.getSelectionGroup().getSize()];
\r
51 for (int i = 0; i < s.length; i++)
\r
53 s[i] = av.getSelectionGroup().getSequenceAt(i);
\r
59 s = new Sequence[av.getAlignment().getHeight()];
\r
60 for (int i = 0; i < av.getAlignment().getHeight(); i++)
\r
62 s[i] = av.getAlignment().getSequenceAt(i);
\r
66 //////////////////////This part was done in PCATHread originally. Is it too slow???
\r
70 // Now find the component coordinates
\r
72 while (ii < s.length && s[ii] != null)
\r
77 double[][] comps = new double[ii][ii];
\r
79 for (int i = 0; i < ii; i++)
\r
81 if (pca.getEigenvalue(i) > 1e-4)
\r
83 comps[i] = pca.component(i);
\r
89 xCombobox.select(0);
\r
90 yCombobox.select(1);
\r
91 zCombobox.select(2);
\r
93 top = pca.getM().rows - 1;
\r
95 Vector points = new Vector();
\r
96 float[][] scores = pca.getComponents(top - 1, top - 2, top - 3, 100);
\r
98 for (int i = 0; i < pca.getM().rows; i++)
\r
100 SequencePoint sp = new SequencePoint(s[i], scores[i]);
\r
101 points.addElement(sp);
\r
104 rc = new RotatableCanvas(av, points, pca.getM().rows);
\r
106 //rc.printPoints();
\r
108 add(rc, BorderLayout.CENTER);
\r
111 void doDimensionChange()
\r
118 int dim1 = top - xCombobox.getSelectedIndex();
\r
119 int dim2 = top - yCombobox.getSelectedIndex();
\r
120 int dim3 = top - zCombobox.getSelectedIndex();
\r
122 float[][] scores = pca.getComponents(dim1, dim2, dim3, 100);
\r
123 for (int i = 0; i < pca.getM().rows; i++)
\r
125 ( (SequencePoint) rc.points.elementAt(i)).coord = scores[i];
\r
129 rc.rotmat.setIdentity();
\r
131 rc.paint(rc.getGraphics());
\r
134 protected void xCombobox_actionPerformed(ActionEvent e)
\r
136 doDimensionChange();
\r
139 protected void yCombobox_actionPerformed(ActionEvent e)
\r
141 doDimensionChange();
\r
144 protected void zCombobox_actionPerformed(ActionEvent e)
\r
146 doDimensionChange();
\r