if (tbCharSets.isEmpty() != true) {
// a treebase matrix has zero or more character sets, we must iterate over them
for ( CharSet tbCharSet : tbCharSets ) {
// this is how we fetch the equivalent nexml character set
Subset nexSubset = nexMatrix.getSubset(tbCharSet.getLabel());
Assert.assertNotNull("If NexmlMatrixConverter works correctly, a Subset is returned", nexSubset);
//get names of TreeBASE and NeXML character set
String tbCharSetName = tbCharSet.getLabel();
String nexCharSetName = nexSubset.getLabel();
//verify that the names are the same
Assert.assertEquals("The NeXML character set must have copied the label of the TreeBASE character set",tbCharSetName,nexCharSetName);
// the coordinates of the character set are defined by a collection of column ranges that we iterate over
Collection<ColumnRange> tbColumnRanges = tbCharSet.getColumns(tbCharacterMatrix);
for ( ColumnRange tbColumnRange : tbColumnRanges ) {
// these are the beginning and end of the range
int tbStart = tbColumnRange.getStartColIndex();
int tbStop = tbColumnRange.getEndColIndex();
// this is how we increment from beginning to end. This number is probably either null, for a
// contiguous range, or perhaps 3 for codon positions
int tbInc = 1;
// need to do this to prevent nullpointerexceptions
if ( null != tbColumnRange.getRepeatInterval()) {
tbInc = tbColumnRange.getRepeatInterval();
}
// The NexmlMatrixConverter should have created a Subset for each tbCharSet
if ( null != nexSubset ) {
// now we iterate over the coordinates in this column range
//and verify whether correct character objects are returned
for ( int i = tbStart; i <= tbStop; i += tbInc ) {
// get the nexml character that should have been created
org.nexml.model.Character nexCharacter = nexCharacters.get(i);
Assert.assertNotNull("The NeXML Character should not be null if there as an index into it in this set", nexCharacter);
Assert.assertTrue("The Subset should contain the character at index i", nexSubset.containsThing(nexCharacter));
//get the treebase character for the index in this column range
PhyloChar tbCharacter = tbCharacterMatrix.getCharacter(i);
Assert.assertNotNull("The TreeBASE PhyloChar should not be null if there as an index into it in this set", tbCharacter);
Assert.assertEquals("If the TreeBASE character has a label, then the NeXML character's label should match it", tbCharacter.getLabel(), nexCharacter.getLabel());