JAL-1628 tweak signature of core annotation printer for outputting hidden columns...
authorJim Procter <jprocter@dundee.ac.uk>
Fri, 23 Jan 2015 13:14:58 +0000 (13:14 +0000)
committerJim Procter <jprocter@dundee.ac.uk>
Fri, 23 Jan 2015 13:14:58 +0000 (13:14 +0000)
help/html/features/annotationsFormat.html
src/jalview/io/AnnotationFile.java
test/jalview/io/AnnotationFileIOTest.java

index 90dfd9b..72691ce 100755 (executable)
@@ -60,7 +60,7 @@ ignored. The sections below describe the structure of an annotation file.
 <li><a href="#groupdefs">SEQUENCE_GROUP</a> to define groups of sequences for further annotation</li>
 <li><a href="#groupprops">PROPERTIES</a> to set visualisation properties for sequence groups</li>
 <li><a href="#seqgrprefs">SEQUENCE_REF and GROUP_REF</a> for attaching annotation to sequences and groups</li>
 <li><a href="#groupdefs">SEQUENCE_GROUP</a> to define groups of sequences for further annotation</li>
 <li><a href="#groupprops">PROPERTIES</a> to set visualisation properties for sequence groups</li>
 <li><a href="#seqgrprefs">SEQUENCE_REF and GROUP_REF</a> for attaching annotation to sequences and groups</li>
-               <li><a href="#refsandviews">VIEW_SETREF and HIDE_INSERTIONS</a>
+               <li><a href="#refsandviews">VIEW_SETREF, VIEW_HIDECOLS and HIDE_INSERTIONS</a>
                        for defining a reference sequence on the alignment and hiding regions
                        based on gaps in a reference sequence</li>
        </ul>
                        for defining a reference sequence on the alignment and hiding regions
                        based on gaps in a reference sequence</li>
        </ul>
@@ -168,7 +168,7 @@ of sequence IDs. </p>
 <tr><td width="50%">idColour</td><td>Colour for highlighting the Sequence ID labels for this group<br/>If <em>idColour</em> is given but <em>colour</em> is not, then idColor will also be used for the group background colour.</td></tr>
 <tr><td width="50%">showunconserved</td><td>Boolean (default false) indicating whether residues should only be shown that are different from current reference or consensus sequence</td></tr>
 <tr><td width="50%">hide</td><td>Boolean (default false) indicating whether the rows in this group should be marked as hidden.<br/><em>Note:</em> if the group is sequence associated (specified by SEQUENCE_REF), then all members will be hidden and marked as represented by the reference sequence.</td></tr>
 <tr><td width="50%">idColour</td><td>Colour for highlighting the Sequence ID labels for this group<br/>If <em>idColour</em> is given but <em>colour</em> is not, then idColor will also be used for the group background colour.</td></tr>
 <tr><td width="50%">showunconserved</td><td>Boolean (default false) indicating whether residues should only be shown that are different from current reference or consensus sequence</td></tr>
 <tr><td width="50%">hide</td><td>Boolean (default false) indicating whether the rows in this group should be marked as hidden.<br/><em>Note:</em> if the group is sequence associated (specified by SEQUENCE_REF), then all members will be hidden and marked as represented by the reference sequence.</td></tr>
-<tr><td width="50%">hidecols</td><td>Boolean (default false) indicating whether columns in this groushould be marked as hidden</td></tr></tbody>
+<!-- <tr><td width="50%">hidecols</td><td>Boolean (default false) indicating whether columns in this groushould be marked as hidden</td></tr> --></tbody>
 </table>
 
 <p><strong>Specifying colours in PROPERTIES key-value pairs</strong><br/>
 </table>
 
 <p><strong>Specifying colours in PROPERTIES key-value pairs</strong><br/>
@@ -206,7 +206,7 @@ Group association is turned off for subsequent annotation rows by:
 <pre>GROUP_REF&#9;<em>ALIGNMENT</em></pre>
 </p>
 <hr/>
 <pre>GROUP_REF&#9;<em>ALIGNMENT</em></pre>
 </p>
 <hr/>
-<p><strong><a name="refsandviews">VIEW_SETREF, and HIDE_INSERTIONS</a></strong><br/>
+<p><strong><a name="refsandviews">VIEW_SETREF, VIEW_HIDECOL and HIDE_INSERTIONS</a></strong><br/>
 Since Jalview 2.9, the Annotations file has also supported the definition of views on the alignment, and definition of hidden regions.</p>
 <!--   <p>
                <em>VIEW_DEF</em> allows the current view to be named according to the
 Since Jalview 2.9, the Annotations file has also supported the definition of views on the alignment, and definition of hidden regions.</p>
 <!--   <p>
                <em>VIEW_DEF</em> allows the current view to be named according to the
@@ -220,6 +220,12 @@ Since Jalview 2.9, the Annotations file has also supported the definition of vie
                corresponding sequence as the <a href="../features/refsequence.html">reference
                        sequence</a> for the alignment.
        </p>
                corresponding sequence as the <a href="../features/refsequence.html">reference
                        sequence</a> for the alignment.
        </p>
+       <em>VIEW_HIDECOLS</em> takes either a single argument consisting of a
+       comma separated series of integer pairs like
+       <em>3-4</em>. These integer pairs define columns (starting from the
+       left-hand column 0) that should be marked as hidden in the alignment
+       view.
+       </p>
        <p>
                <em>HIDE_INSERTIONS</em> takes a either a single sequence ID or a
                numeric index, or no arguments. This command marks all gapped
        <p>
                <em>HIDE_INSERTIONS</em> takes a either a single sequence ID or a
                numeric index, or no arguments. This command marks all gapped
index 6834e76..8dc84b8 100755 (executable)
@@ -99,7 +99,7 @@ public class AnnotationFile
   public String printAnnotations(AlignmentAnnotation[] annotations,
           List<SequenceGroup> list, Hashtable properties)
   {
   public String printAnnotations(AlignmentAnnotation[] annotations,
           List<SequenceGroup> list, Hashtable properties)
   {
-    return printAnnotations(annotations, list, properties, null);
+    return printAnnotations(annotations, list, properties, null, null, null);
 
   }
 
 
   }
 
@@ -140,16 +140,56 @@ public class AnnotationFile
    * @return annotation file
    */
   public String printAnnotations(AlignmentAnnotation[] annotations,
    * @return annotation file
    */
   public String printAnnotations(AlignmentAnnotation[] annotations,
-          List<SequenceGroup> list, Hashtable properties, ViewDef[] views)
+          List<SequenceGroup> list, Hashtable properties,
+          ColumnSelection cs, AlignmentI al, ViewDef view)
   {
   {
-    // TODO: resolve views issue : annotationFile could contain visible region,
-    // or full data + hidden region specifications for a view.
-    if (views != null)
+    if (view != null)
     {
     {
-      // are views defined and then annotation added to alignment or the other
-      // way around ?
-
+      if (view.viewname != null)
+      {
+        text.append("VIEW_DEF\t" + view.viewname + "\n");
+      }
+      if (list == null)
+      {
+        list = view.visibleGroups;
+      }
+      if (cs == null)
+      {
+        cs = view.hiddencols;
+      }
+      if (al == null)
+      {
+        // add hidden rep sequences.
+      }
+    }
+    // first target - store and restore all settings for a view.
+    if (al != null && al.hasSeqrep())
+    {
+      text.append("VIEW_SETREF\t" + al.getSeqrep().getName() + "\n");
     }
     }
+    if (cs != null && cs.hasHiddenColumns())
+    {
+      text.append("VIEW_HIDECOLS\t");
+      List<int[]> hc = cs.getHiddenColumns();
+      boolean comma = false;
+      for (int[] r : hc)
+      {
+        if (!comma)
+        {
+          comma = true;
+        }
+        else
+        {
+          text.append(",");
+        }
+        text.append(r[0]);
+        text.append("-");
+        text.append(r[1]);
+      }
+      text.append("\n");
+    }
+    // TODO: allow efficient recovery of annotation data shown in several
+    // different views
     if (annotations != null)
     {
       boolean oneColour = true;
     if (annotations != null)
     {
       boolean oneColour = true;
@@ -432,7 +472,8 @@ public class AnnotationFile
         text.append(properties.get(key));
       }
       // TODO: output alignment visualization settings here if required
         text.append(properties.get(key));
       }
       // TODO: output alignment visualization settings here if required
-
+      // iterate through one or more views, defining, marking columns and rows as visible/hidden, and emmitting view properties.
+      // View specific annotation is 
     }
 
     return text.toString();
     }
 
     return text.toString();
@@ -888,6 +929,12 @@ public class AnnotationFile
           modified = true;
           continue;
         }
           modified = true;
           continue;
         }
+        // else if (token.equalsIgnoreCase("VIEW_DEF"))
+        // {
+        // addOrSetView(al,st);
+        // modified = true;
+        // continue;
+        // }
         else if (token.equalsIgnoreCase("VIEW_SETREF"))
         {
           if (refSeq != null)
         else if (token.equalsIgnoreCase("VIEW_SETREF"))
         {
           if (refSeq != null)
@@ -897,6 +944,19 @@ public class AnnotationFile
           modified = true;
           continue;
         }
           modified = true;
           continue;
         }
+        else if (token.equalsIgnoreCase("VIEW_HIDECOLS"))
+        {
+          if (st.hasMoreTokens())
+          {
+            if (colSel == null)
+            {
+              colSel = new ColumnSelection();
+            }
+            parseHideCols(colSel, st.nextToken());
+          }
+          modified = true;
+          continue;
+        }
         else if (token.equalsIgnoreCase("HIDE_INSERTIONS"))
         {
           SequenceI sr = refSeq == null ? al.getSeqrep() : refSeq;
         else if (token.equalsIgnoreCase("HIDE_INSERTIONS"))
         {
           SequenceI sr = refSeq == null ? al.getSeqrep() : refSeq;
@@ -1121,6 +1181,40 @@ public class AnnotationFile
     return modified;
   }
 
     return modified;
   }
 
+  private void parseHideCols(ColumnSelection colSel, String nextToken)
+  {
+    StringTokenizer inval = new StringTokenizer(nextToken,",");
+    while (inval.hasMoreTokens())
+    {
+      String range = inval.nextToken().trim();
+      int from, to = range.indexOf("-");
+      if (to == -1)
+      {
+        from = to = Integer.parseInt(range);
+        if (from >= 0)
+        {
+          colSel.hideColumns(from, to);
+        }
+      }
+      else
+      {
+        from = Integer.parseInt(range.substring(0, to));
+        if (to < range.length() - 1)
+        {
+          to = Integer.parseInt(range.substring(to + 1));
+        }
+        else
+        {
+          to = from;
+        }
+        if (from > 0 && to >= from)
+        {
+          colSel.hideColumns(from, to);
+        }
+      }
+    }
+  }
+
   private Object autoAnnotsKey(AlignmentAnnotation annotation,
           SequenceI refSeq, String groupRef)
   {
   private Object autoAnnotsKey(AlignmentAnnotation annotation,
           SequenceI refSeq, String groupRef)
   {
@@ -1697,12 +1791,13 @@ public class AnnotationFile
     return printAnnotations(viewport.isShowAnnotation() ? viewport
             .getAlignment().getAlignmentAnnotation() : null, viewport
             .getAlignment().getGroups(), viewport.getAlignment()
     return printAnnotations(viewport.isShowAnnotation() ? viewport
             .getAlignment().getAlignmentAnnotation() : null, viewport
             .getAlignment().getGroups(), viewport.getAlignment()
-            .getProperties());
+            .getProperties(), viewport.getColumnSelection(),
+            viewport.getAlignment(), null);
   }
 
   public String printAnnotationsForAlignment(AlignmentI al)
   {
     return printAnnotations(al.getAlignmentAnnotation(), al.getGroups(),
   }
 
   public String printAnnotationsForAlignment(AlignmentI al)
   {
     return printAnnotations(al.getAlignmentAnnotation(), al.getGroups(),
-            al.getProperties());
+            al.getProperties(), null, al, null);
   }
 }
   }
 }
index 3d4e841..56e6cda 100644 (file)
@@ -115,13 +115,12 @@ public class AnnotationFileIOTest
               new AnnotationFile().readAnnotationFile(al, cs, af,
                       FormatAdapter.FILE));
 
               new AnnotationFile().readAnnotationFile(al, cs, af,
                       FormatAdapter.FILE));
 
-      ViewDef[] v = new ViewDef[1];
       AnnotationFile aff = new AnnotationFile();
       AnnotationFile aff = new AnnotationFile();
-      v[0] = aff.new ViewDef(null, al.getHiddenSequences(), cs,
+      ViewDef v = aff.new ViewDef(null, al.getHiddenSequences(), cs,
               new Hashtable());
       String anfileout = new AnnotationFile().printAnnotations(
               al.getAlignmentAnnotation(), al.getGroups(),
               new Hashtable());
       String anfileout = new AnnotationFile().printAnnotations(
               al.getAlignmentAnnotation(), al.getGroups(),
-              al.getProperties(), v);
+              al.getProperties(), null, al, v);
       assertTrue(
               "Test "
                       + testname
       assertTrue(
               "Test "
                       + testname