From 3aaa2e6af84ae474b22de8a97a04cdd44e946b6c Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 1 Oct 2015 12:11:48 +0100 Subject: [PATCH] JAL-1499 tests with gaps; NSites = width --- src/jalview/io/MegaFile.java | 38 ++++++++++++++++++------------------- test/jalview/io/MegaFileTest.java | 27 ++++++++++++++------------ 2 files changed, 34 insertions(+), 31 deletions(-) diff --git a/src/jalview/io/MegaFile.java b/src/jalview/io/MegaFile.java index 1126cff..88200f5 100644 --- a/src/jalview/io/MegaFile.java +++ b/src/jalview/io/MegaFile.java @@ -859,19 +859,23 @@ public class MegaFile extends AlignFile throws IOException { StringBuilder desc = new StringBuilder(256); - String line = getValue(firstDescriptionLine); - while (line != null) + desc.append(getValue(firstDescriptionLine)); + if (!firstDescriptionLine.endsWith(SEMICOLON)) { - if (line.endsWith(SEMICOLON)) + String line = nextNonCommentLine(); + while (line != null) { - desc.append(line.substring(0, line.length() - 1)); - break; - } - else if (line.length() > 0) - { - desc.append(line).append(newline); + if (line.endsWith(SEMICOLON)) + { + desc.append(line.substring(0, line.length() - 1)); + break; + } + else if (line.length() > 0) + { + desc.append(line).append(newline); + } + line = nextNonCommentLine(); } - line = nextNonCommentLine(); } setAlignmentProperty(PROP_DESCRIPTION, desc.toString()); } @@ -988,10 +992,8 @@ public class MegaFile extends AlignFile String propertyValue = (String) al.getProperty(PROP_TITLE); if (propertyValue != null) { - sb.append(BANG).append(TITLE).append(SPACE) -.append(propertyValue) - .append(SEMICOLON) - .append(newline); + sb.append(BANG).append(TITLE).append(SPACE).append(propertyValue) + .append(SEMICOLON).append(newline); } propertyValue = (String) al.getProperty(PROP_DESCRIPTION); if (propertyValue != null) @@ -1017,14 +1019,12 @@ public class MegaFile extends AlignFile .append(newline); /* - * !Format NSeqs NSites - * NSites the length of any sequence (they should all be the same), excluding - * gaps?!? + * !Format NSeqs NSites (the length of sequences - they should all be the + * same - including gaps) */ sb.append(INDENT).append(N_SEQS).append(EQUALS).append(al.getHeight()); - SequenceI seq = al.getSequenceAt(0); sb.append(SPACE).append(N_SITES).append(EQUALS) - .append(seq.getEnd() - seq.getStart() + 1); + .append(String.valueOf(al.getWidth())); sb.append(newline); /* diff --git a/test/jalview/io/MegaFileTest.java b/test/jalview/io/MegaFileTest.java index 477f982..d868dcb 100644 --- a/test/jalview/io/MegaFileTest.java +++ b/test/jalview/io/MegaFileTest.java @@ -72,7 +72,7 @@ public class MegaFileTest + "#CPZANT MNOPQR\n\n" + "#U456 KLMNOP\n"; - // the 'fancy' format, different header format, bases in triplet groups + // interleaved with description, bases/gaps in triplet groups private static final String INTERLEAVED_WITH_DESCRIPTION = "#MEGA\n" + "!Title Data with description;\n" @@ -80,10 +80,10 @@ public class MegaFileTest + "!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"; + + "#U455 C-- GTA\n" + + "#CPZANT ATC -G-\n\n" + + "#U455 CGA --T\n" + + "#CPZANT CA- -GC\n"; //@formatter:on @@ -358,9 +358,9 @@ public class MegaFileTest assertEquals("Second sequence id wrong", "CPZANT", seqs.get(1) .getName()); // check sequence data - assertEquals("First sequence data wrong", "CGCGTACGATTT", seqs.get(0) + assertEquals("First sequence data wrong", "C--GTACGA--T", seqs.get(0) .getSequenceAsString()); - assertEquals("Second sequence data wrong", "ATCGGGCAATGC", seqs.get(1) + assertEquals("Second sequence data wrong", "ATC-G-CA--GC", seqs.get(1) .getSequenceAsString()); assertTrue("File format is not flagged as interleaved", testee.isInterleaved()); @@ -431,12 +431,12 @@ public class MegaFileTest " Line two of description;\n" + "!Format\n" + " DataType=DNA CodeTable=Standard\n" + - " NSeqs=2 NSites=12\n" + + " NSeqs=2 NSites=12\n" + // NSites includes gaps " Indel=- Identical=. Missing=?;\n\n" + - "#U455 CGC GTA [6]\n" + - "#CPZANT ATC GGG [6]\n\n" + - "#U455 CGA TTT [12]\n" + - "#CPZANT CAA TGC [12]\n"; + "#U455 C-- GTA [6]\n" + + "#CPZANT ATC -G- [6]\n\n" + + "#U455 CGA --T [12]\n" + + "#CPZANT CA- -GC [12]\n"; //@formatter:on assertEquals("Roundtrip didn't match", expected, formatted); @@ -603,4 +603,7 @@ public class MegaFileTest assertTrue("File format is not flagged as interleaved", testee.isInterleaved()); } + + //@formatter:on + } -- 1.7.10.2