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
24 import java.awt.event.*;
\r
26 import jalview.analysis.*;
\r
27 import jalview.datamodel.*;
\r
28 import jalview.jbgui.*;
\r
30 public class PCAPanel
\r
31 extends GPCAPanel implements Runnable
\r
38 public PCAPanel(AlignViewport av, SequenceI[] s)
\r
42 if ( (av.getSelectionGroup() != null) &&
\r
43 (av.getSelectionGroup().getSize() > 3))
\r
45 s = new Sequence[av.getSelectionGroup().getSize()];
\r
47 for (int i = 0; i < s.length; i++)
\r
49 s[i] = av.getSelectionGroup().getSequenceAt(i);
\r
55 s = new Sequence[av.getAlignment().getHeight()];
\r
57 for (int i = 0; i < av.getAlignment().getHeight(); i++)
\r
59 s[i] = av.getAlignment().getSequenceAt(i);
\r
63 //////////////////////This part was done in PCATHread originally. Is it too slow???
\r
67 // Now find the component coordinates
\r
70 while ( (ii < s.length) && (s[ii] != null))
\r
75 double[][] comps = new double[ii][ii];
\r
77 for (int i = 0; i < ii; i++)
\r
79 if (pca.getEigenvalue(i) > 1e-4)
\r
81 comps[i] = pca.component(i);
\r
86 xCombobox.setSelectedIndex(0);
\r
87 yCombobox.setSelectedIndex(1);
\r
88 zCombobox.setSelectedIndex(2);
\r
90 top = pca.getM().rows - 1;
\r
92 Vector points = new Vector();
\r
93 float[][] scores = pca.getComponents(top - 1, top - 2, top - 3, 100);
\r
95 for (int i = 0; i < pca.getM().rows; i++)
\r
97 SequencePoint sp = new SequencePoint(s[i], scores[i]);
\r
98 points.addElement(sp);
\r
101 rc = new RotatableCanvas(av, points, pca.getM().rows);
\r
103 //rc.printPoints();
\r
104 add(rc, BorderLayout.CENTER);
\r
112 void doDimensionChange()
\r
119 int dim1 = top - xCombobox.getSelectedIndex();
\r
120 int dim2 = top - yCombobox.getSelectedIndex();
\r
121 int dim3 = top - zCombobox.getSelectedIndex();
\r
123 float[][] scores = pca.getComponents(dim1, dim2, dim3, 100);
\r
125 for (int i = 0; i < pca.getM().rows; i++)
\r
127 ( (SequencePoint) rc.points.elementAt(i)).coord = scores[i];
\r
131 rc.rotmat.setIdentity();
\r
133 rc.paint(rc.getGraphics());
\r
136 protected void xCombobox_actionPerformed(ActionEvent e)
\r
138 doDimensionChange();
\r
141 protected void yCombobox_actionPerformed(ActionEvent e)
\r
143 doDimensionChange();
\r
146 protected void zCombobox_actionPerformed(ActionEvent e)
\r
148 doDimensionChange();
\r