pub struct OneHotEncoder { /* private fields */ }Expand description
One-hot encoder for biological sequences.
Encodes sequences as binary matrices where each position is represented as a one-hot vector. For DNA: A=[1,0,0,0], C=[0,1,0,0], G=[0,0,1,0], T=[0,0,0,1]
§Examples
use deepbiop_fa::encode::onehot::{OneHotEncoder, AmbiguousStrategy};
use deepbiop_core::types::EncodingType;
let encoder = OneHotEncoder::new(EncodingType::DNA, AmbiguousStrategy::Skip);
let encoded = encoder.encode(b"ACGT").unwrap();
assert_eq!(encoded.shape(), &[4, 4]); // 4 bases, 4 possible valuesImplementations§
Source§impl OneHotEncoder
impl OneHotEncoder
Sourcepub fn new(
encoding_type: EncodingType,
ambiguous_strategy: AmbiguousStrategy,
) -> OneHotEncoder
pub fn new( encoding_type: EncodingType, ambiguous_strategy: AmbiguousStrategy, ) -> OneHotEncoder
Sourcepub fn with_seed(
encoding_type: EncodingType,
ambiguous_strategy: AmbiguousStrategy,
seed: u64,
) -> OneHotEncoder
pub fn with_seed( encoding_type: EncodingType, ambiguous_strategy: AmbiguousStrategy, seed: u64, ) -> OneHotEncoder
Create a new one-hot encoder with a random seed.
§Arguments
encoding_type- The type of sequence (DNA, RNA, or Protein)ambiguous_strategy- How to handle ambiguous basesseed- Random seed for reproducible random replacements
Sourcepub fn encode(
&self,
sequence: &[u8],
) -> Result<ArrayBase<OwnedRepr<f32>, Dim<[usize; 2]>>, Error>
pub fn encode( &self, sequence: &[u8], ) -> Result<ArrayBase<OwnedRepr<f32>, Dim<[usize; 2]>>, Error>
Encode a single sequence as a one-hot matrix.
§Arguments
sequence- The sequence to encode
§Returns
A 2D array of shape [sequence_length, alphabet_size]
§Errors
Returns an error if:
- The sequence contains invalid characters for the encoding type
- The sequence contains ambiguous bases and strategy is
Skip
Sourcepub fn encode_batch(
&self,
sequences: &[&[u8]],
) -> Result<ArrayBase<OwnedRepr<f32>, Dim<[usize; 3]>>, Error>
pub fn encode_batch( &self, sequences: &[&[u8]], ) -> Result<ArrayBase<OwnedRepr<f32>, Dim<[usize; 3]>>, Error>
Sourcepub fn encoding_type(&self) -> EncodingType
pub fn encoding_type(&self) -> EncodingType
Get the encoding type.
Sourcepub fn ambiguous_strategy(&self) -> AmbiguousStrategy
pub fn ambiguous_strategy(&self) -> AmbiguousStrategy
Get the ambiguous strategy.
Trait Implementations§
Source§impl SequenceEncoder for OneHotEncoder
impl SequenceEncoder for OneHotEncoder
Source§type EncodeOutput = ArrayBase<OwnedRepr<f32>, Dim<[usize; 2]>>
type EncodeOutput = ArrayBase<OwnedRepr<f32>, Dim<[usize; 2]>>
The type of the encoded output Read more
Source§fn encode_sequence(
&self,
seq: &[u8],
qual: Option<&[u8]>,
) -> Result<<OneHotEncoder as SequenceEncoder>::EncodeOutput, Error>
fn encode_sequence( &self, seq: &[u8], qual: Option<&[u8]>, ) -> Result<<OneHotEncoder as SequenceEncoder>::EncodeOutput, Error>
Encodes a biological sequence into a numerical representation Read more
Source§fn expected_output_size(&self, seq_len: usize) -> usize
fn expected_output_size(&self, seq_len: usize) -> usize
Returns the expected size of the encoded output Read more
Auto Trait Implementations§
impl Forget for OneHotEncoder
impl Freeze for OneHotEncoder
impl Move for OneHotEncoder
impl RefUnwindSafe for OneHotEncoder
impl Send for OneHotEncoder
impl Sync for OneHotEncoder
impl Unpin for OneHotEncoder
impl UnsafeUnpin for OneHotEncoder
impl UnwindSafe for OneHotEncoder
Blanket Implementations§
impl<T> Allocation for T
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
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> ⓘ
Converts
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> ⓘ
Converts
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