MCPcopy Create free account
hub / github.com/GlobalTechInfo/MEGA-MD / decode

Function decode

lib/dna.cpp:24–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22}
23
24std::string decode(const std::string& dna) {
25 if (dna.size() % 4 != 0) throw std::runtime_error("Invalid DNA length");
26 std::string result;
27 result.reserve(dna.size() / 4);
28 for (size_t i = 0; i < dna.size(); i += 4) {
29 unsigned char c = 0;
30 for (int j = 0; j < 4; j++) {
31 auto it = BASE_VAL.find(std::toupper(dna[i+j]));
32 if (it == BASE_VAL.end()) throw std::runtime_error("Invalid base: " + std::string(1, dna[i+j]));
33 c = (c << 2) | it->second;
34 }
35 result += c;
36 }
37 return result;
38}
39
40int main(int argc, char* argv[]) {
41 if (argc < 3) {

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected