added colour by label to feature type colourspec and gff statement to allow mixed...
authorjprocter <Jim Procter>
Wed, 15 Sep 2010 14:03:03 +0000 (14:03 +0000)
committerjprocter <Jim Procter>
Wed, 15 Sep 2010 14:03:03 +0000 (14:03 +0000)
help/html/features/featuresFormat.html
src/jalview/io/FeaturesFile.java

index 93ce408..faf2340 100755 (executable)
@@ -1,3 +1,4 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
 <html>
 <!--
  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
 -->
 <head>
+<meta name="generator" content="HTML Tidy, see www.w3.org">
 <title>Sequence Features File</title>
 </head>
-
 <body>
-<p><strong>Sequence Features File</strong></p>
-<p>The Sequence features file (which used to be known as the
-&quot;Groups file&quot; prior to version 2.08) is a simple way of
-getting your own sequence annotations into Jalview. It was introduced to
-allow sequence features to be rendered in the Jalview applet, and so is
-intentionally lightweight and minimal because the applet is often used
-in situations where data file size must be kept to a minimum, and no XML
-parser is available.</p>
-<p>Features files are imported into Jalview in the following ways:<br>
+<p><strong>Sequence Features File</strong><p>
+<p>
+The Sequence features file (which used to be known as the
+"Groups file" prior to version 2.08) is a simple way of getting
+your own sequence annotations into Jalview. It was introduced to
+allow sequence features to be rendered in the Jalview applet, and
+so is intentionally lightweight and minimal because the applet is
+often used in situations where data file size must be kept to a
+minimum, and no XML parser is available.</p>
+
+<p>Features files are imported into Jalview in the following
+ways:<br>
+
 <ul>
-       <li>from the command line<strong><pre>
- -features &lt;<em>Features filename</em>&gt;</pre></strong></li>
-       <li>Dragging a features file onto an alignment window</li>
-       <li>Via the &quot;Load Features / Annotations&quot; entry in the <strong>File</strong>
-       menu of an alignment window.</li>
+<li>from the command line
+
+<pre>
+<strong> -features &lt;<em>Features filename</em>&gt;</strong>
+</pre>
+</li>
+
+<li>Dragging a features file onto an alignment window</li>
+
+<li>Via the &quot;Load Features / Annotations&quot; entry in the
+<strong>File</strong> menu of an alignment window.</li>
 </ul>
+
 </p>
+
 <p><strong>Sequence Features File Format</strong></p>
-<p>A features file is a simple ASCII text file, where each line
+<p>
+A features file is a simple ASCII text file, where each line
 contains tab separated text fields. <strong>No comments are
 allowed</strong>.</p>
-<p>The first set of lines contain type definitions:<strong>
-<pre><em>Feature label</em>&#9;<em>Feature Colour</em><!-- &#9<em>Feature links</em>  --></pre> </strong>A feature
-type has a text label, and a colour specification. This can be either:
+<p>
+The first set of lines contain type definitions:
+
+<pre>
+<strong><em>Feature label</em>&#9;<em>Feature Colour</em>
+<!-- &#9;<em>Feature links</em>  --></strong>
+</pre>
+
+A feature type has a text label, and a colour specification. This
+can be either: 
+
+<ul>
+<li>A single colour specified as either a red,green,blue 24 bit
+triplet in hexadecimal (eg. 00ff00) or as comma separated numbers
+(ranging from 0 to 255))</li>
+
+<li>A <a href="featureschemes.html">graduated colourscheme</a>
+specified as a "|" separated list of fields:
+
+<pre>
+[label|]&lt;mincolor&gt;|&lt;maxcolor&gt;|[absolute|]&lt;minvalue&gt;|&lt;maxvalue&gt;[|&lt;thresholdtype&gt;|[&lt;threshold value&gt;]]
+</pre>
+
+The fields are as follows:
+
 <ul>
-       <li>A single colour specified as either a red,green,blue 24 bit
-       triplet in hexadecimal (eg. 00ff00) or as comma separated numbers
-       (ranging from 0 to 255))</li>
-       <li>A <a href="featureschemes.html">graduated colourscheme</a> specified as a &quot;|&quot; separated list
-       of fields:<pre>
-&lt;mincolor&gt;|&lt;maxcolor&gt;|[absolute|]&lt;minvalue&gt;|&lt;maxvalue&gt;[|&lt;thresholdtype&gt;|[&lt;threshold value&gt;]]
-</pre>The fields are as follows
-       <ul>
-               <li><em>mincolor</em> and <em>maxcolor</em><br>
-               Colour triplets specified as hexadecimal or comma separated values</li>
-               <li><em>absolute</em><br>
-               An optional switch indicating that the <em>minvalue</em> and <em>maxvalue</em>
-               parameters should be left as is, rather than rescaled according to the
-               range of scores for this feature type.
-               <li><em>minvalue</em> and <em>maxvalue</em><br>
-               Minimum and maximum values defining the range of scores for which the colour range will be defined over. If minvalue is greater than maxvalue then the linear mapping will have negative gradient.
-               </li>
-               <li><em>thresholdtype</em> <br>
-               Either &quot;none&quot;, &quot;below&quot;, or &quot;above&quot;. <em>below</em>
-               and <em>above</em> require an additional <em>threshold value</em>
-               which is used to control the display of features with a score either
-               below or above the value.</li>
-       </ul>
-       </li>
+<li><em>label</em><br>
+ Indicate that the feature description should be used to create a
+colour for features of this type.<br>
+<em>Note: if no threshold value is needed then the final '|' may be
+ommitted.<br>
+This keyword was added in Jalview 2.6</em></li>
+
+<li><em>mincolor</em> and <em>maxcolor</em><br>
+ Colour triplets specified as hexadecimal or comma separated values
+(may be left blank for a <em>label</em> style colourscheme, but
+remember to specify the remaining fields)</li>
+
+<li><em>absolute</em><br>
+ An optional switch indicating that the <em>minvalue</em> and
+<em>maxvalue</em> parameters should be left as is, rather than
+rescaled according to the range of scores for this feature
+type.</li>
+
+<li><em>minvalue</em> and <em>maxvalue</em><br>
+ Minimum and maximum values defining the range of scores for which
+the colour range will be defined over. If minvalue is greater than
+maxvalue then the linear mapping will have negative gradient.</li>
+
+<li><em>thresholdtype</em><br>
+ Either &quot;none&quot;, &quot;below&quot;, or &quot;above&quot;. <em>below</em> and
+<em>above</em> require an additional <em>threshold value</em> which
+is used to control the display of features with a score either
+below or above the value.</li>
+</ul>
+</li>
 </ul>
 </p>
+
 <p>The remaining lines in the file are the sequence annotation
-definitions, where the now defined features are attached to regions on
-particular sequences, optionally with some descriptive text (displayed
-in a tooltip when the mouse is near the feature on that sequence). There
-are two alternate ways of referring to a sequence, either by its text
-ID, or its index in an associated alignment.
+definitions, where the now defined features are attached to regions
+on particular sequences. Each feature can optionally include some descriptive text
+which is displayed in a tooltip when the mouse is near the feature on that
+sequence (and can also be used to generate a colour the feature).</p>
+
+<p>If your sequence annotation is already available in GFF Format (see <a href="http://www.sanger.ac.uk/resources/software/gff/spec.html">http://www.sanger.ac.uk/resources/software/gff/spec.html</a>),
+then you can leave it as is, after first adding a line containing
+only 'GFF' after any Jalview feature colour definitions (<em>this mixed format capability was added in Jalview 2.6</em>). Alternately, you can use Jalview's own sequence feature
+annotation format, which additionally allows HTML and URLs to be
+directly attached to each piece of annotation.</p>
+
+<p><strong>Jalview's sequence feature annotation format</strong></p>
+<p>
+Each feature is specified as a tab-separated series of columns as defined below:
 <pre>
-<em>description</em>&#9;<em>sequenceId</em>&#9;<em>sequenceIndex</em>&#9;<em>start</em>&#9;<em>end</em>&#9;<em>featureType</em>&#9;<em>score (optional)</em></pre>
-Normally, sequence features are associated with sequences rather than
-alignments, and the sequenceIndex field is given as &quot;-1&quot;. In
-order to specify a sequence by its index in a particular alignment, the
-sequenceId should be given as &quot;ID_NOT_SPECIFIED&quot;, otherwise
-the sequenceId field will be used in preference to the sequenceIndex
+<em>description</em>&#9;<em>sequenceId</em>&#9;<em>sequenceIndex</em>&#9;<em>start</em>&#9;<em>end</em>&#9;<em>featureType</em>&#9;<em>score (optional)</em>
+</pre>
+
+This format allows two alternate ways of referring to a sequence, either by
+its text ID, or its index in an associated alignment. Normally, sequence features are associated with sequences rather
+than alignments, and the sequenceIndex field is given as &quot;-1&quot;. In
+order to specify a sequence by its index in a particular alignment,
+the sequenceId should be given as &quot;ID_NOT_SPECIFIED&quot;, otherwise the
+sequenceId field will be used in preference to the sequenceIndex
 field.
 </p>
+
 <p>The description may contain simple HTML document body tags if
-enclosed by &quot;&lt;html&gt;&lt;/html&gt;&quot; and these will be
-rendered as formatted tooltips in the Jalview Application (the Jalview
-applet is not capable of rendering HTML tooltips, so all formatting tags
-will be removed).<br>
-<em>Attaching Links to Sequence Features</em> <br>
-Any anchor tags in an html formatted description line will be translated
-into URL links. A link symbol will be displayed adjacent to any feature
-which includes links, and these are made available from the <a
-       href="../menus/popupMenu.html#sqid.popup">links submenu</a> of the
-popup menu which is obtained by right-clicking when a link symbol is
-displayed in the tooltip.<br>
+enclosed by &quot;&lt;html&gt;&lt;/html&gt;&quot; and these will be rendered
+as formatted tooltips in the Jalview Application (the Jalview
+applet is not capable of rendering HTML tooltips, so all formatting
+tags will be removed).<br>
+<em>Attaching Links to Sequence Features</em><br>
+Any anchor tags in an html formatted description line will be
+translated into URL links. A link symbol will be displayed adjacent
+to any feature which includes links, and these are made available
+from the <a href="../menus/popupMenu.html#sqid.popup">links
+submenu</a> of the popup menu which is obtained by right-clicking
+when a link symbol is displayed in the tooltip.<br>
 <em>Non-positional features</em><br>
-Specify the <em>start</em> and <em>end</em> for a feature to be <strong>0</strong>
-in order to attach it to the whole sequence. Non-positional features are
-shown in a tooltip when the mouse hovers over the sequence ID panel, and
-any embedded links can be accessed from the popup menu.
-<em>Scores</em><br>
-Scores can be associated with sequence features, and used to sort sequences or shade the alignment (this was added in jalview 2.5). The score field is optional, and malformed scores will be ignored.
-</p>
+Specify the <em>start</em> and <em>end</em> for a feature to be
+<strong>0</strong> in order to attach it to the whole sequence.
+Non-positional features are shown in a tooltip when the mouse
+hovers over the sequence ID panel, and any embedded links can be
+accessed from the popup menu. <em>Scores</em><br>
+Scores can be associated with sequence features, and used to sort
+sequences or shade the alignment (this was added in jalview 2.5).
+The score field is optional, and malformed scores will be
+ignored.</p>
+
 <p>Feature annotations can be collected into named groups by
-prefixing definitions with lines of the form:<strong><pre>startgroup&#9;groupname</pre></strong>..
-and subsequently post-fixing the group with:<strong><pre>endgroup&#9;groupname</pre></strong>Feature
-grouping was introduced in version 2.08, and used to control whether a
-set of features are either hidden or shown together in the <a
-       href="seqfeatures.html">sequence Feature settings dialog box</a>.</p>
+prefixing definitions with lines of the form:
+
+<pre>
+<strong>startgroup     groupname</strong>
+</pre>
+
+.. and subsequently post-fixing the group with:
+
+<pre>
+<strong>endgroup       groupname</strong>
+</pre>
+
+Feature grouping was introduced in version 2.08, and used to
+control whether a set of features are either hidden or shown
+together in the <a href="seqfeatures.html">sequence Feature
+settings dialog box</a>.</p>
+
 <p>A complete example is shown below :
 <pre>
 domain&#9;red
@@ -135,8 +208,9 @@ startgroup&#9;secondarystucture
 PDB secondary structure annotation&#9;FER1_SPIOL&#9;-1&#9;52&#9;59&#9;strand
 PDB secondary structure annotation&#9;FER1_SPIOL&#9;-1&#9;74&#9;80&#9;helix
 endgroup&#9;secondarystructure
+GFF
+FER_CAPAA&#9;GffGroup&#9;domain&#9;3&#9;93&#9;.&#9;.
 </pre>
-</li>
-</p>
 </body>
 </html>
+
index 8f5e4bd..ccf7b30 100755 (executable)
@@ -104,9 +104,10 @@ public class FeaturesFile extends AlignFile
       SequenceFeature sf;\r
       String featureGroup = null, groupLink = null;\r
       Hashtable typeLink = new Hashtable();\r
-\r
+      /**\r
+       * when true, assume GFF style features rather than Jalview style.\r
+       */\r
       boolean GFFFile = true;\r
-\r
       while ((line = nextLine()) != null)\r
       {\r
         if (line.startsWith("#"))\r
@@ -115,6 +116,15 @@ public class FeaturesFile extends AlignFile
         }\r
 \r
         st = new StringTokenizer(line, "\t");\r
+        if (st.countTokens() == 1)\r
+        {\r
+          if (line.trim().equalsIgnoreCase("GFF"))\r
+          {\r
+            // Start parsing file as if it might be GFF again.\r
+            GFFFile = true;\r
+            continue;\r
+          }\r
+        }\r
         if (st.countTokens() > 1 && st.countTokens() < 4)\r
         {\r
           GFFFile = false;\r
@@ -140,58 +150,109 @@ public class FeaturesFile extends AlignFile
           {\r
             Object colour = null;\r
             String colscheme = st.nextToken();\r
-            if (colscheme.indexOf("|") > -1)\r
+            if (colscheme.indexOf("|") > -1\r
+                    || colscheme.trim().equalsIgnoreCase("label"))\r
             {\r
               // Parse '|' separated graduated colourscheme fields:\r
-              // mincolour|maxcolour|[absolute|]minvalue|maxvalue|thresholdtype|thresholdvalue\r
-              // first four are required.\r
-              // first two are hexadecimal or word equivalent colours.\r
-              // second two are values parsed as floats.\r
+              // [label|][mincolour|maxcolour|[absolute|]minvalue|maxvalue|thresholdtype|thresholdvalue]\r
+              // can either provide 'label' only, first is optional, next two\r
+              // colors are required (but may be\r
+              // left blank), next is optional, nxt two min/max are required.\r
+              // first is either 'label'\r
+              // first/second and third are both hexadecimal or word equivalent\r
+              // colour.\r
+              // next two are values parsed as floats.\r
               // fifth is either 'above','below', or 'none'.\r
               // sixth is a float value and only required when fifth is either\r
               // 'above' or 'below'.\r
-              StringTokenizer gcol = new StringTokenizer(colscheme, "|");\r
-              String mincol = gcol.nextToken(), maxcol = gcol.nextToken();\r
-              String abso = gcol.nextToken(), minval, maxval;\r
-              if (abso.toLowerCase().indexOf("abso") != 0)\r
-              {\r
-                minval = abso;\r
-                abso = null;\r
-              }\r
-              else\r
-              {\r
-                minval = gcol.nextToken();\r
-              }\r
-              maxval = gcol.nextToken();\r
+              StringTokenizer gcol = new StringTokenizer(colscheme, "|", true);\r
               // set defaults\r
               int threshtype = AnnotationColourGradient.NO_THRESHOLD;\r
               float min = Float.MIN_VALUE, max = Float.MAX_VALUE, threshval = Float.NaN;\r
-              try\r
-              {\r
-                if (minval.length() > 0)\r
-                {\r
-                  min = new Float(minval).floatValue();\r
-                }\r
-              } catch (Exception e)\r
+              boolean labelCol = false;\r
+              // Parse spec line\r
+              String mincol = gcol.nextToken();\r
+              if (mincol=="|")\r
               {\r
                 System.err\r
-                        .println("Couldn't parse the minimum value for graduated colour for type ("\r
-                                + colscheme\r
-                                + ") - did you misspell 'auto' for the optional automatic colour switch ?");\r
-                e.printStackTrace();\r
+                .println("Expected either 'label' or a colour specification in the line: "+line );\r
+                continue;\r
               }\r
-              try\r
+              String maxcol = null;\r
+              if (mincol.toLowerCase().indexOf("label") == 0)\r
+              {\r
+                labelCol = true;\r
+                mincol = (gcol.hasMoreTokens() ? gcol.nextToken() : null); // skip '|'\r
+                mincol = (gcol.hasMoreTokens() ? gcol.nextToken() : null);\r
+              }\r
+              String abso = null, minval, maxval;\r
+              if (mincol != null)\r
               {\r
-                if (maxval.length() > 0)\r
+                // at least four more tokens\r
+                if (mincol.equals("|"))\r
                 {\r
-                  max = new Float(maxval).floatValue();\r
+                  mincol="";\r
+                } else {\r
+                  gcol.nextToken(); // skip next '|'\r
                 }\r
-              } catch (Exception e)\r
+                // continue parsing rest of line\r
+                maxcol = gcol.nextToken();\r
+                if (maxcol.equals("|"))\r
+                {\r
+                  maxcol="";\r
+                } else {\r
+                  gcol.nextToken(); // skip next '|'\r
+                }\r
+                abso = gcol.nextToken();\r
+                gcol.nextToken(); // skip next '|'\r
+                if (abso.toLowerCase().indexOf("abso") != 0)\r
+                {\r
+                  minval = abso;\r
+                  abso = null;\r
+                }\r
+                else\r
+                {\r
+                  minval = gcol.nextToken();\r
+                  gcol.nextToken(); // skip next '|'\r
+                }\r
+                maxval = gcol.nextToken();\r
+                if (gcol.hasMoreTokens()) {\r
+                  gcol.nextToken(); // skip next '|'\r
+                }\r
+                try\r
+                {\r
+                  if (minval.length() > 0)\r
+                  {\r
+                    min = new Float(minval).floatValue();\r
+                  }\r
+                } catch (Exception e)\r
+                {\r
+                  System.err\r
+                          .println("Couldn't parse the minimum value for graduated colour for type ("\r
+                                  + colscheme\r
+                                  + ") - did you misspell 'auto' for the optional automatic colour switch ?");\r
+                  e.printStackTrace();\r
+                }\r
+                try\r
+                {\r
+                  if (maxval.length() > 0)\r
+                  {\r
+                    max = new Float(maxval).floatValue();\r
+                  }\r
+                } catch (Exception e)\r
+                {\r
+                  System.err\r
+                          .println("Couldn't parse the maximum value for graduated colour for type ("\r
+                                  + colscheme + ")");\r
+                  e.printStackTrace();\r
+                }\r
+              }\r
+              else\r
               {\r
-                System.err\r
-                        .println("Couldn't parse the maximum value for graduated colour for type ("\r
-                                + colscheme + ")");\r
-                e.printStackTrace();\r
+                // add in some dummy min/max colours for the label-only\r
+                // colourscheme.\r
+                mincol = "FFFFFF";\r
+                maxcol = "000000";\r
               }\r
               try\r
               {\r
@@ -209,6 +270,8 @@ public class FeaturesFile extends AlignFile
               if (colour != null)\r
               {\r
                 ((jalview.schemes.GraduatedColor) colour)\r
+                        .setColourByLabel(labelCol);\r
+                ((jalview.schemes.GraduatedColor) colour)\r
                         .setAutoScaled(abso == null);\r
                 // add in any additional parameters\r
                 String ttype = null, tval = null;\r
@@ -240,9 +303,10 @@ public class FeaturesFile extends AlignFile
                 }\r
                 if (((GraduatedColor) colour).getThreshType() != AnnotationColourGradient.NO_THRESHOLD)\r
                 {\r
-                  tval = gcol.nextToken();\r
                   try\r
                   {\r
+                    gcol.nextToken();\r
+                    tval = gcol.nextToken();\r
                     ((jalview.schemes.GraduatedColor) colour)\r
                             .setThresh(new Float(tval).floatValue());\r
                   } catch (Exception e)\r
@@ -260,7 +324,7 @@ public class FeaturesFile extends AlignFile
                           .println("Ignoring additional tokens in parameters in graduated colour specification\n");\r
                   while (gcol.hasMoreTokens())\r
                   {\r
-                    System.err.println("|" + gcol);\r
+                    System.err.println("|" + gcol.nextToken());\r
                   }\r
                   System.err.println("\n");\r
                 }\r
@@ -616,8 +680,8 @@ public class FeaturesFile extends AlignFile
         if (visible.get(type) instanceof GraduatedColor)\r
         {\r
           GraduatedColor gc = (GraduatedColor) visible.get(type);\r
-          // TODO: NOW: colour by label, autoscale flags.\r
-          color = Format.getHexString(gc.getMinColor()) + "|"\r
+          color = (gc.isColourByLabel() ? "label|" : "")\r
+                  + Format.getHexString(gc.getMinColor()) + "|"\r
                   + Format.getHexString(gc.getMaxColor())\r
                   + (gc.isAutoScale() ? "|" : "|abso|") + gc.getMin() + "|"\r
                   + gc.getMax() + "|";\r
@@ -754,9 +818,7 @@ public class FeaturesFile extends AlignFile
 \r
                   if (next[j].description.indexOf(href) == -1)\r
                   {\r
-                    out\r
-                            .append("<a href=\"" + href + "\">" + label\r
-                                    + "</a>");\r
+                    out.append("<a href=\"" + href + "\">" + label + "</a>");\r
                   }\r
                 }\r
 \r