use std::str::FromStr;
#[derive(Debug)]
pub enum Nucleotide {
A,
T,
C,
G,
N,
}
impl Nucleotide {
pub fn from_ascii(asc: u8) -> Option<Self> {
Some(match asc {
b'A' | b'a' => Nucleotide::A,
b'T' | b't' => Nucleotide::T,
b'C' | b'c' => Nucleotide::C,
b'G' | b'g' => Nucleotide::G,
b'N' => Nucleotide::N,
_ => return None,
})
}
}
impl FromStr for Nucleotide {
type Err = ();
fn from_str(s: &str) -> Result<Self, ()> {
Ok(match s {
"A" | "a" => Nucleotide::A,
"T" | "t" => Nucleotide::T,
"C" | "c" => Nucleotide::C,
"G" | "g" => Nucleotide::G,
"N" => Nucleotide::N,
_ => {
return Err(());
}
})
}
}
impl From<u8> for Nucleotide {
fn from(what: u8) -> Self {
match what {
1 => Nucleotide::A,
2 => Nucleotide::C,
4 => Nucleotide::G,
8 => Nucleotide::T,
_ => Nucleotide::N,
}
}
}