66 std::string rec; rec.reserve(1024);
67 while( __is.peek() != std::istream::traits_type::eof() )
69 if(rec.capacity() == rec.size()) rec.reserve(rec.capacity() * 2);
70 if( rec.size() && __is.peek() ==
'>' && *rec.rbegin() ==
'\n' )
break;
71 else rec += __is.get();
74 if( !rec.size() || *rec.begin() !=
'>' )
throw runtime_error( std::string(
"FASTA syntax error in record '") + rec +
"': no leading '>'" );
76 rec = bo::regex_replace( rec, bo::regex(
"^>"),
"" );
78 bo::sregex_token_iterator i(rec.begin(), rec.end(), bo::regex(
"\n"), -1);
80 if( i == boost::sregex_token_iterator() )
throw runtime_error( std::string(
"FASTA syntax error in record '") + rec +
"': only one line" );
82 std::string top = *i++;
83 std::string sequence( i->first,
static_cast<std::string::const_iterator
>( rec.end() ) );
85 sequence = bo::regex_replace( sequence, bo::regex(
">"),
"" );
87 bo::match_results<std::string::const_iterator> what;
88 std::string id, fulldesc;
89 if( bo::regex_search( top, what, bo::regex(
"^[[:space:]]*([^[:space:]]+)[:space:]*(.*)") ) )
90 {
id = std::string( what[1].first, what[1].second ); fulldesc = std::string( what[2].first, what[2].second ); }
92 if(
id.empty() )
id = fulldesc;
94 sequence = bo::regex_replace( sequence, bo::regex(
"[ \t\n\r]"),
"" );