Sha256: c0dede69087441e49c7a933553d5bf27420946ea1a2e73bad0a10dea8bf3e4bb
Contents?: true
Size: 837 Bytes
Versions: 199
Compression:
Stored size: 837 Bytes
Contents
use std::collections::HashMap; pub struct CodonInfo<'a> { actual_codons: HashMap<&'a str, &'a str> } pub fn parse<'a>(pairs: Vec<(&'a str, &'a str)>) -> CodonInfo<'a> { CodonInfo{ actual_codons: pairs.into_iter().collect() } } impl<'a> CodonInfo<'a> { pub fn name_for(&self, codon: &str) -> Result<&'a str, &'static str> { match self.actual_codons.get(&codon) { Some(name) => Ok(name), None => Err("Invalid") } } pub fn of_rna(&self, strand: &str) -> Result<Vec<&'a str>, &'static str> { strand.chars() .collect::<Vec<char>>() .chunks(3) .map(|chars| self.name_for(&chars.iter().collect::<String>())) .take_while(|result| result.is_err() || result.unwrap() != "stop codon") .collect() } }
Version data entries
199 entries across 199 versions & 1 rubygems