Formatted source
[jalview.git] / src / jalview / appletgui / PCAPanel.java
index f652aae..1dd05e0 100755 (executable)
@@ -1,33 +1,35 @@
 /*\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
+ * 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
 package jalview.appletgui;\r
 \r
-import jalview.datamodel.*;\r
-import jalview.analysis.PCA;\r
-import jalview.jbappletgui.*;\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.jbappletgui.*;\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
@@ -39,30 +41,34 @@ public class PCAPanel extends GPCAPanel implements Runnable
     // do stuff\r
   }\r
 \r
-  public PCAPanel(AlignViewport av, SequenceI[] s) {\r
+  public PCAPanel(AlignViewport av, SequenceI[] s)\r
+  {\r
 \r
     this.av = av;\r
-    if(av.getSelectionGroup().getSize()>3)\r
+    if (av.getSelectionGroup().getSize() > 3)\r
     {\r
       s = new Sequence[av.getSelectionGroup().getSize()];\r
-      for(int i=0; i<s.length; i++)\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
       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
     pca = new PCA(s);\r
     pca.run();\r
 \r
     // Now find the component coordinates\r
-    int ii=0;\r
+    int ii = 0;\r
     while (ii < s.length && s[ii] != null)\r
     {\r
       ii++;\r
@@ -70,11 +76,11 @@ public class PCAPanel extends GPCAPanel implements Runnable
 \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
@@ -84,37 +90,39 @@ public class PCAPanel extends GPCAPanel implements Runnable
     yCombobox.select(1);\r
     zCombobox.select(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
-\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
+    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