Formatted source
[jalview.git] / src / jalview / gui / PCAPanel.java
index 8f3ff73..ebde9cb 100755 (executable)
 /*\r
-* Jalview - A Sequence Alignment Editor and Viewer\r
-* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
-*\r
-* This program is free software; you can redistribute it and/or\r
-* modify it under the terms of the GNU General Public License\r
-* as published by the Free Software Foundation; either version 2\r
-* of the License, or (at your option) any later version.\r
-*\r
-* This program is distributed in the hope that it will be useful,\r
-* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-* GNU General Public License for more details.\r
-*\r
-* You should have received a copy of the GNU General Public License\r
-* along with this program; if not, write to the Free Software\r
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
-*/\r
-\r
+ * Jalview - A Sequence Alignment Editor and Viewer\r
+ * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
+ */\r
 package jalview.gui;\r
 \r
-import jalview.datamodel.*;\r
-import jalview.analysis.PCA;\r
-import jalview.jbgui.*;\r
+import java.util.*;\r
+\r
 import java.awt.*;\r
 import java.awt.event.*;\r
-import java.util.*;\r
 \r
+import jalview.analysis.*;\r
+import jalview.datamodel.*;\r
+import jalview.jbgui.*;\r
 \r
-public class PCAPanel extends GPCAPanel implements Runnable\r
+public class PCAPanel\r
+    extends GPCAPanel implements Runnable\r
 {\r
   PCA pca;\r
   int top;\r
   RotatableCanvas rc;\r
   AlignViewport av;\r
 \r
-  public void run()\r
+  public PCAPanel(AlignViewport av, SequenceI[] s)\r
   {\r
-    // do stuff\r
-  }\r
-\r
-  public PCAPanel(AlignViewport av, SequenceI[] s) {\r
-\r
     this.av = av;\r
-    if(av.getSelectionGroup()!=null && av.getSelectionGroup().getSize()>3)\r
+\r
+    if ( (av.getSelectionGroup() != null) &&\r
+        (av.getSelectionGroup().getSize() > 3))\r
     {\r
       s = new Sequence[av.getSelectionGroup().getSize()];\r
-      for(int i=0; i<s.length; i++)\r
+\r
+      for (int i = 0; i < s.length; i++)\r
+      {\r
         s[i] = av.getSelectionGroup().getSequenceAt(i);\r
+      }\r
     }\r
 \r
-\r
-    if(s==null)\r
+    if (s == null)\r
     {\r
       s = new Sequence[av.getAlignment().getHeight()];\r
+\r
       for (int i = 0; i < av.getAlignment().getHeight(); i++)\r
+      {\r
         s[i] = av.getAlignment().getSequenceAt(i);\r
-     }\r
+      }\r
+    }\r
 \r
-//////////////////////This part was done in PCATHread originally. Is it too slow???\r
+    //////////////////////This part was done in PCATHread originally. Is it too slow???\r
     pca = new PCA(s);\r
     pca.run();\r
 \r
     // Now find the component coordinates\r
-    int ii=0;\r
-    while (ii < s.length && s[ii] != null)\r
+    int ii = 0;\r
+\r
+    while ( (ii < s.length) && (s[ii] != null))\r
     {\r
       ii++;\r
     }\r
 \r
     double[][] comps = new double[ii][ii];\r
 \r
-    for (int i=0; i < ii; i++ )\r
+    for (int i = 0; i < ii; i++)\r
     {\r
       if (pca.getEigenvalue(i) > 1e-4)\r
       {\r
-        comps[i]  = pca.component(i);\r
+        comps[i] = pca.component(i);\r
       }\r
     }\r
 \r
     //////////////////\r
-\r
     xCombobox.setSelectedIndex(0);\r
     yCombobox.setSelectedIndex(1);\r
     zCombobox.setSelectedIndex(2);\r
 \r
-    top = pca.getM().rows-1;\r
+    top = pca.getM().rows - 1;\r
 \r
     Vector points = new Vector();\r
-    float[][] scores = pca.getComponents(top-1,top-2,top-3,100);\r
+    float[][] scores = pca.getComponents(top - 1, top - 2, top - 3, 100);\r
 \r
-    for (int i =0; i < pca.getM().rows; i++ )\r
+    for (int i = 0; i < pca.getM().rows; i++)\r
     {\r
-      SequencePoint sp = new SequencePoint(s[i],scores[i]);\r
+      SequencePoint sp = new SequencePoint(s[i], scores[i]);\r
       points.addElement(sp);\r
     }\r
 \r
-    rc = new RotatableCanvas(av,points,pca.getM().rows);\r
+    rc = new RotatableCanvas(av, points, pca.getM().rows);\r
 \r
     //rc.printPoints();\r
-\r
     add(rc, BorderLayout.CENTER);\r
   }\r
 \r
+  public void run()\r
+  {\r
+    // do stuff\r
+  }\r
 \r
   void doDimensionChange()\r
   {\r
-    if(top==0)\r
+    if (top == 0)\r
+    {\r
       return;\r
+    }\r
 \r
     int dim1 = top - xCombobox.getSelectedIndex();\r
     int dim2 = top - yCombobox.getSelectedIndex();\r
     int dim3 = top - zCombobox.getSelectedIndex();\r
 \r
-    float[][] scores  = pca.getComponents(dim1,dim2,dim3,100);\r
-    for (int i=0; i < pca.getM().rows; i++) {\r
-      ((SequencePoint)rc.points.elementAt(i)).coord = scores[i];\r
+    float[][] scores = pca.getComponents(dim1, dim2, dim3, 100);\r
+\r
+    for (int i = 0; i < pca.getM().rows; i++)\r
+    {\r
+      ( (SequencePoint) rc.points.elementAt(i)).coord = scores[i];\r
     }\r
 \r
     rc.img = null;\r
@@ -137,5 +147,4 @@ public class PCAPanel extends GPCAPanel implements Runnable
   {\r
     doDimensionChange();\r
   }\r
-\r
 }\r