nedblorf nedblorf - 3 years ago 347
C Question

Validate DNA in C/C++

I am iterating over DNA sequences pulling out chunks of 5-15 bases at a time into C++ std::string objects. Occasionally, my string will contain a non ATCG base, and I want to take an action when this happens. For example, I might see:

CTACGGTACGRCTA


Because there is an 'R', I want to recognize this case. I am familiar with regex, but people seem to recommend several different libraries. I've seen Boost, TR1, and others. Can someone please suggest either a different way to catch my cases or tell me which library I should use and why?

Thanks

Answer Source

A regular expression is overkill for this. You can use std::string::find_first_not_of().

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download