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

Version Path
trackler-2.2.1.179 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.178 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.177 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.176 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.175 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.174 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.173 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.172 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.171 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.170 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.169 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.167 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.166 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.165 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.164 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.163 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.162 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.161 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.160 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.159 tracks/rust/exercises/protein-translation/example.rs