+ private void writeToNexus( final Writer w ) throws IOException {
+ final int max = determineMaxIdLength() + 1;
+ w.write( "Begin Data;" );
+ w.write( ForesterUtil.LINE_SEPARATOR );
+ w.write( " Dimensions NTax=" + getNumberOfSequences() );
+ w.write( " NChar=" + getLength() );
+ w.write( ";" );
+ w.write( ForesterUtil.LINE_SEPARATOR );
+ w.write( " Format DataType=Protein Interleave=No gap=-;" );
+ w.write( ForesterUtil.LINE_SEPARATOR );
+ w.write( " Matrix" );
+ w.write( ForesterUtil.LINE_SEPARATOR );
+ for( int row = 0; row < getNumberOfSequences(); ++row ) {
+ final MolecularSequence seq = getSequence( row );
+ final String s = seq.getMolecularSequenceAsString();
+ w.write( " " );
+ w.write( ForesterUtil.pad( getIdentifier( row ).replace( ' ', '_' ), max, ' ', false ).toString() );
+ w.write( " " );
+ w.write( s );
+ w.write( ForesterUtil.LINE_SEPARATOR );
+ }
+ w.write( " ;" );
+ w.write( ForesterUtil.LINE_SEPARATOR );
+ w.write( "End;" );
+ w.write( ForesterUtil.LINE_SEPARATOR );
+ }
+