36 lines
618 B
C++
36 lines
618 B
C++
#include "nucleotide_count.h"
|
|
|
|
#include <stdexcept>
|
|
|
|
|
|
namespace dna {
|
|
|
|
using namespace std;
|
|
|
|
|
|
counter::counter(const string &sequence)
|
|
: nucleotide_counts_{ {'A', 0}, {'T', 0}, {'C', 0}, {'G', 0}}
|
|
{
|
|
for (auto c : sequence)
|
|
++nucleotide_counts_[c];
|
|
}
|
|
|
|
bool counter::is_valid_nucleotide(char c) const
|
|
{
|
|
return nucleotide_counts_.count(c);
|
|
}
|
|
|
|
const NucleotideCounts &counter::nucleotide_counts() const
|
|
{
|
|
return nucleotide_counts_;
|
|
}
|
|
|
|
int counter::count(char c) const
|
|
{
|
|
if (!is_valid_nucleotide(c))
|
|
throw invalid_argument("invalid nucleotide");
|
|
|
|
return nucleotide_counts_.at(c);
|
|
}
|
|
|
|
}
|