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;
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
{
/*
* Blank line after processing some data...
*/
- endOfDataBlock();
+ endDataBlock();
}
dataLine = nextNonCommentLine();
}
/**
* Post-processing after reading one block of interleaved data
*/
- protected void endOfDataBlock()
+ protected void endDataBlock()
{
- this.firstDataBlockRead = true;
-
padAnnotations(labelAnnotations);
}
// 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;
}
/*
* 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);
+ "!TITLE Interleaved sequence data\n\n"
+ "#U455 ABCDEF\n"
+ "#CPZANT MNOPQR\n\n"
- + "#U456 KLMNOP\n";
+ + "#U455 GHIJKL\n"
+ + "#U456 KLMNOP\n"; // wossis?
// interleaved with description, bases/gaps in triplet groups
private static final String INTERLEAVED_WITH_DESCRIPTION =
assertEquals("Noncoding", MegaFile.getPropertyFromAnnotation(3, aa));
assertEquals("Coding", MegaFile.getPropertyFromAnnotation(4, aa));
}
+
+ //@formatter:on
+
+ /**
+ * Test parse of interleaved data with no blank lines to separate blocks of
+ * sequence data; to confirm we can handle this correctly
+ *
+ * @throws IOException
+ */
+ @Test(groups = { "Functional" })
+ public void testParse_interleaved_noBlankLines() throws IOException
+ {
+ String data = INTERLEAVED.replace("\n\n", "\n");
+ MegaFile testee = new MegaFile(data, AppletFormatAdapter.PASTE);
+ assertEquals("Title not as expected", "Interleaved sequence data",
+ testee.getAlignmentProperty(MegaFile.PROP_TITLE));
+ Vector<SequenceI> seqs = testee.getSeqs();
+ // should be 2 sequences
+ assertEquals("Expected two sequences", 2, seqs.size());
+ // check sequence names correct and order preserved
+ assertEquals("First sequence id wrong", "U455", seqs.get(0).getName());
+ assertEquals("Second sequence id wrong", "CPZANT", seqs.get(1)
+ .getName());
+ // check sequence data
+ assertEquals("First sequence data wrong", "ABCDEFKLMNOP", seqs.get(0)
+ .getSequenceAsString());
+ assertEquals("Second sequence data wrong", "MNOPQRWXYZGC", seqs.get(1)
+ .getSequenceAsString());
+ assertTrue("File format is not flagged as interleaved",
+ testee.isInterleaved());
+ }
}