bitnuc

Struct PackedSequence

Source
pub struct PackedSequence { /* private fields */ }

Implementations§

Source§

impl PackedSequence

Source

pub fn new(seq: &[u8]) -> Result<Self, NucleotideError>

Creates a new PackedSequence from a byte slice containing nucleotides.

The input sequence must contain only valid nucleotides (A, C, G, T, case insensitive).

§Examples
use bitnuc::PackedSequence;

let seq = PackedSequence::new(b"ACGT")?;
assert_eq!(seq.len(), 4);
§Errors

Returns NucleotideError::InvalidBase if the input contains non-ACGT characters:

use bitnuc::PackedSequence;

let result = PackedSequence::new(b"ACGN");
assert!(result.is_err());
Source

pub fn len(&self) -> usize

Returns the number of bases in the sequence.

§Examples
use bitnuc::PackedSequence;

let seq = PackedSequence::new(b"ACGT")?;
assert_eq!(seq.len(), 4);
Source

pub fn is_empty(&self) -> bool

Returns true if the sequence contains no bases.

§Examples
use bitnuc::PackedSequence;

let seq = PackedSequence::new(b"")?;
assert!(seq.is_empty());
Source

pub fn get(&self, index: usize) -> Result<u8, NucleotideError>

Returns the nucleotide at the given position.

§Examples
use bitnuc::PackedSequence;

let seq = PackedSequence::new(b"ACGT")?;
assert_eq!(seq.get(0)?, b'A');
assert_eq!(seq.get(3)?, b'T');
§Errors

Returns NucleotideError::IndexOutOfBounds if the index is past the end of the sequence:

use bitnuc::PackedSequence;

let result = seq.get(4);
assert!(result.is_err());
Source

pub fn slice(&self, range: Range<usize>) -> Result<Vec<u8>, NucleotideError>

Returns a subsequence within the given range.

The range is exclusive of the end bound, matching Rust’s standard range behavior.

§Examples

Basic slicing:

use bitnuc::PackedSequence;

let seq = PackedSequence::new(b"ACGTACGT")?;

// Get middle section
assert_eq!(seq.slice(1..5)?, b"CGTA");

// Get prefix
assert_eq!(seq.slice(0..3)?, b"ACG");

// Get suffix
assert_eq!(seq.slice(5..8)?, b"CGT");

Empty slices are allowed:

use bitnuc::PackedSequence;

let seq = PackedSequence::new(b"ACGT")?;
assert_eq!(seq.slice(2..2)?, b"");
§Errors

Returns NucleotideError::InvalidRange in these cases:

Start index greater than end index:

use bitnuc::PackedSequence;

let result = seq.slice(3..2);
assert!(result.is_err());

Range extends past end of sequence:

use bitnuc::PackedSequence;

let result = seq.slice(2..5);
assert!(result.is_err());
Source

pub fn to_vec(&self) -> Result<Vec<u8>, NucleotideError>

Converts the entire packed sequence back to a vector of bytes.

This is equivalent to slice(0..len()) but may be more efficient for full sequence conversion.

§Examples

Basic conversion:

use bitnuc::PackedSequence;

let seq = PackedSequence::new(b"ACGT")?;
assert_eq!(seq.to_vec()?, b"ACGT");

Working with longer sequences:

use bitnuc::PackedSequence;

let original = b"ACGTACGTACGTACGT".to_vec();
let seq = PackedSequence::new(&original)?;
assert_eq!(seq.to_vec()?, original);

Empty sequences:

use bitnuc::PackedSequence;

let seq = PackedSequence::new(b"")?;
assert_eq!(seq.to_vec()?, b"");
§Performance

This method allocates a new vector and performs a full copy of the sequence. For frequent access to subsequences, consider using slice() or individual base access via get() instead.

Trait Implementations§

Source§

impl BaseCount for PackedSequence

Source§

fn base_counts(&self) -> [usize; 4]

Source§

impl Clone for PackedSequence

Source§

fn clone(&self) -> PackedSequence

Returns a copy 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 PackedSequence

Source§

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

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

impl GCContent for PackedSequence

Source§

fn gc_content(&self) -> f64

Source§

impl Hash for PackedSequence

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 PartialEq for PackedSequence

Source§

fn eq(&self, other: &PackedSequence) -> 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 Eq for PackedSequence

Source§

impl StructuralPartialEq for PackedSequence

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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, 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.