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
31 import javax.swing.JOptionPane;
\r
32 import javax.swing.JInternalFrame;
\r
39 * @version $Revision$
\r
41 public class PCAPanel extends GPCAPanel implements Runnable
\r
50 * Creates a new PCAPanel object.
\r
52 * @param av DOCUMENT ME!
\r
53 * @param s DOCUMENT ME!
\r
55 public PCAPanel(AlignViewport av)
\r
59 boolean sameLength = true;
\r
61 if ((av.getSelectionGroup() != null) &&
\r
62 (av.getSelectionGroup().getSize() > 3))
\r
64 seqs = new Sequence[av.getSelectionGroup().getSize()];
\r
65 int length = av.getSelectionGroup().getSequenceAt(0).getLength();
\r
66 for (int i = 0; i < av.getSelectionGroup().getSize(); i++)
\r
68 seqs[i] = av.getSelectionGroup().getSequenceAt(i);
\r
69 if(seqs[i].getLength()!=length)
\r
78 seqs = new Sequence[av.getAlignment().getHeight()];
\r
79 int length = av.alignment.getSequenceAt(0).getLength();
\r
81 for (int i = 0; i < av.getAlignment().getHeight(); i++)
\r
83 seqs[i] = av.getAlignment().getSequenceAt(i);
\r
84 if(seqs[i].getLength()!=length)
\r
95 JOptionPane.showMessageDialog(Desktop.desktop,
\r
96 "The sequences must be aligned before calculating PCA.\n" +
\r
97 "Try using the Pad function in the edit menu,\n" +
\r
98 "or one of the multiple sequence alignment web services.",
\r
99 "Sequences not aligned",
\r
100 JOptionPane.WARNING_MESSAGE);
\r
105 JInternalFrame frame = new JInternalFrame();
\r
106 frame.setContentPane(this);
\r
107 Desktop.addInternalFrame(frame, "Principal component analysis",
\r
111 rc = new RotatableCanvas(av);
\r
112 add(rc, BorderLayout.CENTER);
\r
113 Thread worker = new Thread(this);
\r
125 pca = new PCA(seqs);
\r
128 // Now find the component coordinates
\r
131 while ( (ii < seqs.length) && (seqs[ii] != null))
\r
136 double[][] comps = new double[ii][ii];
\r
138 for (int i = 0; i < ii; i++)
\r
140 if (pca.getEigenvalue(i) > 1e-4)
\r
142 comps[i] = pca.component(i);
\r
147 xCombobox.setSelectedIndex(0);
\r
148 yCombobox.setSelectedIndex(1);
\r
149 zCombobox.setSelectedIndex(2);
\r
151 top = pca.getM().rows - 1;
\r
153 Vector points = new Vector();
\r
154 float[][] scores = pca.getComponents(top - 1, top - 2, top - 3, 100);
\r
156 for (int i = 0; i < pca.getM().rows; i++)
\r
158 SequencePoint sp = new SequencePoint(seqs[i], scores[i]);
\r
159 points.addElement(sp);
\r
162 rc.setPoints(points, pca.getM().rows);
\r
166 catch(OutOfMemoryError er)
\r
167 { JOptionPane.showInternalMessageDialog(Desktop.desktop,
\r
168 "Out of memory calculating PCA!!"
\r
170 "\nSee help files for increasing Java Virtual Machine memory."
\r
172 JOptionPane.WARNING_MESSAGE);
\r
173 System.out.println("PCAPanel: "+er);
\r
183 void doDimensionChange()
\r
190 int dim1 = top - xCombobox.getSelectedIndex();
\r
191 int dim2 = top - yCombobox.getSelectedIndex();
\r
192 int dim3 = top - zCombobox.getSelectedIndex();
\r
194 float[][] scores = pca.getComponents(dim1, dim2, dim3, 100);
\r
196 for (int i = 0; i < pca.getM().rows; i++)
\r
198 ((SequencePoint) rc.points.elementAt(i)).coord = scores[i];
\r
202 rc.rotmat.setIdentity();
\r
204 rc.paint(rc.getGraphics());
\r
210 * @param e DOCUMENT ME!
\r
212 protected void xCombobox_actionPerformed(ActionEvent e)
\r
214 doDimensionChange();
\r
220 * @param e DOCUMENT ME!
\r
222 protected void yCombobox_actionPerformed(ActionEvent e)
\r
224 doDimensionChange();
\r
230 * @param e DOCUMENT ME!
\r
232 protected void zCombobox_actionPerformed(ActionEvent e)
\r
234 doDimensionChange();
\r