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.97 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.96 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.95 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.94 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.93 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.92 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.91 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.90 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.89 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.88 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.87 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.86 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.85 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.84 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.83 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.82 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.81 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.80 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.79 tracks/rust/exercises/protein-translation/example.rs
trackler-2.2.1.78 tracks/rust/exercises/protein-translation/example.rs