pub struct Alphabet {
pub symbols: BitSet,
}
Expand description
Representation of an alphabet.
Fields§
§symbols: BitSet
Implementations§
source§impl Alphabet
impl Alphabet
sourcepub fn new<C, T>(symbols: T) -> Selfwhere
C: Borrow<u8>,
T: IntoIterator<Item = C>,
pub fn new<C, T>(symbols: T) -> Selfwhere C: Borrow<u8>, T: IntoIterator<Item = C>,
Create new alphabet from given symbols.
Complexity: O(n), where n is the number of symbols in the alphabet.
Example
use bio::alphabets;
// Create an alphabet (note that a DNA alphabet is already available in bio::alphabets::dna).
let dna_alphabet = alphabets::Alphabet::new(b"ACGTacgt");
// Check whether a given text is a word over the alphabet.
assert!(dna_alphabet.is_word(b"GAttACA"));
sourcepub fn insert(&mut self, a: u8)
pub fn insert(&mut self, a: u8)
Insert symbol into alphabet.
Complexity: O(1)
Example
use bio::alphabets;
let mut dna_alphabet = alphabets::Alphabet::new(b"ACGTacgt");
assert!(!dna_alphabet.is_word(b"N"));
dna_alphabet.insert(78);
assert!(dna_alphabet.is_word(b"N"));
sourcepub fn is_word<C, T>(&self, text: T) -> boolwhere
C: Borrow<u8>,
T: IntoIterator<Item = C>,
pub fn is_word<C, T>(&self, text: T) -> boolwhere C: Borrow<u8>, T: IntoIterator<Item = C>,
Check if given text is a word over the alphabet.
Complexity: O(n), where n is the length of the text.
Example
use bio::alphabets;
let dna_alphabet = alphabets::Alphabet::new(b"ACGTacgt");
assert!(dna_alphabet.is_word(b"GAttACA"));
assert!(!dna_alphabet.is_word(b"42"));
sourcepub fn max_symbol(&self) -> Option<u8>
pub fn max_symbol(&self) -> Option<u8>
Return lexicographically maximal symbol.
Complexity: O(n), where n is the number of symbols in the alphabet.
Example
use bio::alphabets;
let dna_alphabet = alphabets::Alphabet::new(b"acgtACGT");
assert_eq!(dna_alphabet.max_symbol(), Some(116)); // max symbol is "t"
let empty_alphabet = alphabets::Alphabet::new(b"");
assert_eq!(empty_alphabet.max_symbol(), None);
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Return size of the alphabet.
Upper and lower case representations of the same character are counted as distinct characters.
Complexity: O(n), where n is the number of symbols in the alphabet.
Example
use bio::alphabets;
let dna_alphabet = alphabets::Alphabet::new(b"acgtACGT");
assert_eq!(dna_alphabet.len(), 8);
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Is this alphabet empty?
Complexity: O(n), where n is the number of symbols in the alphabet.
Example
use bio::alphabets;
let dna_alphabet = alphabets::Alphabet::new(b"acgtACGT");
assert!(!dna_alphabet.is_empty());
let empty_alphabet = alphabets::Alphabet::new(b"");
assert!(empty_alphabet.is_empty());
sourcepub fn intersection(&self, other: &Alphabet) -> Self
pub fn intersection(&self, other: &Alphabet) -> Self
Return a new alphabet taking the intersect between this and other.
Example
use bio::alphabets;
let alpha_a = alphabets::Alphabet::new(b"acgtACGT");
let alpha_b = alphabets::Alphabet::new(b"atcgMVP");
let intersect_alpha = alpha_a.intersection(&alpha_b);
assert_eq!(intersect_alpha, alphabets::Alphabet::new(b"atcg"));
sourcepub fn difference(&self, other: &Alphabet) -> Self
pub fn difference(&self, other: &Alphabet) -> Self
Return a new alphabet taking the difference between this and other.
Example
use bio::alphabets;
let dna_alphabet = alphabets::Alphabet::new(b"acgtACGT");
let dna_alphabet_upper = alphabets::Alphabet::new(b"ACGT");
let dna_lower = dna_alphabet.difference(&dna_alphabet_upper);
assert_eq!(dna_lower, alphabets::Alphabet::new(b"atcg"));
sourcepub fn union(&self, other: &Alphabet) -> Self
pub fn union(&self, other: &Alphabet) -> Self
Return a new alphabet taking the union between this and other.
Example
use bio::alphabets;
let dna_alphabet = alphabets::Alphabet::new(b"ATCG");
let tokenize_alpha = alphabets::Alphabet::new(b"?|");
let alpha = dna_alphabet.union(&tokenize_alpha);
assert_eq!(alpha, alphabets::Alphabet::new(b"ATCG?|"));
Trait Implementations§
source§impl Ord for Alphabet
impl Ord for Alphabet
source§impl PartialEq<Alphabet> for Alphabet
impl PartialEq<Alphabet> for Alphabet
source§impl PartialOrd<Alphabet> for Alphabet
impl PartialOrd<Alphabet> for Alphabet
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl Eq for Alphabet
impl StructuralEq for Alphabet
impl StructuralPartialEq for Alphabet
Auto Trait Implementations§
impl RefUnwindSafe for Alphabet
impl Send for Alphabet
impl Sync for Alphabet
impl Unpin for Alphabet
impl UnwindSafe for Alphabet
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.