pub struct SaProtTokenizer { /* private fields */ }Expand description
A tokenizer built from SaProt’s vocab.txt.
Implementations§
Source§impl SaProtTokenizer
impl SaProtTokenizer
Sourcepub fn from_vocab_txt(contents: &str) -> Result<Self>
pub fn from_vocab_txt(contents: &str) -> Result<Self>
Parse a vocab.txt: one token per line, line number is the id.
Rejects a file whose special tokens are absent or misplaced, since the
ids are load-bearing — <cls> and <eos> wrap every sequence, and a
silently-wrong <unk> would turn unknown residues into a real amino
acid rather than an unknown.
Sourcepub fn token_to_id(&self, token: &str) -> Option<u32>
pub fn token_to_id(&self, token: &str) -> Option<u32>
Look up a token’s id.
Sourcepub fn residue_count(&self, sequence: &str) -> usize
pub fn residue_count(&self, sequence: &str) -> usize
How many residues sequence encodes.
A trailing odd character is its own (malformed) residue rather than
being dropped, so encode can report it as <unk>
instead of silently shortening the sequence.
Sourcepub fn encode(&self, sequence: &str) -> Vec<u32>
pub fn encode(&self, sequence: &str) -> Vec<u32>
Encode a SaProt sequence to token ids, without special tokens.
Unknown pairs map to <unk> rather than erroring: a residue whose 3Di
state could not be determined is written with a # placeholder in
practice, and refusing the whole sequence for one such residue would be
unhelpful.
Trait Implementations§
Source§impl Clone for SaProtTokenizer
impl Clone for SaProtTokenizer
Source§fn clone(&self) -> SaProtTokenizer
fn clone(&self) -> SaProtTokenizer
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for SaProtTokenizer
impl RefUnwindSafe for SaProtTokenizer
impl Send for SaProtTokenizer
impl Sync for SaProtTokenizer
impl Unpin for SaProtTokenizer
impl UnsafeUnpin for SaProtTokenizer
impl UnwindSafe for SaProtTokenizer
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more