X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fappletgui%2FPCAPanel.java;h=b121828c8e5bf3b3b18db3cdfac298f38af0958f;hb=fd618c7346eab858aa0039376872820aca37783a;hp=845e8804b175abf5603dfcc0e865b276e6409fe9;hpb=174230b4233d9ce80f94527768d2cd2f76da11ab;p=jalview.git diff --git a/src/jalview/appletgui/PCAPanel.java b/src/jalview/appletgui/PCAPanel.java index 845e880..b121828 100755 --- a/src/jalview/appletgui/PCAPanel.java +++ b/src/jalview/appletgui/PCAPanel.java @@ -1,6 +1,6 @@ /* * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * 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 @@ -27,7 +27,6 @@ import java.awt.event.*; import jalview.analysis.*; import jalview.datamodel.*; - public class PCAPanel extends Frame implements Runnable, ActionListener, ItemListener { @@ -35,10 +34,9 @@ public class PCAPanel int top; RotatableCanvas rc; AlignViewport av; - SequenceI [] seqs; + SequenceI[] seqs; AlignmentView seqstrings; - public PCAPanel(AlignViewport av) { try @@ -58,8 +56,8 @@ public class PCAPanel } this.av = av; - seqstrings = av.getAlignmentView(av.getSelectionGroup()!=null); - if(av.getSelectionGroup()==null) + seqstrings = av.getAlignmentView(av.getSelectionGroup() != null); + if (av.getSelectionGroup() == null) { seqs = av.alignment.getSequencesArray(); } @@ -67,7 +65,7 @@ public class PCAPanel { seqs = av.getSelectionGroup().getSequencesInOrder(av.alignment); } - SeqCigar sq[]=seqstrings.getSequences(); + SeqCigar sq[] = seqstrings.getSequences(); int length = sq[0].getWidth(); for (int i = 0; i < seqs.length; i++) @@ -79,13 +77,11 @@ public class PCAPanel } } - rc = new RotatableCanvas(av); add(rc, BorderLayout.CENTER); jalview.bin.JalviewLite.addFrame(this, "Principal component analysis", - 400, 400); - + 400, 400); Thread worker = new Thread(this); worker.start(); @@ -96,47 +92,47 @@ public class PCAPanel */ 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++) - { - 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(); + 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++) + { + 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() @@ -164,23 +160,32 @@ public class PCAPanel public void actionPerformed(ActionEvent evt) { - if(evt.getSource()==inputData) + if (evt.getSource() == inputData) + { showOriginalData(); + } else + { values_actionPerformed(); + } } public void itemStateChanged(ItemEvent evt) { - if(evt.getSource()==xCombobox) + if (evt.getSource() == xCombobox) + { xCombobox_actionPerformed(); - else if(evt.getSource()==yCombobox) + } + else if (evt.getSource() == yCombobox) + { yCombobox_actionPerformed(); - else if(evt.getSource()==zCombobox) + } + else if (evt.getSource() == zCombobox) + { zCombobox_actionPerformed(); + } } - protected void xCombobox_actionPerformed() { doDimensionChange(); @@ -204,7 +209,7 @@ public class PCAPanel frame.add(cap); jalview.bin.JalviewLite.addFrame(frame, "PCA details", 500, 500); - cap.setText(pca.getDetails()); + cap.setText(pca.getDetails()); } void showOriginalData() @@ -216,23 +221,23 @@ public class PCAPanel Object[] alAndColsel = seqstrings.getAlignmentAndColumnSelection(av. getGapCharacter()); + 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); - 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); - - af.viewport.setHiddenColumns( (ColumnSelection) alAndColsel[1] ); - } + af.viewport.setHiddenColumns( (ColumnSelection) alAndColsel[1]); + } } public void labels_itemStateChanged(ItemEvent itemEvent) { - rc.showLabels( labels.getState() ); + rc.showLabels(labels.getState()); } + Panel jPanel2 = new Panel(); Label jLabel1 = new Label(); Label jLabel2 = new Label();