X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FPCAPanel.java;h=a75de066eaee9a93d56416be9c563a12f32768d0;hb=38299bef6dfd4b713f615781e631dcb66e1155f2;hp=f652aae504245316c29cc2aa225fc00b6b5baa13;hpb=99c58ee0ae2a848f982552e53feaf6d5cb9925e5;p=jalview.git diff --git a/src/jalview/appletgui/PCAPanel.java b/src/jalview/appletgui/PCAPanel.java index f652aae..a75de06 100755 --- a/src/jalview/appletgui/PCAPanel.java +++ b/src/jalview/appletgui/PCAPanel.java @@ -1,120 +1,153 @@ /* -* 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.appletgui; -import jalview.datamodel.*; -import jalview.analysis.PCA; -import jalview.jbappletgui.*; +import java.util.*; + import java.awt.*; import java.awt.event.*; -import java.util.*; + +import jalview.analysis.*; +import jalview.datamodel.*; -public class PCAPanel extends GPCAPanel implements Runnable +public class PCAPanel + extends Frame implements Runnable, ActionListener, ItemListener { PCA pca; int top; RotatableCanvas rc; AlignViewport av; + SequenceI [] seqs; - public void run() - { - // do stuff - } - - public PCAPanel(AlignViewport av, SequenceI[] s) { - this.av = av; - if(av.getSelectionGroup().getSize()>3) + public PCAPanel(AlignViewport av) + { + try { - s = new Sequence[av.getSelectionGroup().getSize()]; - for(int i=0; i 3) { - if (pca.getEigenvalue(i) > 1e-4) + seqs = new Sequence[av.getSelectionGroup().getSize()]; + for (int i = 0; i < av.getSelectionGroup().getSize(); i++) { - comps[i] = pca.component(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); - xCombobox.select(0); - yCombobox.select(1); - zCombobox.select(2); + jalview.bin.JalviewLite.addFrame(this, "Principal component analysis", + 400, 400); - top = pca.getM().rows-1; - Vector points = new Vector(); - float[][] scores = pca.getComponents(top-1,top-2,top-3,100); + Thread worker = new Thread(this); + worker.start(); + } - for (int i =0; i < pca.getM().rows; i++ ) - { - SequencePoint sp = new SequencePoint(s[i],scores[i]); - points.addElement(sp); - } + /** + * DOCUMENT ME! + */ + public void run() + { + pca = new PCA(seqs); + pca.run(); - rc = new RotatableCanvas(av,points,pca.getM().rows); + // Now find the component coordinates + int ii = 0; - //rc.printPoints(); + while ((ii < seqs.length) && (seqs[ii] != null)) + { + ii++; + } - add(rc, BorderLayout.CENTER); - } + 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; + this.repaint(); + } void doDimensionChange() { - if(top==0) + 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]; + 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; @@ -123,19 +156,103 @@ public class PCAPanel extends GPCAPanel implements Runnable rc.paint(rc.getGraphics()); } - protected void xCombobox_actionPerformed(ActionEvent e) + public void actionPerformed(ActionEvent evt) + { + values_actionPerformed(); + } + + public void itemStateChanged(ItemEvent evt) + { + if(evt.getSource()==xCombobox) + xCombobox_actionPerformed(); + else if(evt.getSource()==yCombobox) + yCombobox_actionPerformed(); + else if(evt.getSource()==zCombobox) + zCombobox_actionPerformed(); + } + + + protected void xCombobox_actionPerformed() { doDimensionChange(); } - protected void yCombobox_actionPerformed(ActionEvent e) + protected void yCombobox_actionPerformed() { doDimensionChange(); } - protected void zCombobox_actionPerformed(ActionEvent e) + protected void zCombobox_actionPerformed() { doDimensionChange(); } + public void values_actionPerformed() + { + + CutAndPasteTransfer cap = new CutAndPasteTransfer(false, null); + Frame frame = new Frame(); + frame.add(cap); + jalview.bin.JalviewLite.addFrame(frame, "PCA details", 500, 500); + + cap.setText(pca.getDetails()); + } + + public void labels_itemStateChanged(ItemEvent itemEvent) + { + rc.showLabels( labels.getState() ); + } + Panel jPanel2 = new Panel(); + Label jLabel1 = new Label(); + Label jLabel2 = new Label(); + Label jLabel3 = new Label(); + protected Choice xCombobox = new Choice(); + protected Choice yCombobox = new Choice(); + protected Choice zCombobox = new Choice(); + FlowLayout flowLayout1 = new FlowLayout(); + BorderLayout borderLayout1 = new BorderLayout(); + MenuBar menuBar1 = new MenuBar(); + Menu menu1 = new Menu(); + Menu menu2 = new Menu(); + protected CheckboxMenuItem labels = new CheckboxMenuItem(); + MenuItem values = new MenuItem(); + + private void jbInit() + throws Exception + { + this.setLayout(borderLayout1); + jPanel2.setLayout(flowLayout1); + jLabel1.setFont(new java.awt.Font("Verdana", 0, 12)); + jLabel1.setText("x="); + jLabel2.setFont(new java.awt.Font("Verdana", 0, 12)); + jLabel2.setText("y="); + jLabel3.setFont(new java.awt.Font("Verdana", 0, 12)); + jLabel3.setText("z="); + jPanel2.setBackground(Color.white); + zCombobox.setFont(new java.awt.Font("Verdana", 0, 12)); + zCombobox.addItemListener(this); + yCombobox.setFont(new java.awt.Font("Verdana", 0, 12)); + yCombobox.addItemListener(this); + xCombobox.setFont(new java.awt.Font("Verdana", 0, 12)); + xCombobox.addItemListener(this); + this.setMenuBar(menuBar1); + menu1.setLabel("File"); + menu2.setLabel("View"); + labels.setLabel("Labels"); + labels.addItemListener(this); + values.setLabel("Output Values..."); + values.addActionListener(this); + this.add(jPanel2, BorderLayout.SOUTH); + jPanel2.add(jLabel1, null); + jPanel2.add(xCombobox, null); + jPanel2.add(jLabel2, null); + jPanel2.add(yCombobox, null); + jPanel2.add(jLabel3, null); + jPanel2.add(zCombobox, null); + menuBar1.add(menu1); + menuBar1.add(menu2); + menu2.add(labels); + menu1.add(values); + } + }