1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| #include <iostream>
#include <algorithm>
#include <array>
#include <map>
enum Nucleotide : char
{
A = 0x01,
C = 0x05,
G = 0x07,
T = 0x03
};
class Sequence
{
public:
static constexpr size_t SIZE = 4;
Sequence(const std::array<Nucleotide, SIZE> &sequence);
void reverse();
void complement();
friend std::ostream &operator <<(std::ostream &os, const Sequence &sequence);
private:
static constexpr char COMPLEMENT = 0x02;
static const std::map<char, char> mapping;
std::array<Nucleotide, SIZE> sequence;
};
const std::map<char, char> mapping =
{
{0x01, 'A'},
{0x05, 'C'},
{0x07, 'G'},
{0x03, 'T'}
};
Sequence::Sequence(const std::array<Nucleotide, SIZE> &sequence) :
sequence(sequence)
{
}
void Sequence::reverse()
{
std::reverse(sequence.begin(), sequence.end());
}
void Sequence::complement()
{
// ...
}
inline std::ostream &operator <<(std::ostream &os, const Sequence &sequence)
{
for (char nucleotide : sequence.sequence)
{
os << mapping.at(nucleotide);
}
return os;
}
int main()
{
Sequence sequence{{A, T, C, G}};
std::cout << sequence << std::endl;
sequence.reverse();
std::cout << sequence << std::endl;
sequence.complement();
std::cout << sequence << std::endl;
return 0;
} |
Partager