/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2007 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 (Version 2.7)
+ * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
+ *
+ * This file is part of Jalview.
+ *
+ * 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.
+ *
+ * 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 <http://www.gnu.org/licenses/>.
*/
-
package jalview.appletgui;
import java.util.*;
import jalview.analysis.*;
import jalview.datamodel.*;
+import jalview.viewmodel.PCAModel;
-public class PCAPanel
- extends EmbmenuFrame implements Runnable, ActionListener, ItemListener
+public class PCAPanel extends EmbmenuFrame implements Runnable,
+ ActionListener, ItemListener
{
- PCA pca;
- int top;
RotatableCanvas rc;
+
AlignViewport av;
- SequenceI[] seqs;
- AlignmentView seqstrings;
+
+ PCAModel pcaModel;
+
+ int top = 0;
public PCAPanel(AlignViewport av)
{
try
{
jbInit();
- }
- catch (Exception e)
+ } catch (Exception e)
{
e.printStackTrace();
}
}
this.av = av;
- seqstrings = av.getAlignmentView(av.getSelectionGroup() != null);
+ AlignmentView seqstrings = av
+ .getAlignmentView(av.getSelectionGroup() != null);
+ boolean nucleotide = av.getAlignment().isNucleotide();
+ SequenceI[] seqs;
if (av.getSelectionGroup() == null)
{
- seqs = av.alignment.getSequencesArray();
+ seqs = av.getAlignment().getSequencesArray();
}
else
{
- seqs = av.getSelectionGroup().getSequencesInOrder(av.alignment);
+ seqs = av.getSelectionGroup().getSequencesInOrder(av.getAlignment());
}
SeqCigar sq[] = seqstrings.getSequences();
int length = sq[0].getWidth();
{
if (sq[i].getWidth() != length)
{
- System.out.println("Sequences must be equal length for PCA analysis");
+ System.out
+ .println("Sequences must be equal length for PCA analysis");
return;
}
}
+ pcaModel = new PCAModel(seqstrings, seqs, nucleotide);
rc = new RotatableCanvas(av);
embedMenuIfNeeded(rc);
add(rc, BorderLayout.CENTER);
jalview.bin.JalviewLite.addFrame(this, "Principal component analysis",
- 400, 400);
+ 475, 400);
Thread worker = new Thread(this);
worker.start();
*/
public void run()
{
- pca = new PCA(seqstrings.getSequenceStrings(' '));
- 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++)
+ // TODO progress indicator
+ calcSettings.setEnabled(false);
+ rc.setEnabled(false);
+ try
{
- 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++)
+ nuclSetting.setState(pcaModel.isNucleotide());
+ protSetting.setState(!pcaModel.isNucleotide());
+ pcaModel.run();
+ // ////////////////
+ xCombobox.select(0);
+ yCombobox.select(1);
+ zCombobox.select(2);
+
+ pcaModel.updateRc(rc);
+ // rc.invalidate();
+ top = pcaModel.getTop();
+ } catch (OutOfMemoryError x)
{
- SequencePoint sp = new SequencePoint(seqs[i], scores[i]);
- points.addElement(sp);
+ System.err.println("Out of memory when calculating PCA.");
+ return;
}
+ calcSettings.setEnabled(true);
- rc.setPoints(points, pca.getM().rows);
+ // TODO revert progress indicator
+ rc.setEnabled(true);
rc.repaint();
- seqs = null;
this.repaint();
}
{
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];
- }
-
+ pcaModel.updateRcView(dim1, dim2, dim3);
rc.img = null;
rc.rotmat.setIdentity();
rc.initAxes();
{
showOriginalData();
}
- else
+ if (evt.getSource() == resetButton)
+ {
+ xCombobox.select(0);
+ yCombobox.select(1);
+ zCombobox.select(2);
+ doDimensionChange();
+ }
+ if (evt.getSource() == values)
{
values_actionPerformed();
}
{
zCombobox_actionPerformed();
}
+ else if (evt.getSource() == labels)
+ {
+ labels_itemStateChanged(evt);
+ }
+ else if (evt.getSource() == nuclSetting)
+ {
+ if (!pcaModel.isNucleotide())
+ {
+ pcaModel.setNucleotide(true);
+ new Thread(this).start();
+ }
+ }
+ else if (evt.getSource() == protSetting)
+ {
+ if (pcaModel.isNucleotide())
+ {
+ pcaModel.setNucleotide(false);
+ new Thread(this).start();
+ }
+ }
}
protected void xCombobox_actionPerformed()
frame.add(cap);
jalview.bin.JalviewLite.addFrame(frame, "PCA details", 500, 500);
- cap.setText(pca.getDetails());
+ cap.setText(pcaModel.getDetails());
}
void showOriginalData()
{
- // decide if av alignment is sufficiently different to original data to warrant a new window to be created
- // create new alignmnt window with hidden regions (unhiding hidden regions yields unaligned seqs)
+ // decide if av alignment is sufficiently different to original data to
+ // warrant a new window to be created
+ // create new alignmnt window with hidden regions (unhiding hidden regions
+ // yields unaligned seqs)
// or create a selection box around columns in alignment view
// test Alignment(SeqCigar[])
- Object[] alAndColsel = seqstrings.getAlignmentAndColumnSelection(av.
- getGapCharacter());
+ char gc = '-';
+ try
+ {
+ // we try to get the associated view's gap character
+ // but this may fail if the view was closed...
+ gc = av.getGapCharacter();
+ } catch (Exception ex)
+ {
+ }
+ ;
+ Object[] alAndColsel = pcaModel.getSeqtrings()
+ .getAlignmentAndColumnSelection(gc);
if (alAndColsel != null && alAndColsel[0] != null)
{
- Alignment al = new Alignment( (SequenceI[]) alAndColsel[0]);
- AlignFrame af = new AlignFrame(al,
- av.applet,
- "Original Data for PCA",
- false);
+ Alignment al = new Alignment((SequenceI[]) alAndColsel[0]);
+ AlignFrame af = new AlignFrame(al, av.applet,
+ "Original Data for PCA", false);
- af.viewport.setHiddenColumns( (ColumnSelection) alAndColsel[1]);
+ af.viewport.setHiddenColumns((ColumnSelection) alAndColsel[1]);
}
}
}
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();
+
+ protected Button resetButton = new Button();
+
FlowLayout flowLayout1 = new FlowLayout();
+
BorderLayout borderLayout1 = new BorderLayout();
+
MenuBar menuBar1 = new MenuBar();
+
Menu menu1 = new Menu();
+
Menu menu2 = new Menu();
+
+ Menu calcSettings = new Menu();
+
protected CheckboxMenuItem labels = new CheckboxMenuItem();
+
+ protected CheckboxMenuItem protSetting = new CheckboxMenuItem();
+
+ protected CheckboxMenuItem nuclSetting = new CheckboxMenuItem();
+
MenuItem values = new MenuItem();
+
MenuItem inputData = new MenuItem();
- private void jbInit()
- throws Exception
+ private void jbInit() throws Exception
{
this.setLayout(borderLayout1);
jPanel2.setLayout(flowLayout1);
yCombobox.addItemListener(this);
xCombobox.setFont(new java.awt.Font("Verdana", 0, 12));
xCombobox.addItemListener(this);
+ resetButton.setFont(new java.awt.Font("Verdana", 0, 12));
+ resetButton.setLabel("Reset");
+ resetButton.addActionListener(this);
this.setMenuBar(menuBar1);
menu1.setLabel("File");
menu2.setLabel("View");
+ calcSettings.setLabel("Change Parameters");
labels.setLabel("Labels");
labels.addItemListener(this);
values.setLabel("Output Values...");
values.addActionListener(this);
inputData.setLabel("Input Data...");
+ nuclSetting.setLabel("Nucleotide matrix");
+ nuclSetting.addItemListener(this);
+ protSetting.setLabel("Protein matrix");
+ protSetting.addItemListener(this);
this.add(jPanel2, BorderLayout.SOUTH);
jPanel2.add(jLabel1, null);
jPanel2.add(xCombobox, null);
jPanel2.add(yCombobox, null);
jPanel2.add(jLabel3, null);
jPanel2.add(zCombobox, null);
+ jPanel2.add(resetButton, null);
menuBar1.add(menu1);
menuBar1.add(menu2);
+ menuBar1.add(calcSettings);
menu2.add(labels);
menu1.add(values);
menu1.add(inputData);
+ calcSettings.add(nuclSetting);
+ calcSettings.add(protSetting);
inputData.addActionListener(this);
}