Skip to content

Commit

Permalink
Rename AminoAcid methods for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
althonos committed Feb 17, 2022
1 parent 7f55a6a commit c4a723b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extern crate proteinogenic;

let residues = "KGILGKLGVVQAGVDFVSGVWAGIKQSAKDHPNA"
.chars()
.map(proteinogenic::AminoAcid::from_code1)
.map(proteinogenic::AminoAcid::from_char)
.map(Result::unwrap);
let s = proteinogenic::smiles(residues)
.expect("failed to generate SMILES string");
Expand All @@ -45,7 +45,7 @@ extern crate proteinogenic;

let residues = "GLPVCGETCVGGTCNTPGCTCSWPVCTRN"
.chars()
.map(proteinogenic::AminoAcid::from_code1)
.map(proteinogenic::AminoAcid::from_char)
.map(Result::unwrap);

let mut p = proteinogenic::Protein::new(residues);
Expand Down Expand Up @@ -75,7 +75,8 @@ extern crate purr;

let sequence = "KGILGKLGVVQAGVDFVSGVWAGIKQSAKDHPNA";
let residues = sequence.chars()
.map(|c| proteinogenic::AminoAcid::from_code1(c).unwrap());
.map(proteinogenic::AminoAcid::from_char)
.map(Result::unwrap);

let mut builder = purr::graph::Builder::new();
proteinogenic::visit(residues, &mut builder);
Expand Down
16 changes: 8 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ pub enum AminoAcid {

impl AminoAcid {
/// Create an `AminoAcid` variant from a 1-letter code.
pub fn from_code1(code: char) -> Result<AminoAcid, UnknownResidue> {
pub fn from_char(code: char) -> Result<AminoAcid, UnknownResidue> {
match code {
'R' => Ok(AminoAcid::Arg),
'H' => Ok(AminoAcid::His),
Expand Down Expand Up @@ -250,7 +250,7 @@ impl AminoAcid {
}

/// Create an `AminoAcid` variant from a 3-letter code.
pub fn from_code3(code: &str) -> Result<AminoAcid, UnknownResidue> {
pub fn from_code(code: &str) -> Result<AminoAcid, UnknownResidue> {
match code {
"Arg" => Ok(AminoAcid::Arg),
"His" => Ok(AminoAcid::His),
Expand Down Expand Up @@ -866,14 +866,14 @@ mod tests {
}

#[test]
fn from_code1() {
assert_eq!(AminoAcid::from_code1('Y'), Ok(AminoAcid::Tyr));
assert_eq!(AminoAcid::from_code1('α'), Err(UnknownResidue));
fn from_char() {
assert_eq!(AminoAcid::from_char('Y'), Ok(AminoAcid::Tyr));
assert_eq!(AminoAcid::from_char('α'), Err(UnknownResidue));
}

#[test]
fn from_code3() {
assert_eq!(AminoAcid::from_code3("Thr"), Ok(AminoAcid::Thr));
assert_eq!(AminoAcid::from_code3("Xyz"), Err(UnknownResidue));
fn from_code() {
assert_eq!(AminoAcid::from_code("Thr"), Ok(AminoAcid::Thr));
assert_eq!(AminoAcid::from_code("Xyz"), Err(UnknownResidue));
}
}

0 comments on commit c4a723b

Please sign in to comment.