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
19 package jalview.gui;
\r
21 import jalview.analysis.*;
\r
23 import jalview.datamodel.*;
\r
25 import jalview.jbgui.*;
\r
28 import java.awt.event.*;
\r
37 * @version $Revision$
\r
39 public class PCAPanel extends GPCAPanel implements Runnable
\r
47 * Creates a new PCAPanel object.
\r
49 * @param av DOCUMENT ME!
\r
50 * @param s DOCUMENT ME!
\r
52 public PCAPanel(AlignViewport av, SequenceI[] s)
\r
56 if ((av.getSelectionGroup() != null) &&
\r
57 (av.getSelectionGroup().getSize() > 3))
\r
59 s = new Sequence[av.getSelectionGroup().getSize()];
\r
61 for (int i = 0; i < s.length; i++)
\r
63 s[i] = av.getSelectionGroup().getSequenceAt(i);
\r
69 s = new Sequence[av.getAlignment().getHeight()];
\r
71 for (int i = 0; i < av.getAlignment().getHeight(); i++)
\r
73 s[i] = av.getAlignment().getSequenceAt(i);
\r
77 //////////////////////This part was done in PCATHread originally. Is it too slow???
\r
81 // Now find the component coordinates
\r
84 while ((ii < s.length) && (s[ii] != null))
\r
89 double[][] comps = new double[ii][ii];
\r
91 for (int i = 0; i < ii; i++)
\r
93 if (pca.getEigenvalue(i) > 1e-4)
\r
95 comps[i] = pca.component(i);
\r
100 xCombobox.setSelectedIndex(0);
\r
101 yCombobox.setSelectedIndex(1);
\r
102 zCombobox.setSelectedIndex(2);
\r
104 top = pca.getM().rows - 1;
\r
106 Vector points = new Vector();
\r
107 float[][] scores = pca.getComponents(top - 1, top - 2, top - 3, 100);
\r
109 for (int i = 0; i < pca.getM().rows; i++)
\r
111 SequencePoint sp = new SequencePoint(s[i], scores[i]);
\r
112 points.addElement(sp);
\r
115 rc = new RotatableCanvas(av, points, pca.getM().rows);
\r
117 //rc.printPoints();
\r
118 add(rc, BorderLayout.CENTER);
\r
132 void doDimensionChange()
\r
139 int dim1 = top - xCombobox.getSelectedIndex();
\r
140 int dim2 = top - yCombobox.getSelectedIndex();
\r
141 int dim3 = top - zCombobox.getSelectedIndex();
\r
143 float[][] scores = pca.getComponents(dim1, dim2, dim3, 100);
\r
145 for (int i = 0; i < pca.getM().rows; i++)
\r
147 ((SequencePoint) rc.points.elementAt(i)).coord = scores[i];
\r
151 rc.rotmat.setIdentity();
\r
153 rc.paint(rc.getGraphics());
\r
159 * @param e DOCUMENT ME!
\r
161 protected void xCombobox_actionPerformed(ActionEvent e)
\r
163 doDimensionChange();
\r
169 * @param e DOCUMENT ME!
\r
171 protected void yCombobox_actionPerformed(ActionEvent e)
\r
173 doDimensionChange();
\r
179 * @param e DOCUMENT ME!
\r
181 protected void zCombobox_actionPerformed(ActionEvent e)
\r
183 doDimensionChange();
\r