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.138 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.137 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.136 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.135 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.134 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.133 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.132 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.131 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.130 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.129 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.128 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.127 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.126 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.125 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.124 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.123 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.122 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.121 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.120 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.119 tracks/rust/exercises/protein-translation/example.rs