AmbiAmino

Struct AmbiAmino 

Source
pub struct AmbiAmino(/* private fields */);
Expand description

Ambiguous amino acid

Note that AmbiAmino always represents at least one possible amino acid; there is no such thing as an empty/null AmbiAmino. Also beware that ambi_amino.to_string().parse() is lossy because there are too many AmbiAminos to represent in a single character; anything without a standard character will be displayed as "X" but "X" is parsed as a maximally ambiguous AmbiAmino. However, the Debug implementation will exactly represent the AmbiAmino at the cost of being 1-25 characters long.

For details, see: https://en.wikipedia.org/wiki/FASTA_format#Sequence_representation

Beware that AmbiAmino’s order isn’t alphabetic.

Implementations§

Source§

impl AmbiAmino

Source

pub const Stop: Self = Self::STOP

Translation stop (alias for consistency with Amino::Stop)

Source

pub const STOP: Self

Translation stop

Source

pub const A: Self

Alanine

Source

pub const B: Self

Aspartic acid (D) or asparagine (N)

Source

pub const C: Self

Cysteine

Source

pub const D: Self

Aspartic acid

Source

pub const E: Self

Glutamic acid

Source

pub const F: Self

Phenylalanine

Source

pub const G: Self

Glycine

Source

pub const H: Self

Histidine

Source

pub const I: Self

Isoleucine

Source

pub const J: Self

Leucine (L) or isoleucine (I)

Source

pub const K: Self

Lysine

Source

pub const L: Self

Leucine

Source

pub const M: Self

Methionine

Source

pub const N: Self

Asparagine

Source

pub const O: Self

Pyrrolysine

Source

pub const P: Self

Proline,

Source

pub const Q: Self

Glutamine

Source

pub const R: Self

Arginine

Source

pub const S: Self

Serine

Source

pub const T: Self

Threonine

Source

pub const U: Self

Selenocysteine

Source

pub const V: Self

Valine

Source

pub const W: Self

Tryptophan

Source

pub const Y: Self

Tyrosine

Source

pub const Z: Self

Glutamic acid (E) or glutamine (Q)

Source

pub const X: Self

Any amino acid

Note that this doesn’t perfectly round-trip. Any ambiguous amino that can’t be represented with a single-letter code will be displayed as “X” but “X” will be parsed as the X constant, which refers to a maximally ambiguous AmbiAmino.

Source

pub fn to_bits(self) -> NonZeroU32

Cast AmbiAmino to NonZeroU32.

No particular representation is promised and the exact values are not part of stability guarantees.

Source

pub fn to_str(self) -> &'static str

Return uppercase string representation

Note that anything without a single-character representation will result in "X". Use Debug formatting if you want a lossless representation.

§Examples
use nucs::AmbiAmino;

assert_eq!(AmbiAmino::A.to_str(), "A");
assert_eq!(AmbiAmino::STOP.to_str(), "*");
assert_eq!((AmbiAmino::D | AmbiAmino::N).to_str(), "B");
assert_eq!((AmbiAmino::D | AmbiAmino::E).to_str(), "X");
Source

pub const fn from_ascii(ascii: u8) -> Result<Self, ParseSymbolError>

Construct from ASCII representation

§Errors

Returns ParseSymbolError if the given byte isn’t a letter or *.

§Examples
use nucs::AmbiAmino;

assert_eq!(AmbiAmino::from_ascii(b'A'), Ok(AmbiAmino::A));
assert_eq!(AmbiAmino::from_ascii(b'*'), Ok(AmbiAmino::STOP));
assert_eq!(AmbiAmino::from_ascii(b'X'), Ok(AmbiAmino::X));
assert!(AmbiAmino::from_ascii(b'.').is_err());
Source

pub fn to_ascii(self) -> u8

Return uppercase ASCII representation

See to_str for caveats.

§Examples
use nucs::AmbiAmino;

assert_eq!(AmbiAmino::A.to_ascii(), b'A');
assert_eq!(AmbiAmino::STOP.to_ascii(), b'*');
assert_eq!((AmbiAmino::D | AmbiAmino::N).to_ascii(), b'B');
assert_eq!((AmbiAmino::D | AmbiAmino::E).to_ascii(), b'X');
Source

pub const fn lit<const N: usize>(literal: &[u8; N]) -> [AmbiAmino; N]

Construct AmbiAmino array from literal without allocating.

§Examples
use nucs::AmbiAmino;

let aas1 = AmbiAmino::lit(b"TOO*LONG");
// ...is shorthand for...
let aas2 = [
    AmbiAmino::T, AmbiAmino::O, AmbiAmino::O, AmbiAmino::STOP,
    AmbiAmino::L, AmbiAmino::O, AmbiAmino::N, AmbiAmino::G
];

assert_eq!(aas1, aas2);
§Panics

This panics if the supplied literal isn’t valid. Whitespace is NOT allowed because the returned array must have the same length.

Source

pub fn iter(self) -> AmbiAminoIter

Return iterator of Aminos that this ambiguous amino acid could be.

The iterator is guaranteed to return things in sorted order and without duplicates, and its contents are guaranteed to recompose into this AmbiAmino via BitOr.

§Examples
use nucs::{AmbiAmino, Amino};

let aa = AmbiAmino::A | AmbiAmino::B | AmbiAmino::C;
assert!(aa.iter().eq(Amino::lit(b"ACDN")));

Trait Implementations§

Source§

impl AsMut<AmbiAmino> for AmbiAmino

Source§

fn as_mut(&mut self) -> &mut AmbiAmino

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsRef<AmbiAmino> for AmbiAmino

Source§

fn as_ref(&self) -> &AmbiAmino

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl BitOr<&AmbiAmino> for &Amino

Source§

type Output = AmbiAmino

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: &AmbiAmino) -> Self::Output

Performs the | operation. Read more
Source§

impl BitOr<&Amino> for &AmbiAmino

Source§

type Output = AmbiAmino

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: &Amino) -> Self::Output

Performs the | operation. Read more
Source§

impl BitOr<AmbiAmino> for Amino

Source§

type Output = AmbiAmino

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: AmbiAmino) -> Self::Output

Performs the | operation. Read more
Source§

impl BitOr<Amino> for AmbiAmino

Source§

type Output = AmbiAmino

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Amino) -> Self::Output

Performs the | operation. Read more
Source§

impl BitOr for &AmbiAmino

Source§

type Output = AmbiAmino

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: &AmbiAmino) -> Self::Output

Performs the | operation. Read more
Source§

impl BitOr for AmbiAmino

Source§

type Output = AmbiAmino

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: AmbiAmino) -> Self::Output

Performs the | operation. Read more
Source§

impl BitOrAssign<&AmbiAmino> for AmbiAmino

Source§

fn bitor_assign(&mut self, rhs: &AmbiAmino)

Performs the |= operation. Read more
Source§

impl BitOrAssign<&Amino> for AmbiAmino

Source§

fn bitor_assign(&mut self, rhs: &Amino)

Performs the |= operation. Read more
Source§

impl BitOrAssign<Amino> for AmbiAmino

Source§

fn bitor_assign(&mut self, rhs: Amino)

Performs the |= operation. Read more
Source§

impl BitOrAssign for AmbiAmino

Source§

fn bitor_assign(&mut self, rhs: AmbiAmino)

Performs the |= operation. Read more
Source§

impl Clone for AmbiAmino

Source§

fn clone(&self) -> AmbiAmino

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AmbiAmino

Displays single-character code when possible, otherwise all possibilities.

Note that when falling back to bracket-enclosed possibilities, this doesn’t use ambiguity codes like B, J or Z.

use nucs::AmbiAmino;

assert_eq!(format!("{:?}", AmbiAmino::S), "S");
assert_eq!(format!("{:?}", AmbiAmino::L | AmbiAmino::I), "J");
assert_eq!(format!("{:?}", AmbiAmino::A | AmbiAmino::B), "[ADN]");
assert_eq!(format!("{:?}", AmbiAmino::X), "X");
Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AmbiAmino

Source§

fn default() -> AmbiAmino

Returns the “default value” for a type. Read more
Source§

impl Display for AmbiAmino

Displays a single-character code, falling back to X.

§Examples

use nucs::AmbiAmino;

assert_eq!(AmbiAmino::S.to_string(), "S");
assert_eq!((AmbiAmino::L | AmbiAmino::I).to_string(), "J");
assert_eq!((AmbiAmino::A | AmbiAmino::B).to_string(), "X");
assert_eq!(AmbiAmino::X.to_string(), "X");
// Note that despite the same representation they're not actually the same:
assert_ne!(AmbiAmino::A | AmbiAmino::B, AmbiAmino::X);
Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Amino> for AmbiAmino

Source§

fn from(amino: Amino) -> Self

Converts to this type from the input type.
Source§

impl FromStr for AmbiAmino

Source§

type Err = ParseSymbolError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for AmbiAmino

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl IntoIterator for &AmbiAmino

Source§

type IntoIter = AmbiAminoIter

Which kind of iterator are we turning this into?
Source§

type Item = Amino

The type of the elements being iterated over.
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for AmbiAmino

Source§

type IntoIter = AmbiAminoIter

Which kind of iterator are we turning this into?
Source§

type Item = Amino

The type of the elements being iterated over.
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl Ord for AmbiAmino

Source§

fn cmp(&self, other: &AmbiAmino) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq<AmbiAmino> for Amino

Source§

fn eq(&self, other: &AmbiAmino) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<Amino> for AmbiAmino

Source§

fn eq(&self, other: &Amino) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for AmbiAmino

Source§

fn eq(&self, other: &AmbiAmino) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd<AmbiAmino> for Amino

Source§

fn partial_cmp(&self, other: &AmbiAmino) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl PartialOrd<Amino> for AmbiAmino

Source§

fn partial_cmp(&self, other: &Amino) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl PartialOrd for AmbiAmino

Source§

fn partial_cmp(&self, other: &AmbiAmino) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Symbol for AmbiAmino

Source§

type Concrete = Amino

Concrete symbols, i.e. Nuc or Amino
Source§

type Ambiguous = AmbiAmino

Ambiguous symbols, i.e. AmbiNuc or AmbiAmino
Source§

fn to_str(self) -> &'static str

Return uppercase string representation
Source§

fn from_ascii(ascii: u8) -> Result<Self, ParseSymbolError>

Construct from (case-insensitive) ASCII representation Read more
Source§

fn to_ascii(self) -> u8

Return uppercase ASCII representation
Source§

fn lit<const N: usize>(literal: &[u8; N]) -> [Self; N]

Construct array from literal without allocating. Read more
Source§

impl TryFrom<AmbiAmino> for Amino

Source§

type Error = AmbiAmino

The type returned in the event of a conversion error.
Source§

fn try_from(amino: AmbiAmino) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Copy for AmbiAmino

Source§

impl Eq for AmbiAmino

Source§

impl StructuralPartialEq for AmbiAmino

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.