// 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()
{
}
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;
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;
}
// normally output should match input
// we cheated here with a number of short input lines
// nb don't get Title in output if not calling print(AlignmentI)
- String expected = "#MEGA\n\n" + "#U455 ABCDEF\n"
- + "#CPZANT MNOPQR\n\n" + "#U455 KLMNOP\n" + "#CPZANT WXYZGC"
+ String expected = "#MEGA\n\n" + "#U455 ABCDEF [6]\n"
+ + "#CPZANT MNOPQR [6]\n\n" + "#U455 KLMNOP [12]\n"
+ + "#CPZANT WXYZGC [12]"
+ "\n";
assertEquals("Print format wrong", expected, printed);
}
String printed = testee.print();
System.out.println(printed);
- assertEquals("Print format wrong", "#MEGA\n\n" + INTERLEAVED_NOHEADERS,
+ //@formatter:off
+ assertEquals("Print format wrong",
+ "#MEGA\n\n" + "#U455 ABCDEF [6]\n"
+ + "#CPZANT MNOPQR [6]\n\n"
+ + "#U455 KLMNOP [12]\n"
+ + "#CPZANT WXYZGC [12]\n",
printed);
+ //@formatter:on
}
/**
//0123456789klmnopqrstABCDEFGHIJ9876543210abcdefghij
String expected =
"#MEGA\n\n" +
- "#U455 0123456789 klmnopqrst\n" + // first 20
- "#CPZANT 9876543210 abcdefghij\n\n" +
- "#U455 ABCDEFGHIJ 9876543210\n" + // next 20
- "#CPZANT 0123456789 klmnopqrst\n\n" +
- "#U455 abcdefghij\n" + // last 10
- "#CPZANT ABCDEFGHIJ\n";
+ "#U455 0123456789 klmnopqrst [20]\n" + // first 20
+ "#CPZANT 9876543210 abcdefghij [20]\n\n" +
+ "#U455 ABCDEFGHIJ 9876543210 [40]\n" + // next 20
+ "#CPZANT 0123456789 klmnopqrst [40]\n\n" +
+ "#U455 abcdefghij [50]\n" + // last 10
+ "#CPZANT ABCDEFGHIJ [50]\n";
//@formatter:on
assertEquals("Print format wrong", expected, printed);
}
" DataType=DNA CodeTable=Standard\n" +
" NSeqs=2 NSites=12\n" +
" Indel=- Identical=. Missing=?;\n\n" +
- "#U455 CGC GTA\n" +
- "#CPZANT ATC GGG\n\n" +
- "#U455 CGA TTT\n" +
- "#CPZANT CAA TGC\n";
+ "#U455 CGC GTA [6]\n" +
+ "#CPZANT ATC GGG [6]\n\n" +
+ "#U455 CGA TTT [12]\n" +
+ "#CPZANT CAA TGC [12]\n";
//@formatter:on
assertEquals("Roundtrip didn't match", expected,
formatted);
" DataType=DNA CodeTable=Standard\n" +
" NSeqs=2 NSites=12\n" +
" Indel=- Identical=. Missing=?;\n\n" +
- "#U455 CGC GTA\n" +
- "#CPZANT ATC GGG\n\n" +
- "#U455 CGA TTT\n" +
- "#CPZANT CAA TGC\n";
+ "#U455 CGC GTA [6]\n" +
+ "#CPZANT ATC GGG [6]\n\n" +
+ "#U455 CGA TTT [12]\n" +
+ "#CPZANT CAA TGC [12]\n";
//@formatter:on
assertEquals("Roundtrip didn't match", expected,
formatted);