JAL-1499 slight refactoring of handling interleaved data blocks
[jalview.git] / src / jalview / io / MegaFile.java
index 5a76d07..73cfe23 100644 (file)
@@ -175,7 +175,7 @@ public class MegaFile extends AlignFile
   private Boolean nucleotide;
 
   // set once we have seen one block of interleaved data
-  private boolean firstDataBlockRead = false;
+  private boolean seenAllSequences = false;
 
   // this can be True, False or null (meaning we don't know yet)
   private Boolean interleaved;
@@ -284,11 +284,13 @@ public class MegaFile extends AlignFile
         if (upperCased.startsWith(BANG + GENE.toUpperCase())
                 || upperCased.startsWith(BANG + DOMAIN.toUpperCase()))
         {
+          endDataBlock();
           parseGeneOrDomain(dataLine);
         }
         else if (upperCased.startsWith(BANG + LABEL.toUpperCase()))
         {
           parseLabel(dataLine);
+          endDataBlock();
         }
         else
         {
@@ -300,7 +302,7 @@ public class MegaFile extends AlignFile
         /*
          * Blank line after processing some data...
          */
-        endOfDataBlock();
+        endDataBlock();
       }
       dataLine = nextNonCommentLine();
     }
@@ -410,10 +412,8 @@ public class MegaFile extends AlignFile
   /**
    * Post-processing after reading one block of interleaved data
    */
-  protected void endOfDataBlock()
+  protected void endDataBlock()
   {
-    this.firstDataBlockRead = true;
-
     padAnnotations(labelAnnotations);
   }
 
@@ -1029,6 +1029,14 @@ public class MegaFile extends AlignFile
       // and a placeholder for any SequenceFeature found
       sequenceFeatures.put(currentId, new ArrayList<SequenceFeature>());
     }
+    else
+    {
+      /*
+       * we are appending to a previously seen sequence; flag that we have seen
+       * all sequences
+       */
+      this.seenAllSequences = true;
+    }
     return sb;
   }
 
@@ -1049,7 +1057,7 @@ public class MegaFile extends AlignFile
     /*
      * New sequence found in second or later data block - error.
      */
-    if (this.firstDataBlockRead && !seqData.containsKey(seqId))
+    if (this.seenAllSequences && !seqData.containsKey(seqId))
     {
       throw new FileFormatException(
               "Parse error: misplaced new sequence starting at " + dataLine);