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
22 import jalview.datamodel.*;
\r
23 import jalview.analysis.PCA;
\r
24 import jalview.jbappletgui.*;
\r
26 import java.awt.event.*;
\r
30 public class PCAPanel extends GPCAPanel implements Runnable
\r
42 public PCAPanel(AlignViewport av, SequenceI[] s) {
\r
45 if(av.getSelectionGroup().getSize()>3)
\r
47 s = new Sequence[av.getSelectionGroup().getSize()];
\r
48 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
56 for (int i = 0; i < av.getAlignment().getHeight(); i++)
\r
57 s[i] = av.getAlignment().getSequenceAt(i);
\r
60 //////////////////////This part was done in PCATHread originally. Is it too slow???
\r
64 // Now find the component coordinates
\r
66 while (ii < s.length && s[ii] != null)
\r
71 double[][] comps = new double[ii][ii];
\r
73 for (int i=0; i < ii; i++ )
\r
75 if (pca.getEigenvalue(i) > 1e-4)
\r
77 comps[i] = pca.component(i);
\r
83 xCombobox.select(0);
\r
84 yCombobox.select(1);
\r
85 zCombobox.select(2);
\r
87 top = pca.getM().rows-1;
\r
89 Vector points = new Vector();
\r
90 float[][] scores = pca.getComponents(top-1,top-2,top-3,100);
\r
92 for (int i =0; i < pca.getM().rows; i++ )
\r
94 SequencePoint sp = new SequencePoint(s[i],scores[i]);
\r
95 points.addElement(sp);
\r
98 rc = new RotatableCanvas(av,points,pca.getM().rows);
\r
100 //rc.printPoints();
\r
102 add(rc, BorderLayout.CENTER);
\r
106 void doDimensionChange()
\r
111 int dim1 = top - xCombobox.getSelectedIndex();
\r
112 int dim2 = top - yCombobox.getSelectedIndex();
\r
113 int dim3 = top - zCombobox.getSelectedIndex();
\r
115 float[][] scores = pca.getComponents(dim1,dim2,dim3,100);
\r
116 for (int i=0; i < pca.getM().rows; i++) {
\r
117 ((SequencePoint)rc.points.elementAt(i)).coord = scores[i];
\r
121 rc.rotmat.setIdentity();
\r
123 rc.paint(rc.getGraphics());
\r
126 protected void xCombobox_actionPerformed(ActionEvent e)
\r
128 doDimensionChange();
\r
131 protected void yCombobox_actionPerformed(ActionEvent e)
\r
133 doDimensionChange();
\r
136 protected void zCombobox_actionPerformed(ActionEvent e)
\r
138 doDimensionChange();
\r