Sequences must be aligned before PCA
authoramwaterhouse <Andrew Waterhouse>
Wed, 21 Sep 2005 17:08:56 +0000 (17:08 +0000)
committeramwaterhouse <Andrew Waterhouse>
Wed, 21 Sep 2005 17:08:56 +0000 (17:08 +0000)
src/jalview/appletgui/AlignFrame.java
src/jalview/gui/AlignFrame.java
src/jalview/gui/PCAPanel.java

index 1cfddf8..3da1401 100755 (executable)
@@ -1125,6 +1125,24 @@ public class AlignFrame
 \r
   public void PCAMenuItem_actionPerformed(ActionEvent e)\r
   {\r
+    //are the sequences aligned?\r
+    if (!viewport.alignment.isAligned())\r
+    {\r
+      SequenceI current;\r
+      int Width = viewport.getAlignment().getWidth();\r
+\r
+      for (int i = 0; i < viewport.getAlignment().getSequences().size();\r
+           i++)\r
+      {\r
+        current = viewport.getAlignment().getSequenceAt(i);\r
+\r
+        if (current.getLength() < Width)\r
+        {\r
+          current.insertCharAt(Width - 1, viewport.getGapCharacter());\r
+        }\r
+      }\r
+      alignPanel.repaint();\r
+    }\r
 \r
     if ( (viewport.getSelectionGroup() != null &&\r
           viewport.getSelectionGroup().getSize() < 4 &&\r
index b6705ad..4d0e1b2 100755 (executable)
@@ -1149,7 +1149,7 @@ public class AlignFrame
    */\r
   public void font_actionPerformed(ActionEvent e)\r
   {\r
-    FontChooser fc = new FontChooser(alignPanel);\r
+    new FontChooser(alignPanel);\r
   }\r
 \r
   /**\r
@@ -1836,11 +1836,7 @@ public class AlignFrame
       return;\r
     }\r
 \r
-      PCAPanel pcaPanel = new PCAPanel(viewport);\r
-      JInternalFrame frame = new JInternalFrame();\r
-      frame.setContentPane(pcaPanel);\r
-      Desktop.addInternalFrame(frame, "Principal component analysis",\r
-                               400, 400);\r
+     new PCAPanel(viewport);\r
   }\r
 \r
   /**\r
index 8685b3e..26f1160 100755 (executable)
@@ -29,6 +29,7 @@ import java.awt.event.*;
 \r
 import java.util.*;\r
 import javax.swing.JOptionPane;\r
+import javax.swing.JInternalFrame;\r
 \r
 \r
 /**\r
@@ -55,26 +56,57 @@ public class PCAPanel extends GPCAPanel implements Runnable
     {\r
         this.av = av;\r
 \r
+        boolean sameLength = true;\r
+\r
         if ((av.getSelectionGroup() != null) &&\r
                 (av.getSelectionGroup().getSize() > 3))\r
         {\r
             seqs = new Sequence[av.getSelectionGroup().getSize()];\r
-\r
+            int length = av.getSelectionGroup().getSequenceAt(0).getLength();\r
             for (int i = 0; i < av.getSelectionGroup().getSize(); i++)\r
             {\r
                 seqs[i] = av.getSelectionGroup().getSequenceAt(i);\r
+                if(seqs[i].getLength()!=length)\r
+                {\r
+                  sameLength = false;\r
+                  break;\r
+                }\r
             }\r
         }\r
         else\r
         {\r
             seqs = new Sequence[av.getAlignment().getHeight()];\r
+            int length = av.alignment.getSequenceAt(0).getLength();\r
 \r
             for (int i = 0; i < av.getAlignment().getHeight(); i++)\r
             {\r
                 seqs[i] = av.getAlignment().getSequenceAt(i);\r
+                if(seqs[i].getLength()!=length)\r
+               {\r
+                 sameLength = false;\r
+                 break;\r
+               }\r
+\r
             }\r
         }\r
 \r
+        if (!sameLength)\r
+        {\r
+          JOptionPane.showMessageDialog(Desktop.desktop,\r
+                                        "The sequences must be aligned before calculating PCA.\n" +\r
+                                        "Try using the Pad function in the edit menu,\n" +\r
+                                        "or one of the multiple sequence alignment web services.",\r
+                                        "Sequences not aligned",\r
+                                        JOptionPane.WARNING_MESSAGE);\r
+\r
+          return;\r
+        }\r
+\r
+        JInternalFrame frame = new JInternalFrame();\r
+        frame.setContentPane(this);\r
+        Desktop.addInternalFrame(frame, "Principal component analysis",\r
+                               400, 400);\r
+\r
 \r
         rc = new RotatableCanvas(av);\r
         add(rc, BorderLayout.CENTER);\r