/* * Jalview - A Sequence Alignment Editor and Viewer * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ package jalview.appletgui; import java.util.*; import java.awt.*; import java.awt.event.*; import jalview.analysis.*; import jalview.datamodel.*; import jalview.jbappletgui.*; public class PCAPanel extends GPCAPanel implements Runnable { PCA pca; int top; RotatableCanvas rc; AlignViewport av; SequenceI [] seqs; public PCAPanel(AlignViewport av) { this.av = av; if (av.getSelectionGroup()!=null && av.getSelectionGroup().getSize() > 3) { seqs = new Sequence[av.getSelectionGroup().getSize()]; for (int i = 0; i < av.getSelectionGroup().getSize(); i++) { seqs[i] = av.getSelectionGroup().getSequenceAt(i); } } else { seqs = new Sequence[av.getAlignment().getHeight()]; for (int i = 0; i < av.getAlignment().getHeight(); i++) { seqs[i] = av.getAlignment().getSequenceAt(i); } } rc = new RotatableCanvas(av); add(rc, BorderLayout.CENTER); Thread worker = new Thread(this); worker.start(); } /** * DOCUMENT ME! */ public void run() { pca = new PCA(seqs); pca.run(); // Now find the component coordinates int ii = 0; while ((ii < seqs.length) && (seqs[ii] != null)) { ii++; } double[][] comps = new double[ii][ii]; for (int i = 0; i < ii; i++) { if (pca.getEigenvalue(i) > 1e-4) { comps[i] = pca.component(i); } } ////////////////// xCombobox.select(0); yCombobox.select(1); zCombobox.select(2); top = pca.getM().rows - 1; Vector points = new Vector(); float[][] scores = pca.getComponents(top - 1, top - 2, top - 3, 100); for (int i = 0; i < pca.getM().rows; i++) { SequencePoint sp = new SequencePoint(seqs[i], scores[i]); points.addElement(sp); } rc.setPoints(points, pca.getM().rows); rc.repaint(); seqs = null; } void doDimensionChange() { if (top == 0) { return; } int dim1 = top - xCombobox.getSelectedIndex(); int dim2 = top - yCombobox.getSelectedIndex(); int dim3 = top - zCombobox.getSelectedIndex(); float[][] scores = pca.getComponents(dim1, dim2, dim3, 100); for (int i = 0; i < pca.getM().rows; i++) { ( (SequencePoint) rc.points.elementAt(i)).coord = scores[i]; } rc.img = null; rc.rotmat.setIdentity(); rc.initAxes(); rc.paint(rc.getGraphics()); } protected void xCombobox_actionPerformed(ActionEvent e) { doDimensionChange(); } protected void yCombobox_actionPerformed(ActionEvent e) { doDimensionChange(); } protected void zCombobox_actionPerformed(ActionEvent e) { doDimensionChange(); } }