JAL-1499 write position numbers at end of each line (interleaved)
[jalview.git] / src / jalview / io / MegaFile.java
index af9889b..2f48bf5 100644 (file)
@@ -143,6 +143,9 @@ public class MegaFile extends AlignFile
   // this can be True, False or null (meaning we don't know yet)
   private Boolean interleaved;
 
+  // write end of line positions as a comment
+  private boolean writePositionNumbers = true;
+
   public MegaFile()
   {
   }
@@ -891,17 +894,17 @@ public class MegaFile extends AlignFile
     int maxSequenceLength = getMaxSequenceLength(s);
     int numLines = maxSequenceLength / positionsPerLine + 3; // approx
 
-    /*
-     * Size a buffer to hold the whole output
-     */
-    StringBuilder sb = new StringBuilder(numLines
-            * (maxIdLength + 2 + positionsPerLine));
-
     int numDataBlocks = (maxSequenceLength - 1) / positionsPerLine + 1;
     int spaceEvery = this.nucleotide != null && this.nucleotide ? 3 : 10;
     int chunksPerLine = (positionsPerLine + spaceEvery - 1) / spaceEvery;
 
     /*
+     * Roughly size a buffer to hold the whole output
+     */
+    StringBuilder sb = new StringBuilder(numLines
+            * (maxIdLength + positionsPerLine + chunksPerLine + 10));
+
+    /*
      * Output as: #Seqid CGT AGC ACT ... or blocks of 10 for peptide
      */
     int from = 0;
@@ -936,6 +939,12 @@ public class MegaFile extends AlignFile
             advancedBy += subSequence.length;
           }
         }
+        // write last position as a comment
+        if (writePositionNumbers)
+        {
+          sb.append(SPACE).append(COMMENT_START).append(from + advancedBy)
+                  .append(COMMENT_END);
+        }
         sb.append(newline);
         first = false;
       }