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
41 public PCAPanel(AlignViewport av)
\r
44 if (av.getSelectionGroup()!=null && av.getSelectionGroup().getSize() > 3)
\r
46 seqs = new Sequence[av.getSelectionGroup().getSize()];
\r
47 for (int i = 0; i < av.getSelectionGroup().getSize(); i++)
\r
49 seqs[i] = av.getSelectionGroup().getSequenceAt(i);
\r
54 seqs = new Sequence[av.getAlignment().getHeight()];
\r
55 for (int i = 0; i < av.getAlignment().getHeight(); i++)
\r
57 seqs[i] = av.getAlignment().getSequenceAt(i);
\r
61 rc = new RotatableCanvas(av);
\r
62 add(rc, BorderLayout.CENTER);
\r
64 jalview.bin.JalviewLite.addFrame(this, "Principal component analysis",
\r
68 Thread worker = new Thread(this);
\r
77 pca = new PCA(seqs);
\r
80 // Now find the component coordinates
\r
83 while ((ii < seqs.length) && (seqs[ii] != null))
\r
88 double[][] comps = new double[ii][ii];
\r
90 for (int i = 0; i < ii; i++)
\r
92 if (pca.getEigenvalue(i) > 1e-4)
\r
94 comps[i] = pca.component(i);
\r
99 xCombobox.select(0);
\r
100 yCombobox.select(1);
\r
101 zCombobox.select(2);
\r
103 top = pca.getM().rows - 1;
\r
105 Vector points = new Vector();
\r
106 float[][] scores = pca.getComponents(top - 1, top - 2, top - 3, 100);
\r
108 for (int i = 0; i < pca.getM().rows; i++)
\r
110 SequencePoint sp = new SequencePoint(seqs[i], scores[i]);
\r
111 points.addElement(sp);
\r
114 rc.setPoints(points, pca.getM().rows);
\r
120 void doDimensionChange()
\r
127 int dim1 = top - xCombobox.getSelectedIndex();
\r
128 int dim2 = top - yCombobox.getSelectedIndex();
\r
129 int dim3 = top - zCombobox.getSelectedIndex();
\r
131 float[][] scores = pca.getComponents(dim1, dim2, dim3, 100);
\r
132 for (int i = 0; i < pca.getM().rows; i++)
\r
134 ( (SequencePoint) rc.points.elementAt(i)).coord = scores[i];
\r
138 rc.rotmat.setIdentity();
\r
140 rc.paint(rc.getGraphics());
\r
143 protected void xCombobox_actionPerformed(ActionEvent e)
\r
145 doDimensionChange();
\r
148 protected void yCombobox_actionPerformed(ActionEvent e)
\r
150 doDimensionChange();
\r
153 protected void zCombobox_actionPerformed(ActionEvent e)
\r
155 doDimensionChange();
\r
158 public void values_actionPerformed(ActionEvent actionEvent)
\r
161 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, null);
\r
162 Frame frame = new Frame();
\r
164 jalview.bin.JalviewLite.addFrame(frame, "PCA details", 500, 500);
\r
166 cap.setText(pca.getDetails());
\r
169 public void labels_itemStateChanged(ItemEvent itemEvent)
\r
171 rc.showLabels( labels.getState() );
\r