X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FPCAPanel.java;h=ac37106fde9221eae33edc2d36afa53217bfcda7;hb=a45774ee31d9f35d4eff46d54d7deab719afb092;hp=b397cf598a6bd0372c9534c6ddbd6ce6412ec6e2;hpb=506d60f0e188723ddc91c26824b41ac7034df3fe;p=jalview.git diff --git a/src/jalview/gui/PCAPanel.java b/src/jalview/gui/PCAPanel.java index b397cf5..ac37106 100755 --- a/src/jalview/gui/PCAPanel.java +++ b/src/jalview/gui/PCAPanel.java @@ -1,20 +1,19 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4) - * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7) + * Copyright (C) 2011 J Procter, AM Waterhouse, 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 file is part of Jalview. * - * 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. + * Jalview 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 3 of the License, or (at your option) any later version. * - * 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 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 Jalview. If not, see . */ package jalview.gui; @@ -37,6 +36,7 @@ import jalview.jbgui.*; */ public class PCAPanel extends GPCAPanel implements Runnable { + PCA pca; int top; @@ -55,9 +55,9 @@ public class PCAPanel extends GPCAPanel implements Runnable * Creates a new PCAPanel object. * * @param av - * DOCUMENT ME! + * DOCUMENT ME! * @param s - * DOCUMENT ME! + * DOCUMENT ME! */ public PCAPanel(AlignmentPanel ap) { @@ -100,9 +100,7 @@ public class PCAPanel extends GPCAPanel implements Runnable return; } - Desktop - .addInternalFrame(this, "Principal component analysis", 400, - 400); + Desktop.addInternalFrame(this, "Principal component analysis", 400, 400); PaintRefresher.Register(this, av.getSequenceSetId()); @@ -212,7 +210,7 @@ public class PCAPanel extends GPCAPanel implements Runnable * DOCUMENT ME! * * @param e - * DOCUMENT ME! + * DOCUMENT ME! */ protected void xCombobox_actionPerformed(ActionEvent e) { @@ -223,7 +221,7 @@ public class PCAPanel extends GPCAPanel implements Runnable * DOCUMENT ME! * * @param e - * DOCUMENT ME! + * DOCUMENT ME! */ protected void yCombobox_actionPerformed(ActionEvent e) { @@ -234,7 +232,7 @@ public class PCAPanel extends GPCAPanel implements Runnable * DOCUMENT ME! * * @param e - * DOCUMENT ME! + * DOCUMENT ME! */ protected void zCombobox_actionPerformed(ActionEvent e) { @@ -244,9 +242,15 @@ public class PCAPanel extends GPCAPanel implements Runnable public void outputValues_actionPerformed(ActionEvent e) { CutAndPasteTransfer cap = new CutAndPasteTransfer(); - Desktop.addInternalFrame(cap, "PCA details", 500, 500); - - cap.setText(pca.getDetails()); + try + { + cap.setText(pca.getDetails()); + Desktop.addInternalFrame(cap, "PCA details", 500, 500); + } catch (OutOfMemoryError oom) + { + new OOMWarning("opening PCA details", oom); + cap.dispose(); + } } public void showLabels_actionPerformed(ActionEvent e) @@ -322,8 +326,7 @@ public class PCAPanel extends GPCAPanel implements Runnable * CutAndPasteTransfer cap = new CutAndPasteTransfer(); for (int i = 0; i < * seqs.length; i++) { cap.appendText(new jalview.util.Format("%-" + 15 + * "s").form( seqs[i].getName())); cap.appendText(" " + seqstrings[i] + - * "\n"); - * } + * "\n"); } * * Desktop.addInternalFrame(cap, "Original Data", 400, 400); */ @@ -377,7 +380,7 @@ public class PCAPanel extends GPCAPanel implements Runnable * DOCUMENT ME! * * @param e - * DOCUMENT ME! + * DOCUMENT ME! */ public void eps_actionPerformed(ActionEvent e) { @@ -388,7 +391,7 @@ public class PCAPanel extends GPCAPanel implements Runnable * DOCUMENT ME! * * @param e - * DOCUMENT ME! + * DOCUMENT ME! */ public void png_actionPerformed(ActionEvent e) { @@ -410,8 +413,8 @@ public class PCAPanel extends GPCAPanel implements Runnable else { im = new jalview.util.ImageMaker(this, jalview.util.ImageMaker.EPS, - "Make EPS file from PCA", width, height, null, this - .getTitle()); + "Make EPS file from PCA", width, height, null, + this.getTitle()); } if (im.getGraphics() != null) @@ -489,4 +492,97 @@ public class PCAPanel extends GPCAPanel implements Runnable } + /* + * (non-Javadoc) + * + * @see + * jalview.jbgui.GPCAPanel#outputPoints_actionPerformed(java.awt.event.ActionEvent + * ) + */ + protected void outputPoints_actionPerformed(ActionEvent e) + { + CutAndPasteTransfer cap = new CutAndPasteTransfer(); + try + { + cap.setText(getPointsasCsv(false)); + Desktop.addInternalFrame(cap, "Points for " + getTitle(), 500, 500); + } catch (OutOfMemoryError oom) + { + new OOMWarning("exporting PCA points", oom); + cap.dispose(); + } + } + + private String getPointsasCsv(boolean transformed) + { + StringBuffer csv = new StringBuffer(); + csv.append("\"Sequence\""); + if (transformed) + { + csv.append(","); + csv.append(xCombobox.getSelectedIndex()); + csv.append(","); + csv.append(yCombobox.getSelectedIndex()); + csv.append(","); + csv.append(zCombobox.getSelectedIndex()); + } + else + { + for (int d = 1, dmax = pca.component(1).length; d <= dmax; d++) + { + csv.append("," + d); + } + } + csv.append("\n"); + for (int s = 0; s < seqs.length; s++) + { + csv.append("\"" + seqs[s].getName() + "\""); + double fl[]; + if (!transformed) + { + // output pca in correct order + fl = pca.component(s); + for (int d = fl.length - 1; d >= 0; d--) + { + csv.append(","); + csv.append(fl[d]); + } + } + else + { + // output current x,y,z coords for points + fl = rc.getPointPosition(s); + for (int d = 0; d < fl.length; d++) + { + csv.append(","); + csv.append(fl[d]); + } + } + csv.append("\n"); + } + return csv.toString(); + } + + /* + * (non-Javadoc) + * + * @see + * jalview.jbgui.GPCAPanel#outputProjPoints_actionPerformed(java.awt.event + * .ActionEvent) + */ + protected void outputProjPoints_actionPerformed(ActionEvent e) + { + CutAndPasteTransfer cap = new CutAndPasteTransfer(); + try + { + cap.setText(getPointsasCsv(true)); + Desktop.addInternalFrame(cap, "Transformed points for " + getTitle(), + 500, 500); + } catch (OutOfMemoryError oom) + { + new OOMWarning("exporting transformed PCA points", oom); + cap.dispose(); + } + } + }