Struct MLdBG

Source
pub struct MLdBG {
    pub kmer_size: usize,
    pub ldbgs: Vec<LdBG>,
    pub scores: HashMap<Vec<u8>, f32>,
}
Expand description

Represents a multi-color linked de Bruijn graph, all built with same k-mer size.

Fields§

§kmer_size: usize§ldbgs: Vec<LdBG>§scores: HashMap<Vec<u8>, f32>

Implementations§

Source§

impl MLdBG

Source

pub fn new(kmer_size: usize) -> Self

Create an empty multi-color LdBG.

Source

pub fn from_ldbgs(ldbgs: Vec<LdBG>) -> Self

Create an MLdBG from a vector of LdBGs.

§Arguments
  • ldbgs - A vector of LdBGs.
§Returns

A new MLdBG.

§Panics

This function will panic if the kmer_size of the LdBG being added does not match the kmer_size of the MLdBG. Specifically, it will panic at the assert! statement if the condition ldbg.kmer_size == self.kmer_size is not met.

Source

pub fn push(&mut self, ldbg: LdBG)

Add a LdBG to the MLdBG.

§Arguments
  • ldbg - The LdBG to add.
§Panics

The push function will panic if the kmer_size of the ldbg being added does not match the kmer_size of the MLdBG. Specifically, it will panic at the assert! statement if the condition ldbg.kmer_size == self.kmer_size is not met.

Source

pub fn insert(&mut self, index: usize, ldbg: LdBG)

Insert a LdBG at a specific position in the MLdBG.

Source

pub fn append(&mut self, ldbg: LdBG)

Append a LdBG to the end of the MLdBG.

Source

pub fn append_from_file(&mut self, name: String, seq_path: &PathBuf)

Append an LdBG to the end of the MLdBG, created anew from a fasta file.

Source

pub fn append_from_filtered_file<F>( &mut self, name: String, seq_path: &PathBuf, filter: F, )
where F: Fn(&Record, &HashSet<Vec<u8>>) -> bool,

Append an LdBG to the end of the MLdBG, created from a filtered set of sequences in a fasta file.

This function reads sequences from a specified fasta file, filters them based on a provided condition, and then creates an LdBG from the filtered sequences. The new LdBG is appended to the MLdBG.

§Arguments
  • name - A string representing the name of the new LdBG.
  • seq_path - A reference to a PathBuf representing the path to the fasta file containing the sequences.
  • filter - A closure that takes a fasta record and a set of kmers and returns a boolean indicating whether the record should be included.
§Panics

This function will panic if it cannot read the fasta file.

Source

pub fn score_kmers(self, model_path: &PathBuf) -> Self

Scores the k-mers in the MLdBG using a pre-trained Gradient Boosting Decision Tree (GBDT) model.

This function loads a GBDT model from the specified path and uses it to predict scores for each k-mer in the union of k-mers from all LdBGs in the MLdBG. The scores are stored in the scores field of the MLdBG.

§Arguments
  • model_path - A path to the file containing the pre-trained GBDT model.
§Returns

An updated MLdBG with the k-mer scores populated.

§Panics

This function will panic if the model file cannot be loaded or if the prediction fails.

Source

pub fn collapse(&mut self) -> LdBG

Source

pub fn filter_reads<F>(&mut self, seq_path: &PathBuf, filter: F) -> Vec<Vec<u8>>
where F: Fn(&Record, &HashSet<Vec<u8>>) -> bool,

Filter reads from a fasta file based on a condition.

§Arguments
  • seq_path - A path to the fasta file containing the reads.
  • filter - A closure that takes a fasta record and a set of kmers and returns a boolean.
§Returns

A vector of the kept reads.

§Panics

This function will panic if it cannot read the fasta file.

Source

pub fn union_of_kmers(&self) -> HashSet<Vec<u8>>

Get the union of kmers from all LdBGs in the MLdBG.

Source

pub fn get(&self, index: usize) -> Option<&LdBG>

Get a reference to the LdBG at a specific index.

Source

pub fn iter(&self) -> Iter<'_, LdBG>

Returns an iterator over the LdBGs in the MLdBG.

Source

pub fn iter_mut(&mut self) -> IterMut<'_, LdBG>

Returns a mutable iterator over the LdBGs in the MLdBG.

Source

pub fn clear(&mut self)

Clear all LdBGs from the MLdBG.

Source

pub fn remove(&mut self, index: usize) -> Option<LdBG>

Remove a LdBG from the MLdBG by index.

Source

pub fn len(&self) -> usize

Returns the number of LdBGs in the MLdBG.

Source

pub fn is_empty(&self) -> bool

Check if the MLdBG is empty.

Source

pub fn pop(&mut self) -> Option<LdBG>

Remove and return the last LdBG from the MLdBG.

Source

pub fn pop_if<F>(&mut self, condition: F) -> Option<LdBG>
where F: Fn(&LdBG) -> bool,

Remove and return the LdBG from the MLdBG if it matches a certain condition.

Trait Implementations§

Source§

impl Debug for MLdBG

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for MLdBG

§

impl RefUnwindSafe for MLdBG

§

impl Send for MLdBG

§

impl Sync for MLdBG

§

impl Unpin for MLdBG

§

impl UnwindSafe for MLdBG

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,