Move alphabet type into SeqString
[mussa.git] / alg / alphabet.cpp
index 3e4e5c83ca1455f5bc2e66bef6fc11b1c1712f41..56919199b6c7ccf30c05a6471b95187c6075f150 100644 (file)
@@ -1,3 +1,5 @@
+#include <stdexcept>
+
 #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