{
StringBuilder sb = new StringBuilder(128);
sb.append(MEGA_ID).append(newline);
- printProperty(al, sb, PROP_TITLE, TITLE);
- printProperty(al, sb, PROP_DESCRIPTION, DESCRIPTION);
+ String propertyValue = (String) al.getProperty(PROP_TITLE);
+ if (propertyValue != null)
+ {
+ sb.append(BANG).append(TITLE).append(SPACE)
+.append(propertyValue)
+ .append(SEMICOLON)
+ .append(newline);
+ }
+ propertyValue = (String) al.getProperty(PROP_DESCRIPTION);
+ if (propertyValue != null)
+ {
+ sb.append(BANG).append(DESCRIPTION).append(newline)
+ .append(propertyValue).append(SEMICOLON)
+ .append(newline);
+ }
/*
* !Format DataType CodeTable
}
/**
- * Helper method to append a property e.g. !Title to the output buffer, if the
- * property is set on the alignment.
- *
- * @param al
- * @param headers
- * @param propertyName
- * @param propertyKeyword
- */
- protected void printProperty(AlignmentI al, StringBuilder headers,
- String propertyName, String propertyKeyword)
- {
- String propertyValue = (String) al.getProperty(propertyName);
- if (propertyValue != null)
- {
- headers.append(BANG).append(propertyKeyword).append(SPACE)
- .append(propertyValue).append(SEMICOLON)
- .append(newline);
- }
- }
-
- /**
* Returns the number of sequence positions output per line
*
* @return
//@formatter:off
String expected =
"#MEGA\n!Title Data with description;\n" +
- "!Description Line one of description\n" +
+ "!Description\n" +
+ " Line one of description\n" +
+ " Line two of description;\n" +
+ "!Format\n" +
+ " 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";
+ //@formatter:on
+ assertEquals("Roundtrip didn't match", expected,
+ formatted);
+ }
+
+ /**
+ * Test reading a MEGA file to an alignment then writing it out in MEGA
+ * format. Verify the output is (functionally) the same as the input.
+ *
+ * @throws IOException
+ */
+ @Test(groups = "Functional")
+ public void testRoundTrip_multilineFormatWithComments()
+ throws IOException
+ {
+ AppletFormatAdapter fa = new AppletFormatAdapter();
+ //@formatter:off
+ AlignmentI al = fa.readFile("#MEGA\n"
+ + "!Title Data with description;\n"
+ + "[ this comment should be ignored\n"
+ + "including [this nested comment]\n"
+ + "]\n"
+ + "!Format \n"
+ + "DataType=DNA CodeTable=Standard\n"
+ + "indel=- Missing=? MatchChar=.;\n\n"
+ + "!Description\n"
+ + " Line one of description\n"
+ + " Line two of description;\n\n"
+ + "#U455 CGC GTA\n"
+ + "#CPZANT ATC GGG\n\n"
+ + "#U455 CGA TTT\n"
+ + "#CPZANT CAA TGC\n",
+ AppletFormatAdapter.PASTE, "MEGA");
+ //@formatter:on
+ MegaFile output = new MegaFile();
+ String formatted = output.print(al);
+ //@formatter:off
+ String expected =
+ "#MEGA\n!Title Data with description;\n" +
+ "!Description\n" +
+ " Line one of description\n" +
" Line two of description;\n" +
"!Format\n" +
" DataType=DNA CodeTable=Standard\n" +