diff --git a/uk/ac/sanger/artemis/io/GFFDocumentEntry.java b/uk/ac/sanger/artemis/io/GFFDocumentEntry.java
index 12a62c45513fa451aea4183e2082715274a92742..f8f2c77f6622344fbc8b58fb74f49b846686b212 100644
--- a/uk/ac/sanger/artemis/io/GFFDocumentEntry.java
+++ b/uk/ac/sanger/artemis/io/GFFDocumentEntry.java
@@ -20,7 +20,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
- * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/io/GFFDocumentEntry.java,v 1.9 2005-04-21 13:11:51 tjc Exp $
+ * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/io/GFFDocumentEntry.java,v 1.10 2005-04-22 15:04:25 tjc Exp $
  */
 
 package uk.ac.sanger.artemis.io;
@@ -36,7 +36,7 @@ import java.util.Vector;
  *  A DocumentEntry that can read an GFF entry from a Document.
  *
  *  @author Kim Rutherford
- *  @version $Id: GFFDocumentEntry.java,v 1.9 2005-04-21 13:11:51 tjc Exp $
+ *  @version $Id: GFFDocumentEntry.java,v 1.10 2005-04-22 15:04:25 tjc Exp $
  **/
 
 public class GFFDocumentEntry extends SimpleDocumentEntry
@@ -176,7 +176,7 @@ public class GFFDocumentEntry extends SimpleDocumentEntry
 
       try 
       {
-        if(this_feature.getQualifierByName("CDS") != null)
+        if(this_feature.getKey().getKeyString().equals("CDS"))
         {
           if(this_feature.getQualifierByName("Parent") != null)
           {
@@ -185,8 +185,8 @@ public class GFFDocumentEntry extends SimpleDocumentEntry
             group_name = values.elementAt(0);
 
             // check the parent is a gene
-            if(!genes.contains(group_name))
-              continue;
+//          if(!genes.contains(group_name))
+//            continue;
           }
         }
         else
diff --git a/uk/ac/sanger/artemis/io/GFFStreamFeature.java b/uk/ac/sanger/artemis/io/GFFStreamFeature.java
index 6c3bed741fcb222d97652890b942f0d29c46630c..989d99a69e2e79de2f9d8b8b333055d27ff2ea69 100644
--- a/uk/ac/sanger/artemis/io/GFFStreamFeature.java
+++ b/uk/ac/sanger/artemis/io/GFFStreamFeature.java
@@ -20,7 +20,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
- * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/io/GFFStreamFeature.java,v 1.5 2005-04-19 14:49:47 tjc Exp $
+ * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/io/GFFStreamFeature.java,v 1.6 2005-04-22 15:04:25 tjc Exp $
  */
 
 package uk.ac.sanger.artemis.io;
@@ -35,13 +35,27 @@ import java.util.StringTokenizer;
  *  A StreamFeature that thinks it is a GFF feature.
  *
  *  @author Kim Rutherford
- *  @version $Id: GFFStreamFeature.java,v 1.5 2005-04-19 14:49:47 tjc Exp $
+ *  @version $Id: GFFStreamFeature.java,v 1.6 2005-04-22 15:04:25 tjc Exp $
  **/
 
 public class GFFStreamFeature extends SimpleDocumentFeature
                        implements DocumentFeature, StreamFeature, ComparableFeature 
 {
 
+
+  /**
+   *  The DocumentEntry object that contains this Feature as passed to the
+   *  constructor.
+   **/
+  private DocumentEntry entry;
+
+  /**
+   *  This is the line of GFF input that was read to get this
+   *  GFFStreamFeature.  A GFFStreamFeature that was created from multiple GFF
+   *  lines will have a gff_lines variable that contains multiple line.
+   **/
+  StringVector gff_lines = null;
+
   /**
    *  Create a new GFFStreamFeature object.  The feature should be added
    *  to an Entry (with Entry.add()).
@@ -175,10 +189,10 @@ public class GFFStreamFeature extends SimpleDocumentFeature
 
           final StringVector values = (StringVector)attributes.get(name);
 
-          if(name.equals("ID"))
-            name = "systematic_id";
-          else if(name.equals("Name"))
-            name = type;
+//        if(name.equals("ID"))
+//          name = "systematic_id";
+//        else if(name.equals("Name"))
+//          name = type;
 
           if(values.size() == 0)
             setQualifier(new Qualifier(name));
@@ -303,6 +317,30 @@ public class GFFStreamFeature extends SimpleDocumentFeature
 
     return s;
   }
+
+  private String encode(String s)
+  {
+    int ind;
+
+    // white space
+    while( (ind = s.indexOf(" ")) > -1)
+      s = s.substring(0,ind) + "%20" + s.substring(ind+1);
+
+    // comma
+    while( (ind = s.indexOf(",")) > -1)
+      s = s.substring(0,ind) + "%2C" + s.substring(ind+1);
+
+    // semi-colon
+    while( (ind = s.indexOf(";")) > -1)
+      s = s.substring(0,ind) + "%3B" + s.substring(ind+1);
+
+    // equals
+    while( (ind = s.indexOf("=")) > -1)
+      s = s.substring(0,ind) + "%3D" + s.substring(ind+1);
+
+    return s;
+  }
+
    
   /**
    *  Return the reference of a new copy of this Feature.
@@ -375,8 +413,8 @@ public class GFFStreamFeature extends SimpleDocumentFeature
       throws IOException 
   {
     // for now GFF features are read-only so just write what we read
-    if(gff_lines == null) 
-    {
+ // if(gff_lines == null) 
+ // {
       final RangeVector ranges = getLocation().getRanges();
 
       for(int i = 0 ; i < ranges.size() ; ++i) 
@@ -443,12 +481,12 @@ public class GFFStreamFeature extends SimpleDocumentFeature
                       frame + "\t" +
                       attribute_string + "\n");
       }
-    } 
-    else 
-    {
-      for(int i = 0 ; i < gff_lines.size() ; ++i) 
-        writer.write(gff_lines.elementAt(i) + "\n");
-    }
+ // } 
+ // else 
+ // {
+ //   for(int i = 0 ; i < gff_lines.size() ; ++i) 
+ //     writer.write(gff_lines.elementAt(i) + "\n");
+ // }
   }
 
   /**
@@ -464,52 +502,85 @@ public class GFFStreamFeature extends SimpleDocumentFeature
     final QualifierVector qualifiers = getQualifiers();
     final QualifierVector qualifiers_to_write = new QualifierVector();
 
-    for(int i = 0 ; i < qualifiers.size() ; ++i) 
+    final String names[] = { "ID", "Name", "Alias", "Parent",
+                             "Target", "Gap", "Note", 
+                             "Dbxref", "Ontology_term" };
+    int count = 0;
+
+    for(int i=0; i<names.length; i++)
     {
-      final Qualifier this_qualifier = (Qualifier)qualifiers.elementAt(i);
+      Qualifier this_qualifier = (Qualifier)qualifiers.getQualifierByName(names[i]);
+ 
+      if(this_qualifier == null)
+        continue;
 
-      final String name = this_qualifier.getName();
+      String this_qualifier_str = getQualifierString(this_qualifier);
+      if(this_qualifier_str == null)
+        continue;
+
+      if(count != 0)
+        buffer.append(";");
+      buffer.append(this_qualifier_str);
+      count++;
+    }
 
-      if(name.equals("codon_start") || name.equals("gff_source") ||
-         name.equals("gff_seqname") || name.equals("score"))
+/*
+    for(int i = 0 ; i < qualifiers.size() ; ++i) 
+    {
+      this_qualifier = (Qualifier)qualifiers.elementAt(i);
+
+      String this_qualifier_str = getQualifierString(this_qualifier);
+      if(this_qualifier_str == null)
         continue;
 
-      if(i != 0)
-        buffer.append(" ; ");
+      if(count != 0)
+        buffer.append("; ");
+      buffer.append(this_qualifier_str);
+    }
+*/
+
+    return buffer.toString();
+  }
+
 
-      final StringVector values = this_qualifier.getValues();
+  private String getQualifierString(Qualifier q)
+  {
+    StringBuffer buffer = new StringBuffer();
+    final String name = q.getName();
+
+    if(name.equals("codon_start") || name.equals("gff_source") ||
+       name.equals("gff_seqname") || name.equals("score"))
+      return null;
 
-      buffer.append(name);
+    final StringVector values = q.getValues();
+    buffer.append(encode(name));
 
-      if(values != null) 
+    if(values != null)
+    {
+      for(int value_index = 0; value_index < values.size();
+          ++value_index)
       {
-        for(int value_index = 0;
-            value_index < values.size();
-            ++value_index) 
+        final String this_value = values.elementAt(value_index);
+        buffer.append('=');
+        try
+        {
+          buffer.append(Integer.valueOf(this_value));
+        }
+        catch(NumberFormatException _)
         {
-          final String this_value = values.elementAt(value_index);
-          buffer.append(' ');
-          try 
+          // not an integer
+          try
           {
-            buffer.append(Integer.valueOf(this_value));
-          } 
-          catch(NumberFormatException _) 
+            buffer.append(Double.valueOf(this_value));
+          }
+          catch (NumberFormatException __)
           {
-            // not an integer
-            try 
-            {
-              buffer.append(Double.valueOf(this_value));
-            }
-            catch (NumberFormatException __) 
-            {
-              // not a double or integer so quote it
-              buffer.append('"' + this_value + '"');
-            }
+            // not a double or integer so quote it
+            buffer.append('"' + encode(this_value) + '"');
           }
         }
       }
     }
-
     return buffer.toString();
   }
 
@@ -616,16 +687,4 @@ public class GFFStreamFeature extends SimpleDocumentFeature
     return attributes;
   }
 
-  /**
-   *  The DocumentEntry object that contains this Feature as passed to the
-   *  constructor.
-   **/
-  private DocumentEntry entry;
-
-  /**
-   *  This is the line of GFF input that was read to get this
-   *  GFFStreamFeature.  A GFFStreamFeature that was created from multiple GFF
-   *  lines will have a gff_lines variable that contains multiple line.
-   **/
-  StringVector gff_lines = null;
 }
diff --git a/uk/ac/sanger/artemis/io/SimpleDocumentEntry.java b/uk/ac/sanger/artemis/io/SimpleDocumentEntry.java
index 99490589b87b3f93a5651d5aebe58e132ba1efec..5b22424b5b590f2f478077a3c330427b09304b81 100644
--- a/uk/ac/sanger/artemis/io/SimpleDocumentEntry.java
+++ b/uk/ac/sanger/artemis/io/SimpleDocumentEntry.java
@@ -20,7 +20,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  *
- * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/io/SimpleDocumentEntry.java,v 1.10 2005-04-20 14:54:28 tjc Exp $
+ * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/io/SimpleDocumentEntry.java,v 1.11 2005-04-22 15:04:25 tjc Exp $
  */
 
 package uk.ac.sanger.artemis.io;
@@ -37,7 +37,7 @@ import java.util.Enumeration;
  *  This class contains the methods common to all DocumentEntry objects.
  *
  *  @author Kim Rutherford <kmr@sanger.ac.uk>
- *  @version $Id: SimpleDocumentEntry.java,v 1.10 2005-04-20 14:54:28 tjc Exp $
+ *  @version $Id: SimpleDocumentEntry.java,v 1.11 2005-04-22 15:04:25 tjc Exp $
  **/
 
 abstract public class SimpleDocumentEntry
@@ -907,46 +907,43 @@ abstract public class SimpleDocumentEntry
         }
       }
     } 
-    else
+    else if(new_line_group instanceof Feature)
     {
-      if(new_line_group instanceof Feature)
+      // Features before the Sequence and FeatureTable(if any)
+      for(int i = 0 ; i < line_groups.size() ; ++i) 
       {
-        // Features before the Sequence and FeatureTable(if any)
-        for(int i = 0 ; i < line_groups.size() ; ++i) 
-        {
-          final LineGroup this_line_group = line_groups.elementAt(i);
+        final LineGroup this_line_group = line_groups.elementAt(i);
 
-          if(this_line_group instanceof FeatureTable ||
-              this_line_group instanceof Sequence) 
-          {
-            line_groups.insertElementAt(new_line_group, i);
-            return;
-          }
+        if(this_line_group instanceof FeatureTable ||
+            this_line_group instanceof Sequence) 
+        {
+          line_groups.insertElementAt(new_line_group, i);
+          return;
         }
-      } 
-      else
-      {
-        if(!(new_line_group instanceof Sequence) &&
+      }
+    } 
+    else if(!(new_line_group instanceof Sequence) &&
             !(new_line_group instanceof FeatureTable)) 
-        {
-          // insert before features and sequence
-          for(int i = 0 ; i < line_groups.size() ; ++i) 
-          {
-            final LineGroup this_line_group = line_groups.elementAt(i);
+    {
+      if(new_line_group instanceof GFFMisc)
+      {
+        String line = ((GFFMisc)new_line_group).toString();
+        if(line.indexOf("FASTA") > -1)  // ignore
+          return;
+      }   
 
-            if(this_line_group instanceof Feature ||
-                this_line_group instanceof FeatureTable ||
-                this_line_group instanceof FeatureHeader ||
-                this_line_group instanceof Sequence)
-            {
-              line_groups.insertElementAt(new_line_group, i);
-              return;
-            }
-          }
-        }
-        else
+      // insert before features and sequence
+      for(int i = 0 ; i < line_groups.size() ; ++i) 
+      {
+        final LineGroup this_line_group = line_groups.elementAt(i);
+
+        if(this_line_group instanceof Feature ||
+           this_line_group instanceof FeatureTable ||
+           this_line_group instanceof FeatureHeader ||
+           this_line_group instanceof Sequence)
         {
-          // fall throw
+          line_groups.insertElementAt(new_line_group, i);
+          return;
         }
       }
     }