JAL-617 - new menu items for exporting current view or complete PCA pointset
authorjprocter <Jim Procter>
Wed, 18 Aug 2010 16:52:54 +0000 (16:52 +0000)
committerjprocter <Jim Procter>
Wed, 18 Aug 2010 16:52:54 +0000 (16:52 +0000)
src/jalview/gui/PCAPanel.java
src/jalview/gui/RotatableCanvas.java
src/jalview/jbgui/GPCAPanel.java

index 9c852c5..3d38a87 100755 (executable)
@@ -36,6 +36,7 @@ import jalview.jbgui.*;
  */
 public class PCAPanel extends GPCAPanel implements Runnable
 {
+
   PCA pca;
 
   int top;
@@ -243,9 +244,14 @@ public class PCAPanel extends GPCAPanel implements Runnable
   public void outputValues_actionPerformed(ActionEvent e)
   {
     CutAndPasteTransfer cap = new CutAndPasteTransfer();
-    Desktop.addInternalFrame(cap, "PCA details", 500, 500);
-
-    cap.setText(pca.getDetails());
+    try {
+      cap.setText(pca.getDetails());
+      Desktop.addInternalFrame(cap, "PCA details", 500, 500);
+    } catch (OutOfMemoryError oom)
+    {
+      new OOMWarning("opening PCA details",oom);
+      cap.dispose();
+    }
   }
 
   public void showLabels_actionPerformed(ActionEvent e)
@@ -486,5 +492,80 @@ public class PCAPanel extends GPCAPanel implements Runnable
     associateViewsMenu.add(itemf);
 
   }
+  /* (non-Javadoc)
+   * @see jalview.jbgui.GPCAPanel#outputPoints_actionPerformed(java.awt.event.ActionEvent)
+   */
+  protected void outputPoints_actionPerformed(ActionEvent e)
+  {
+    CutAndPasteTransfer cap = new CutAndPasteTransfer();
+    try {
+      cap.setText(getPointsasCsv(false));
+      Desktop.addInternalFrame(cap, "Points for "+getTitle(), 500, 500);
+    } catch (OutOfMemoryError oom)
+    {
+      new OOMWarning("exporting PCA points",oom);
+      cap.dispose();
+    }
+  }
+
+  private String getPointsasCsv(boolean transformed)
+  {
+    StringBuffer csv = new StringBuffer();
+    csv.append("\"Sequence\"");
+    if (transformed) {
+      csv.append(",");
+      csv.append(xCombobox.getSelectedIndex());
+      csv.append(",");
+      csv.append(yCombobox.getSelectedIndex());
+      csv.append(",");
+      csv.append(zCombobox.getSelectedIndex());
+    } else {
+      for (int d=1,dmax=pca.component(1).length;d<=dmax;d++)
+      {
+        csv.append(","+d);
+      }
+    }
+    csv.append("\n");
+    for (int s=0;s<seqs.length;s++)
+    {
+      csv.append("\""+seqs[s].getName()+"\"");
+      double fl[];
+      if (!transformed) {
+        // output pca in correct order
+        fl = pca.component(s);
+        for (int d=fl.length-1; d>=0;d--)
+        {
+          csv.append(",");
+          csv.append(fl[d]);
+        }
+    } else {
+      // output current x,y,z coords for points
+        fl = rc.getPointPosition(s);
+        for (int d=0; d<fl.length;d++)
+        {
+          csv.append(",");
+          csv.append(fl[d]);
+        }
+      }
+      csv.append("\n");
+    }
+    return csv.toString();
+  }
+
+  /* (non-Javadoc)
+   * @see jalview.jbgui.GPCAPanel#outputProjPoints_actionPerformed(java.awt.event.ActionEvent)
+   */
+  protected void outputProjPoints_actionPerformed(ActionEvent e)
+  {
+    CutAndPasteTransfer cap = new CutAndPasteTransfer();
+    try {
+      cap.setText(getPointsasCsv(true));
+      Desktop.addInternalFrame(cap, "Transformed points for "+getTitle(), 500, 500);
+    } catch (OutOfMemoryError oom)
+    {
+      new OOMWarning("exporting transformed PCA points",oom);
+      cap.dispose();
+    }
+  }
 
 }
index 883a4c9..3b983fe 100755 (executable)
@@ -815,4 +815,19 @@ public class RotatableCanvas extends JPanel implements MouseListener,
       { ap };
     }
   }
+
+  /**
+   * 
+   * @return x,y,z positions of point s (index into points) under current transform.
+   */
+  public double[] getPointPosition(int s)
+  {
+    double pts[] = new double[3];
+    float[] p = ((SequencePoint)points.elementAt(s)).coord;
+    pts[0] = p[0];
+    pts[1] = p[1];
+    pts[2] = p[2];
+    return pts;
+  }
+
 }
index 0b0a246..d7e1ba4 100755 (executable)
@@ -19,6 +19,7 @@ package jalview.jbgui;
 
 import java.awt.*;
 import java.awt.event.*;
+
 import javax.swing.*;
 import javax.swing.event.*;
 
@@ -55,6 +56,9 @@ public class GPCAPanel extends JInternalFrame
   JMenuItem print = new JMenuItem();
 
   JMenuItem outputValues = new JMenuItem();
+  
+  JMenuItem outputPoints = new JMenuItem();
+  JMenuItem outputProjPoints = new JMenuItem();
 
   protected JMenu viewMenu = new JMenu();
 
@@ -148,6 +152,22 @@ public class GPCAPanel extends JInternalFrame
         outputValues_actionPerformed(e);
       }
     });
+    outputPoints.setText("Output points...");
+    outputPoints.addActionListener(new ActionListener()
+    {
+      public void actionPerformed(ActionEvent e)
+      {
+        outputPoints_actionPerformed(e);
+      }
+    });
+    outputProjPoints.setText("Output transformed points...");
+    outputProjPoints.addActionListener(new ActionListener()
+    {
+      public void actionPerformed(ActionEvent e)
+      {
+        outputProjPoints_actionPerformed(e);
+      }
+    });
     print.addActionListener(new ActionListener()
     {
       public void actionPerformed(ActionEvent e)
@@ -210,6 +230,8 @@ public class GPCAPanel extends JInternalFrame
     fileMenu.add(outputValues);
     fileMenu.add(print);
     fileMenu.add(originalSeqData);
+    fileMenu.add(outputPoints);
+    fileMenu.add(outputProjPoints);
     saveMenu.add(eps);
     saveMenu.add(png);
     viewMenu.add(showLabels);
@@ -217,6 +239,18 @@ public class GPCAPanel extends JInternalFrame
     viewMenu.add(associateViewsMenu);
   }
 
+  protected void outputPoints_actionPerformed(ActionEvent e)
+  {
+    // TODO Auto-generated method stub
+    
+  }
+
+  protected void outputProjPoints_actionPerformed(ActionEvent e)
+  {
+    // TODO Auto-generated method stub
+    
+  }
+
   protected void xCombobox_actionPerformed(ActionEvent e)
   {
   }