JAL-1499 corrected domainend parsing, add gene name to domain desc
[jalview.git] / src / jalview / io / MegaFile.java
index 58961f8..c7caa3b 100644 (file)
@@ -362,22 +362,26 @@ public class MegaFile extends AlignFile
   protected void processGeneOrDomain(String gene, String domain,
           String property, String codonStart)
   {
+    boolean domainEnd = "domainend".equalsIgnoreCase(property);
+
     /*
-     * If we have been processing a Gene or Domain, and this does not continue
-     * it, then close it off (generate sequence features for it)
+     * If we have been processing a Domain or Gene, and this does not continue
+     * it, then close it off (generate sequence features for it). Do Domain
+     * first as it is in the context of the enclosing gene if any.
      */
-    if (this.currentGene != null && !this.currentGene.equals(gene))
-    {
-      createFeature(GENE, currentGene, geneStart);
-    }
     if (this.currentDomain != null)
     {
-      if (!this.currentDomain.equals(domain)
-              || "domainend".equalsIgnoreCase(property))
+      if (!this.currentDomain.equals(domain) || domainEnd)
       {
-        createFeature(DOMAIN, currentDomain, domainStart);
+        String description = currentDomain
+                + (currentGene == null ? "" : " (" + currentGene + ")");
+        createFeature(DOMAIN, description, domainStart);
       }
     }
+    if (this.currentGene != null && !this.currentGene.equals(gene))
+    {
+      createFeature(GENE, currentGene, geneStart);
+    }
 
     /*
      * and if we have declared a Gene or Domain which does not continue the
@@ -393,7 +397,7 @@ public class MegaFile extends AlignFile
     }
 
     currentGene = gene;
-    currentDomain = domain;
+    currentDomain = domainEnd ? null : domain;
   }
 
   /**