X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=mussa.git;a=blobdiff_plain;f=alg%2Falphabet.cpp;h=56919199b6c7ccf30c05a6471b95187c6075f150;hp=3e4e5c83ca1455f5bc2e66bef6fc11b1c1712f41;hb=f1724abab87d2e5b160620b10cb81eabf56aadeb;hpb=7d4fbcb6060a60a8ea25ca1303fcaaaf8574f24a diff --git a/alg/alphabet.cpp b/alg/alphabet.cpp index 3e4e5c8..5691919 100644 --- a/alg/alphabet.cpp +++ b/alg/alphabet.cpp @@ -1,3 +1,5 @@ +#include + #include "alg/alphabet.hpp" // some standard dna alphabets @@ -12,6 +14,7 @@ const char *Alphabet::nucleic_cstr = //! the protein alphabet const char *Alphabet::protein_cstr = "AaCcDdEeFfGgHhIiKkLlMmNnPpQqRrSsTtVvWwYy\012\015"; +const char *Alphabet::empty_cstr = ""; const Alphabet& Alphabet::reduced_dna_alphabet() { static Alphabet *a = new Alphabet(reduced_dna_cstr); @@ -33,6 +36,10 @@ const Alphabet& Alphabet::protein_alphabet() { static Alphabet *a = new Alphabet(protein_cstr); return *a; } +const Alphabet& Alphabet::empty_alphabet() { + static Alphabet *a = new Alphabet(empty_cstr); + return *a; +} Alphabet::Alphabet(const char *a) : alphabet(a) @@ -47,7 +54,36 @@ void Alphabet::assign(const Alphabet& a) alphabet_set.insert(alphabet.begin(), alphabet.end()); } +bool operator==(const Alphabet& x, const Alphabet& y) +{ + return x.alphabet == y.alphabet; +} + +std::ostream& operator<<(std::ostream& out, const Alphabet& a) +{ + out << a.alphabet; +} + bool Alphabet::exists(const char c) const { return (alphabet_set.find(c) != alphabet_set.end()); } + +const Alphabet& Alphabet::get_alphabet(AlphabetRef alpha) +{ + switch (alpha) { + case ::reduced_dna_alphabet: + return Alphabet::reduced_dna_alphabet(); + case ::reduced_rna_alphabet: + return Alphabet::reduced_rna_alphabet(); + case ::reduced_nucleic_alphabet: + return Alphabet::reduced_nucleic_alphabet(); + case ::nucleic_alphabet: + return Alphabet::nucleic_alphabet(); + case ::protein_alphabet: + return Alphabet::protein_alphabet(); + default: + throw std::runtime_error("unrecognized alphabet type"); + break; + } +} \ No newline at end of file