added CSV export of annotation rows to application.
authorjprocter <Jim Procter>
Fri, 31 Aug 2007 14:05:40 +0000 (14:05 +0000)
committerjprocter <Jim Procter>
Fri, 31 Aug 2007 14:05:40 +0000 (14:05 +0000)
help/html/features/annotation.html
help/html/menus/alwannotations.html
src/jalview/gui/AnnotationExporter.java
src/jalview/io/AnnotationFile.java

index 0c0ccfc..98599e2 100755 (executable)
@@ -1,87 +1,90 @@
-<html>\r
-<head><title>Alignment Annotation</title></head>\r
-<body>\r
-<p><strong>Alignment Annotation</strong></p>\r
-\r
-<p>In addition to the definition of groups and sequence features,\r
-  Jalview can display symbols and graphs under the columns of an\r
-  alignment, and allow you to mark particular columns of an alignment and add symbols and text \r
-  in the annotation area shown below the alignment (which may be hidden if <strong>View&#8594;Show \r
-  Annotation</strong> is not ticked). </p>\r
-<p>Web services can also add annotation to an alignment (see the\r
-  <a href="../webServices/jnet.html">JNet web service</a>), and as of Jalview 2.08 quantitative and symbolic\r
-  annotations can be added to an alignment via an <a href="annotationsFormat.html">Annotations \r
-  File</a> dragged into the alignment window or loaded from the\r
-  alignment's file menu.</p>\r
-<p><strong>Interactive Alignment Annotation</strong></p>\r
-<p>\r
-Annotation rows are added using the <strong>Annotation Label</strong>\r
-menu, which is obtained by clicking anywhere on the annotation row labels\r
-area (below the sequence ID area).\r
-</p>\r
-<ul>\r
-  <li>Add New Row<br>\r
-    <em>Adds a new, named annotation row (a dialog box will pop up for you to \r
-    enter the label for the new row). </em> </li>\r
-  <li>Hide Row<br>\r
-    <em>Hides the annotation row whose label was clicked in order to bring up \r
-    the menu.</em> </li>\r
-  <li>Delete Row<br>\r
-    <em>Deletes the annotation row whose label was clicked in order to bring up \r
-    the menu.</em> </li>\r
-  <li>Show All Hidden Rows<br>\r
-    <em>Shows all hidden annotation rows.</em> </li>\r
-  <li>Show Values in Text Box<br>\r
-    <em>Opens a text box with a list of comma-separated values corresponding to \r
-    the annotation (numerical or otherwise) at each position in the row. This \r
-    is useful to export alignment quality measurements for further analysis.</em> \r
-  </li>\r
-</ul>\r
-<p>\r
-<strong>Editing Label and secondary structure Annotation</strong></p>\r
-<p>\r
-Use the <strong>left mouse button</strong> to select a position along the row that are to\r
-be annotated - these regions will be coloured red. <strong>Control</strong> and <strong>shift</strong> in combination\r
-with the left-click will select more than one position, or a range of\r
-positions on the alignment.\r
-</p>\r
-<p>Once the desired position has been selected, use the <strong>right mouse\r
-button</strong> to open the <strong>annotation menu</strong>:</p>\r
-<ul>\r
-<li>Helix<br><em>Mark selected positions with a helix glyph (a red\r
-oval), and optional text label (see below). A\r
-dialog box will open for you to enter the text. Consecutive ovals\r
-will be rendered as an unbroken red line.</em>\r
-</li>\r
-<li>Sheet<br><em>Mark selected positions with a sheet glyph (a green\r
-arrow oriented from left to right), and optional text label (see\r
-below). A dialog box will open for you to enter the text. Consecutive\r
-arrows will be joined together to form a single green arrow.</em>\r
-</li>\r
-<li>Label<br><em>Set the text label at the selected positions. A\r
-dialog box will open for you to enter the text.  If\r
-more that one consecutive position is marked with the same label, only\r
-the first position's label will be rendered.</em>\r
-</li>\r
-<li>Colour<br><em>Changes the colour of the annotation text label.</em>\r
-</li>\r
-<li>Remove Annotation<br><em>Blanks any annotation at the selected positions on\r
-the row. Note: <strong>This cannot be undone</strong></em>\r
-</li>\r
-</ul>\r
-<p>\r
-User defined annotation is stored and retrieved using <a\r
-href="../features/jalarchive.html">Jalview Archives</a>.\r
-</p>\r
-<p><em>Current Limitations</em></p>\r
-\r
-<p>In the current version of Jalview, reordering of the annotation\r
-rows is not possible. If you save \r
-your annotation as a Jalview file, however, it will be reloaded with user \r
-annotations at the top (nearest the alignment), above any of the\r
-automatically generated Conservation, Quality or consensus\r
-annotations. Finally, the Jalview GUI will not, as yet, allow you to output\r
-Jalview annotation files for the current alignment, change the line\r
-colour, display style, or create groups of quantitative annotation rows.</p>\r
-</body>\r
-</html>\r
+<html>
+<head><title>Alignment Annotation</title></head>
+<body>
+<p><strong>Alignment Annotation</strong></p>
+
+<p>In addition to the definition of groups and sequence features,
+  Jalview can display symbols and graphs under the columns of an
+  alignment, and allow you to mark particular columns of an alignment and add symbols and text 
+  in the annotation area shown below the alignment (which may be hidden if <strong>View&#8594;Show 
+  Annotation</strong> is not ticked). </p>
+<p>Web services can also add annotation to an alignment (see the
+  <a href="../webServices/jnet.html">JNet web service</a>), and as of Jalview 2.08 quantitative and symbolic
+  annotations can be added to an alignment via an <a href="annotationsFormat.html">Annotations 
+  File</a> dragged into the alignment window or loaded from the
+  alignment's file menu.</p>
+<p><strong>Interactive Alignment Annotation</strong></p>
+<p>
+Annotation rows are added using the <strong>Annotation Label</strong>
+menu, which is obtained by clicking anywhere on the annotation row labels
+area (below the sequence ID area).
+</p>
+<ul>
+  <li>Add New Row<br>
+    <em>Adds a new, named annotation row (a dialog box will pop up for you to 
+    enter the label for the new row). </em> </li>
+  <li>Hide Row<br>
+    <em>Hides the annotation row whose label was clicked in order to bring up 
+    the menu.</em> </li>
+  <li>Delete Row<br>
+    <em>Deletes the annotation row whose label was clicked in order to bring up 
+    the menu.</em> </li>
+  <li>Show All Hidden Rows<br>
+    <em>Shows all hidden annotation rows.</em> </li>
+          <li><strong>Export Annotation</strong> <em>(Application only)</em><br>
+       <em>Annotations can be saved to file or output to a text window in either the 
+        Jalview annotations format or as a spreadsheet style set of comma separated values (CSV). </em> </li>
+      <li><strong>Show Values in Text Box</strong> <em>(applet only)</em><br>
+        <em>Opens a text box with a list of comma-separated values corresponding 
+        to the annotation (numerical or otherwise) at each position in the row. 
+        This is useful to export alignment quality measurements for further analysis.</em> 
+      </li>
+</ul>
+<p>
+<strong>Editing Label and secondary structure Annotation</strong></p>
+<p>
+Use the <strong>left mouse button</strong> to select a position along the row that are to
+be annotated - these regions will be coloured red. <strong>Control</strong> and <strong>shift</strong> in combination
+with the left-click will select more than one position, or a range of
+positions on the alignment.
+</p>
+<p>Once the desired position has been selected, use the <strong>right mouse
+button</strong> to open the <strong>annotation menu</strong>:</p>
+<ul>
+<li>Helix<br><em>Mark selected positions with a helix glyph (a red
+oval), and optional text label (see below). A
+dialog box will open for you to enter the text. Consecutive ovals
+will be rendered as an unbroken red line.</em>
+</li>
+<li>Sheet<br><em>Mark selected positions with a sheet glyph (a green
+arrow oriented from left to right), and optional text label (see
+below). A dialog box will open for you to enter the text. Consecutive
+arrows will be joined together to form a single green arrow.</em>
+</li>
+<li>Label<br><em>Set the text label at the selected positions. A
+dialog box will open for you to enter the text.  If
+more that one consecutive position is marked with the same label, only
+the first position's label will be rendered.</em>
+</li>
+<li>Colour<br><em>Changes the colour of the annotation text label.</em>
+</li>
+<li>Remove Annotation<br><em>Blanks any annotation at the selected positions on
+the row. Note: <strong>This cannot be undone</strong></em>
+</li>
+</ul>
+<p>
+User defined annotation is stored and retrieved using <a
+href="../features/jalarchive.html">Jalview Archives</a>.
+</p>
+<p><em>Current Limitations</em></p>
+
+<p>In the current version of Jalview, reordering of the annotation
+rows is not possible. If you save 
+your annotation as a Jalview file, however, it will be reloaded with user 
+annotations at the top (nearest the alignment), above any of the
+automatically generated Conservation, Quality or consensus
+annotations. Finally, the Jalview GUI will not, as yet, allow you to output
+Jalview annotation files for the current alignment, change the line
+colour, display style, or create groups of quantitative annotation rows.</p>
+</body>
+</html>
index 7b9b0d5..c633546 100755 (executable)
@@ -1,28 +1,28 @@
-<html>\r
-<head>\r
-<title>Annotation Panel Menus</title>\r
-</head>\r
-<body>\r
-<p><strong>Annotation Panel Menus</strong></p>\r
-<ul>\r
-  <li> <strong>Annotation Label Popup Menu</strong><br>\r
-    <em>This menu is opened by clicking anywhere on the annotation row labels \r
-    area (below the sequence ID area).</em> \r
-    <ul>\r
-      <li><strong> Add New Row</strong><br>\r
-        <em>Adds a new, named annotation row (a dialog box will pop up for you \r
-        to enter the label for the new row). </em> </li>\r
-      <li><strong>Hide Row</strong><br>\r
-        <em>Hides the annotation row whose label was clicked in order to bring \r
-        up the menu.</em> </li>\r
-      <li><strong>Delete Row</strong><br>\r
-        <em>Deletes the annotation row whose label was clicked in order to bring \r
-        up the menu.</em> </li>\r
-      <li><strong>Show All Hidden Rows</strong><br>\r
+<html>
+<head>
+<title>Annotation Panel Menus</title>
+</head>
+<body>
+<p><strong>Annotation Panel Menus</strong></p>
+<ul>
+  <li> <strong>Annotation Label Popup Menu</strong><br>
+    <em>This menu is opened by clicking anywhere on the annotation row labels 
+    area (below the sequence ID area).</em> 
+    <ul>
+      <li><strong> Add New Row</strong><br>
+        <em>Adds a new, named annotation row (a dialog box will pop up for you 
+        to enter the label for the new row). </em> </li>
+      <li><strong>Hide Row</strong><br>
+        <em>Hides the annotation row whose label was clicked in order to bring 
+        up the menu.</em> </li>
+      <li><strong>Delete Row</strong><br>
+        <em>Deletes the annotation row whose label was clicked in order to bring 
+        up the menu.</em> </li>
+      <li><strong>Show All Hidden Rows</strong><br>
         <em>Shows all hidden annotation rows.</em> </li>
       <li><strong>Export Annotation</strong> <em>(Application only)</em><br>
-       <em>Annotations can be saved to file or output to a text window in the 
-        Jalview annotations format. </em> </li>
+       <em>Annotations can be saved to file or output to a text window in either the 
+        Jalview annotations format or as a spreadsheet style set of comma separated values (CSV). </em> </li>
       <li><strong>Show Values in Text Box</strong> <em>(applet only)</em><br>
         <em>Opens a text box with a list of comma-separated values corresponding 
         to the annotation (numerical or otherwise) at each position in the row. 
       </li>
    </ul>
    <em>The following additional entries are avalable when the popup menu is opened on a consensus sequence annotation row:</em> 
-   <ul>\r
-      <li><strong>Ignore Gaps in Consensus</strong><br>\r
-        If this checkbox is selected, all consensus calculations performed in \r
-        the current Alignment window will be done without counting gaps as a consensus \r
-        character.</li>\r
-      <li><strong>Copy Consensus Sequence</strong><br>\r
-        Copies the consensus sequence to the clipboard in Fasta format, to allow \r
-        the consensus sequence to be added to an alignment. Note the copied sequence \r
-        is not accessible to other programs if Jalview is running as an applet \r
-        in a web page.</li>\r
-    </ul>\r
-  </li>\r
-  <li><strong>Annotation Popup Menu<br>\r
-    </strong><em>This menu is opened when right-clicking on the selected positions \r
-    of an annotation.</em> \r
-    <ul>\r
-      <li><strong>Helix</strong><br>\r
-        <em>Mark selected positions with a helix glyph (a red oval), and optional \r
-        text label (see below). Consecutive ovals will be rendered as an unbroken \r
-        red line.</em> </li>\r
-      <li><strong>Sheet</strong><br>\r
-        <em>Mark selected positions with a sheet glyph (a green arrow oriented \r
-        from left to right), and optional text label (see below). Consecutive \r
-        arrows will be joined together to form a single green arrow.</em> </li>\r
-      <li><strong>Label</strong><br>\r
-        <em>Sets the text label at the selected positions. If more that one consecutive \r
-        position is marked with the same label, only the first position's label \r
-        will be rendered.</em> </li>\r
-      <li><strong>Colour</strong><br>\r
-        <em>Changes the colour of the annotation text label.</em> </li>\r
-      <li><strong>Remove Annotation</strong><br>\r
-        <em>Blanks any annotation at the selected positions on the row. Note: \r
-        <strong>This cannot be undone</strong></em> </li>\r
-    </ul>\r
-  </li>\r
-</ul>\r
-</body>\r
-</html>\r
+   <ul>
+      <li><strong>Ignore Gaps in Consensus</strong><br>
+        If this checkbox is selected, all consensus calculations performed in 
+        the current Alignment window will be done without counting gaps as a consensus 
+        character.</li>
+      <li><strong>Copy Consensus Sequence</strong><br>
+        Copies the consensus sequence to the clipboard in Fasta format, to allow 
+        the consensus sequence to be added to an alignment. Note the copied sequence 
+        is not accessible to other programs if Jalview is running as an applet 
+        in a web page.</li>
+    </ul>
+  </li>
+  <li><strong>Annotation Popup Menu<br>
+    </strong><em>This menu is opened when right-clicking on the selected positions 
+    of an annotation.</em> 
+    <ul>
+      <li><strong>Helix</strong><br>
+        <em>Mark selected positions with a helix glyph (a red oval), and optional 
+        text label (see below). Consecutive ovals will be rendered as an unbroken 
+        red line.</em> </li>
+      <li><strong>Sheet</strong><br>
+        <em>Mark selected positions with a sheet glyph (a green arrow oriented 
+        from left to right), and optional text label (see below). Consecutive 
+        arrows will be joined together to form a single green arrow.</em> </li>
+      <li><strong>Label</strong><br>
+        <em>Sets the text label at the selected positions. If more that one consecutive 
+        position is marked with the same label, only the first position's label 
+        will be rendered.</em> </li>
+      <li><strong>Colour</strong><br>
+        <em>Changes the colour of the annotation text label.</em> </li>
+      <li><strong>Remove Annotation</strong><br>
+        <em>Blanks any annotation at the selected positions on the row. Note: 
+        <strong>This cannot be undone</strong></em> </li>
+    </ul>
+  </li>
+</ul>
+</body>
+</html>
index 41689c5..ab3f0d1 100755 (executable)
@@ -28,6 +28,13 @@ import javax.swing.*;
 import jalview.datamodel.*;\r
 import jalview.io.*;\r
 \r
+/**\r
+ * \r
+ * GUI dialog for exporting features or alignment annotations depending upon which method is called.\r
+ * \r
+ * @author AMW\r
+ *\r
+ */\r
 public class AnnotationExporter\r
     extends JPanel\r
 {\r
@@ -61,6 +68,7 @@ public class AnnotationExporter
   {\r
     this.ap = ap;\r
     features = true;\r
+    CSVFormat.setVisible(false);\r
     frame.setTitle("Export Features");\r
   }\r
 \r
@@ -72,6 +80,7 @@ public class AnnotationExporter
     this.ap = ap;\r
     features = false;\r
     GFFFormat.setVisible(false);\r
+    CSVFormat.setVisible(true);\r
     this.annotations = annotations;\r
     this.sequenceGroups = sequenceGroups;\r
     this.alignmentProperties = alProperties;\r
@@ -110,10 +119,15 @@ public class AnnotationExporter
       }\r
       else\r
       {\r
-        text = new AnnotationFile().printAnnotations(\r
+        if (CSVFormat.isSelected())\r
+        {\r
+          text = new AnnotationFile().printCSVAnnotations(annotations);\r
+        } else {\r
+          text = new AnnotationFile().printAnnotations(\r
             annotations,\r
             sequenceGroups,\r
             alignmentProperties);\r
+        }\r
       }\r
 \r
       try\r
@@ -153,10 +167,15 @@ public class AnnotationExporter
     }\r
     else if (!features)\r
     {\r
-      text = new AnnotationFile().printAnnotations(\r
+      if (CSVFormat.isSelected())\r
+      {\r
+        text = new AnnotationFile().printCSVAnnotations(annotations);\r
+      } else {\r
+        text = new AnnotationFile().printAnnotations(\r
           annotations,\r
           sequenceGroups,\r
           alignmentProperties);\r
+      }\r
     }\r
 \r
     CutAndPasteTransfer cap = new CutAndPasteTransfer();\r
@@ -214,6 +233,8 @@ public class AnnotationExporter
     jalviewFormat.setText("Jalview");\r
     GFFFormat.setOpaque(false);\r
     GFFFormat.setText("GFF");\r
+    CSVFormat.setOpaque(false);\r
+    CSVFormat.setText("CSV(Spreadsheet)");\r
     jLabel1.setHorizontalAlignment(SwingConstants.TRAILING);\r
     jLabel1.setText("Format: ");\r
     this.setBackground(Color.white);\r
@@ -226,8 +247,10 @@ public class AnnotationExporter
     jPanel3.add(jLabel1);\r
     jPanel3.add(jalviewFormat);\r
     jPanel3.add(GFFFormat);\r
+    jPanel3.add(CSVFormat);\r
     buttonGroup.add(jalviewFormat);\r
     buttonGroup.add(GFFFormat);\r
+    buttonGroup.add(CSVFormat);\r
     this.add(jPanel3, null);\r
     this.add(jPanel1, null);\r
   }\r
@@ -239,6 +262,7 @@ public class AnnotationExporter
   ButtonGroup buttonGroup = new ButtonGroup();\r
   JRadioButton jalviewFormat = new JRadioButton();\r
   JRadioButton GFFFormat = new JRadioButton();\r
+  JRadioButton CSVFormat = new JRadioButton();\r
   JLabel jLabel1 = new JLabel();\r
   JPanel jPanel3 = new JPanel();\r
   FlowLayout flowLayout1 = new FlowLayout();\r
index 4acd2a1..577b7e4 100755 (executable)
@@ -882,4 +882,33 @@ public class AnnotationFile
       al.setProperty(key,value);\r
     }\r
   }\r
+\r
+  /**\r
+   * Write annotations as a CSV file of the form 'label, value, value, ...' for each row.\r
+   * @param annotations\r
+   * @return CSV file as a string.\r
+   */\r
+  public String printCSVAnnotations(AlignmentAnnotation[] annotations)\r
+  {\r
+    StringBuffer sp = new StringBuffer();\r
+    for (int i=0; i<annotations.length; i++)\r
+    {\r
+      String atos = annotations[i].toString();\r
+      int p = 0;\r
+      do {\r
+        int cp = atos.indexOf("\n", p);\r
+        sp.append(annotations[i].label);\r
+        sp.append(",");\r
+        if (cp>p)\r
+        {\r
+          sp.append(atos.substring(p, cp+1));\r
+        } else {\r
+          sp.append(atos.substring(p));\r
+          sp.append("\n");\r
+        }\r
+        p = cp+1;\r
+      } while (p>0);\r
+    }\r
+    return sp.toString();\r
+  }\r
 }\r