64 auto& os = target->ostream();
68 for(
Sequence const& s : sequence_set ) {
73 if (s.length() !=
length) {
74 throw std::runtime_error(
75 "Cannot write SequenceSet to Phylip format: Sequences do not have the same length."
80 throw std::runtime_error(
"Cannot write SequenceSet to Phylip format: Sequences are empty." );
84 os << sequence_set.size() <<
" " <<
length <<
"\n";
85 for (
Sequence const& s : sequence_set) {
87 if( label_length_ == 0 ) {
88 auto const f = std::find_if( std::begin(s.label()), std::end(s.label()), [](
char c){
89 return ! ::isgraph(c);
91 if( std::end(s.label()) != f ) {
92 throw std::runtime_error(
93 "Cannot write Sequence to Philip: Sequence label \"" + s.label() +
94 "\" contains non-printable or whitespace characters, "
95 "which cannot be used in the relaxed Phylip format."
98 os << s.label() <<
" ";
100 os << s.label().substr( 0, label_length_ );
101 if( label_length_ > s.label().length() ) {
102 os << std::string( label_length_ - s.label().length(),
' ' );
107 if( line_length_ > 0 ) {
108 for(
size_t i = 0; i < s.length(); i += line_length_ ) {
111 os << s.sites().substr( i, line_length_ ) <<
"\n";
114 os << s.sites() <<
"\n";
125 label_length_ = value;
131 return label_length_;
136 line_length_ = value;