X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FPCAPanel.java;h=7bda65a597613aeac4e41f4ab5ae531b6f4bb862;hb=beaa65409fc4cf865392c4e6e57116b64af37dfc;hp=8f3ff73b400231b7781748f7eaebed0de5aa92bd;hpb=99c58ee0ae2a848f982552e53feaf6d5cb9925e5;p=jalview.git diff --git a/src/jalview/gui/PCAPanel.java b/src/jalview/gui/PCAPanel.java index 8f3ff73..7bda65a 100755 --- a/src/jalview/gui/PCAPanel.java +++ b/src/jalview/gui/PCAPanel.java @@ -1,141 +1,185 @@ /* -* 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 -*/ - + * 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.gui; +import jalview.analysis.*; + import jalview.datamodel.*; -import jalview.analysis.PCA; + import jalview.jbgui.*; + import java.awt.*; import java.awt.event.*; + import java.util.*; +/** + * DOCUMENT ME! + * + * @author $author$ + * @version $Revision$ + */ public class PCAPanel extends GPCAPanel implements Runnable { - PCA pca; - int top; - RotatableCanvas rc; - AlignViewport av; - - public void run() - { - // do stuff - } - - public PCAPanel(AlignViewport av, SequenceI[] s) { - - this.av = av; - if(av.getSelectionGroup()!=null && av.getSelectionGroup().getSize()>3) + PCA pca; + int top; + RotatableCanvas rc; + AlignViewport av; + + /** + * Creates a new PCAPanel object. + * + * @param av DOCUMENT ME! + * @param s DOCUMENT ME! + */ + public PCAPanel(AlignViewport av, SequenceI[] s) { - s = new Sequence[av.getSelectionGroup().getSize()]; - for(int i=0; i 3)) + { + s = new Sequence[av.getSelectionGroup().getSize()]; + + for (int i = 0; i < s.length; i++) + { + s[i] = av.getSelectionGroup().getSequenceAt(i); + } + } + + if (s == null) + { + s = new Sequence[av.getAlignment().getHeight()]; + + for (int i = 0; i < av.getAlignment().getHeight(); i++) + { + s[i] = av.getAlignment().getSequenceAt(i); + } + } + + //////////////////////This part was done in PCATHread originally. Is it too slow??? + pca = new PCA(s); + pca.run(); + + // Now find the component coordinates + int ii = 0; + + while ((ii < s.length) && (s[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.setSelectedIndex(0); + yCombobox.setSelectedIndex(1); + zCombobox.setSelectedIndex(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(s[i], scores[i]); + points.addElement(sp); + } + + rc = new RotatableCanvas(av, points, pca.getM().rows); + + //rc.printPoints(); + add(rc, BorderLayout.CENTER); } - - if(s==null) + /** + * DOCUMENT ME! + */ + public void run() { - s = new Sequence[av.getAlignment().getHeight()]; - for (int i = 0; i < av.getAlignment().getHeight(); i++) - s[i] = av.getAlignment().getSequenceAt(i); - } - -//////////////////////This part was done in PCATHread originally. Is it too slow??? - pca = new PCA(s); - pca.run(); - - // Now find the component coordinates - int ii=0; - while (ii < s.length && s[ii] != null) - { - ii++; + // do stuff } - double[][] comps = new double[ii][ii]; - - for (int i=0; i < ii; i++ ) + /** + * DOCUMENT ME! + */ + void doDimensionChange() { - if (pca.getEigenvalue(i) > 1e-4) - { - comps[i] = pca.component(i); - } + 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()); } - ////////////////// - - xCombobox.setSelectedIndex(0); - yCombobox.setSelectedIndex(1); - zCombobox.setSelectedIndex(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++ ) + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void xCombobox_actionPerformed(ActionEvent e) { - SequencePoint sp = new SequencePoint(s[i],scores[i]); - points.addElement(sp); + doDimensionChange(); } - rc = new RotatableCanvas(av,points,pca.getM().rows); - - //rc.printPoints(); - - add(rc, BorderLayout.CENTER); - } - - - 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]; + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void yCombobox_actionPerformed(ActionEvent e) + { + doDimensionChange(); } - 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(); - } - + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void zCombobox_actionPerformed(ActionEvent e) + { + doDimensionChange(); + } }