Skip to main content

DebruijnGraph

Struct DebruijnGraph 

Source
pub struct DebruijnGraph<K: Hash, D> {
    pub base: BaseGraph<K, D>,
    /* private fields */
}
Expand description

A compressed DeBruijn graph carrying auxiliary data on each node of type D. The struct carries sorted index arrays the allow the graph to be walked efficiently.

Fields§

§base: BaseGraph<K, D>

Implementations§

Source§

impl<K: Kmer, D: Debug> DebruijnGraph<K, D>

Source

pub fn len(&self) -> usize

Total number of nodes in the DeBruijn graph

Source

pub fn is_empty(&self) -> bool

Source

pub fn shrink_to_fit(&mut self)

shrink the storage of the DebruijnGraph to fit its contents

Source

pub fn get_node(&self, node_id: usize) -> Node<'_, K, D>

Get a node given it’s node_id

Source

pub fn get_node_kmer(&self, node_id: usize) -> NodeKmer<'_, K, D>

Get a node given it’s node_id

Source

pub fn iter_nodes(&self) -> NodeIter<'_, K, D>

Return an iterator over all nodes in the graph

Find a link in the graph, possibly handling a RC switch.

Source

pub fn is_compressed<S: CompressionSpec<D>>( &self, spec: &S, ) -> Option<(usize, usize)>

Check whether the graph is fully compressed. Return None if it’s compressed, otherwise return Some(node1, node2) representing a pair of node that could be collapsed. Probably only useful for testing.

Source

pub fn fix_exts(&mut self, valid_nodes: Option<&BitSet>)

Remove non-existent extensions that may be created due to filtered kmers

if valid_nodes if None, all nodes are valid

Source

pub fn get_valid_exts( &self, node_id: usize, valid_nodes: Option<&BitSet>, ) -> Exts

Source

pub fn mut_data(&mut self, node_id: usize) -> &mut D

mutable reference to the auxiliary data of the node node_id

Source

pub fn max_path<F, F2>(&self, score: F, solid_path: F2) -> Vec<(usize, Dir)>
where F: Fn(&D) -> f32, F2: Fn(&D) -> bool,

Find the highest-scoring, unambiguous path in the graph. Each node get a score given by score. Any node where solid_path(node) == True are valid paths - paths will be terminated if there are multiple valid paths emanating from a node.

Source

pub fn max_path_comp<F, F2>( &self, score: F, solid_path: F2, ) -> Vec<VecDeque<(usize, Dir)>>
where F: Fn(&D) -> f32, F2: Fn(&D) -> bool,

Find the highest-scoring, unambiguous path in the graph. Each node get a score given by score. Any node where solid_path(node) == True are valid paths - paths will be terminated if there are multiple valid paths emanating from a node. Returns vec with path for each component

Source

pub fn iter_max_path_comp<F, F2>( &self, score: F, solid_path: F2, ) -> PathCompIter<'_, K, D, F, F2>
where F: Fn(&D) -> f32, F2: Fn(&D) -> bool,

Source

pub fn path_to_fasta<F, F2>( &self, f: &mut dyn Write, path_iter: PathCompIter<'_, K, D, F, F2>, return_lens: bool, ) -> (Vec<usize>, Vec<usize>)
where F: Fn(&D) -> f32, F2: Fn(&D) -> bool,

write the paths from iter_max_path_comp to a fasta file

Source

pub fn sequence_of_path<'a, I: 'a + Iterator<Item = &'a (usize, Dir)>>( &self, path: I, ) -> DnaString

Get the sequence of a path through the graph. The path is given as a sequence of node_id integers

Source

pub fn map_transcripts<P>( &self, path: P, translator: &mut Translator, ) -> Result<Vec<Box<[ID]>>, String>
where P: AsRef<Path>,

map sequences from a fasta reference to the nodes of a completely uncompressed debruijn graph

the IDs are stored with the node if the k-mer occured in the reference

Source

pub fn map_transcripts_to_edges<P>( &self, path: P, translator: &mut Translator, ) -> Result<Vec<EdgeMap>, String>
where P: AsRef<Path>,

map sequences from a fasta reference to the edges of a completely uncompressed debruijn graph

the IDs are stored with the edges if the two k-mers occured together in the reference

Source

pub fn to_dot<P, FN, FE>(&self, path: P, node_label: &FN, edge_label: &FE)
where P: AsRef<Path>, FN: Fn(&Node<'_, K, D>) -> String, FE: Fn(&Node<'_, K, D>, u8, Dir, bool) -> String,

Write the graph to a dot file

§Arguments:
  • path: path to the output file
  • node_label: closure taking Node<K, D> and returning a string containing commands for dot nodes, e.g. Node::node_dot_default
  • edge_label: closure taking Node<K, D>, the base as a u8, the incoming Dir of the edge, e.g. Node::edge_dot_default and if the neighbor is flipped - returns a string containing commands for dot edges,
Source

pub fn to_dot_with_path<P, FE, DI>( &self, path: P, edge_label: &FE, colors: &Colors<'_, D, DI>, translator: &Translator, config: &SummaryConfig, translate_id_groups: bool, )
where P: AsRef<Path>, D: SummaryData<DI>, FE: Fn(&Node<'_, K, D>, u8, Dir, bool) -> String,

Write the graph to a dot file, highlight the nodes which form the “best” path, according to PathCompIter, with the number of occurences as the score and solid_path always true. The nodes are formatted according to Node::node_dot_default.

§Arguments:
  • path: path to the output file
  • edge_label: closure taking Node<K, D>, the base as a u8, the incoming Dir of the edge, e.g. Node::edge_dot_default and if the neighbor is flipped - returns a string containing commands for dot edges,
  • colors: a Colors with the color settings for the graph
  • translator: a Translator which translates tags or IDs to strings
  • config: a SummaryConfig which contains settings for the graph
Source

pub fn to_dot_parallel<P, FN, FE>( &self, path: P, node_label: &FN, edge_label: &FE, )
where D: Sync, K: Sync, P: AsRef<Path> + Display + Sync, FN: Fn(&Node<'_, K, D>) -> String + Sync, FE: Fn(&Node<'_, K, D>, u8, Dir, bool) -> String + Sync,

Write the graph to a dot file in parallel Will write in to n_threads files simultaniously, then go though the files and add the contents to a larger file, and delete the small files.

§Arguments:
  • path: path to the output file
  • node_label: closure taking Node<K, D> and returning a string containing commands for dot nodes
  • edge_label: closure taking Node<K, D>, the base as a u8, the incoming Dir of the edge and if the neighbor is flipped - returns a string containing commands for dot edges,
Source

pub fn to_dot_partial<P, FN, FE>( &self, path: P, node_label: &FN, edge_label: &FE, nodes: &[usize], )
where P: AsRef<Path>, FN: Fn(&Node<'_, K, D>) -> String, FE: Fn(&Node<'_, K, D>, u8, Dir, bool) -> String,

Write part of the graph to a dot file

§Arguments:
  • path: path to the output file
  • node_label: closure taking Node<K, D> and returning a string containing commands for dot nodes
  • edge_label: closure taking Node<K, D>, the base as a u8, the incoming Dir of the edge and if the neighbor is flipped - returns a string containing commands for dot edges,
  • nodes: Vec<usize> listing all IDs of nodes which should be included
Source

pub fn to_gfa<P: AsRef<Path>>(&self, gfa_out: P) -> Result<(), Error>

Write the graph to GFA format

Source

pub fn write_gfa(&self, wtr: &mut impl Write) -> Result<(), Error>

Source

pub fn to_gfa_with_tags<P: AsRef<Path>, F: Fn(&Node<'_, K, D>) -> String>( &self, gfa_out: P, tag_func: F, ) -> Result<(), Error>

Write the graph to GFA format

Source

pub fn to_gfa_otags_parallel<P: AsRef<Path> + Display + Sync, F: Fn(&Node<'_, K, D>) -> String + Sync>( &self, gfa_out: P, tag_func: Option<&F>, ) -> Result<(), Error>
where K: Sync, D: Sync,

Write the graph to GFA format, with multithreading, pass tag_func=None to write without tags

Source

pub fn to_gfa_partial<P: AsRef<Path>, F: Fn(&Node<'_, K, D>) -> String>( &self, gfa_out: P, tag_func: Option<&F>, nodes: Vec<usize>, ) -> Result<(), Error>

Write the graph to GFA format

Source

pub fn to_tsv<P, F>( &self, path: P, data_format: F, ) -> Result<(), Box<dyn Error>>
where F: Fn(&Node<'_, K, D>) -> String, P: AsRef<Path> + Display,

save the graph as a tsv file with custom formatting for the node data

Source

pub fn to_json_3d<P, FN, FE>( &self, path: P, node_properties: &FN, edge_properties: &FE, partial_nodes: Option<&Vec<usize>>, ) -> Result<(), Box<dyn Error>>
where P: AsRef<Path>, FN: Fn(&Node<'_, K, D>) -> String, FE: Fn(&Node<'_, K, D>, usize, u8, Dir, bool) -> String,

write the graph or parts of the graph to a json file to view in 3d

Source

pub fn print(&self)

Print a text representation of the graph.

Source

pub fn print_with_data(&self)

Source

pub fn max_path_beam<F, F2>( &self, beam: usize, score: F, _solid_path: F2, ) -> Vec<(usize, Dir)>
where F: Fn(&D) -> f32, F2: Fn(&D) -> bool,

Source

pub fn iter_components(&self) -> IterComponents<'_, K, D>

Source

pub fn components_i(&self) -> Vec<Vec<usize>>

iteratively returns 2D Vec with node_ids grouped according to the connected components they form

Source

pub fn components_r(&self) -> Vec<Vec<usize>>

recursively detects which nodes form separate graph components returns 2D vector with node ids per component (may lead to stack overflow)

Source

pub fn iter_edges(&self) -> EdgeIter<'_, K, D>

iterate over all edges of the graph, item: (node, ext base, ext dir, target node)

Source

pub fn find_bad_nodes<F: Fn(&Node<'_, K, D>) -> bool>( &self, valid: F, ) -> Vec<usize>

Source§

impl<K: Kmer, SD: Debug> DebruijnGraph<K, SD>

Source

pub fn create_colors<'a, 'b: 'a, DI>( &'a self, config: &SummaryConfig, color_mode: ColorMode<'b>, ) -> Colors<'b, SD, DI>
where SD: SummaryData<DI>,

Source

pub fn fix_edge_data<DI>(&mut self)
where SD: SummaryData<DI>,

crate::EdgeMult and [] will contain hanging edges if the nodes were filtered

Source

pub fn filter_edges<DI>(&mut self, min: u32) -> Result<(), String>
where SD: SummaryData<DI>,

if there are crate::EdgeMults in the data, prune the graph by removing edges that have a low coverage

Source

pub fn remove_lq_splits<DI>( &mut self, min_quality: BaseQuality, ) -> Result<(), String>
where SD: SummaryData<DI>,

if a node has a connection to a high quality node and low quality nodes in the same direction, remove the connections to the low quality ndoes

Source

pub fn remove_lq_paths<DI>( &mut self, min_quality: BaseQuality, max_path_fac: usize, ) -> Result<(), String>
where SD: SummaryData<DI>,

remove bubbles/ladders and tips in which one path has a quality lower than the given min_quality. The method continues searching on a path for a maximum of (`max_path_fac`` * k - 1).

Source

pub fn remove_lc_paths<DI>( &mut self, max_path_fac: usize, min_diff_factor: u32, max_avg_low_cov: f32, ) -> Result<(), String>
where SD: SummaryData<DI>,

remove bubbles/ladders and tips in which one path has a lower coverage than the alternative path. The method continues searching on a path for a maximum of (max_path_fac`` * k - 1). The path is only removed if the average coverage of the lower path is below max_avg_low_covand the average coverage is at leastmin_diff_factor` times higher.

Source

pub fn remove_ladders<DI, P>( &mut self, min_diff_factor: u32, max_avg_low_cov: f32, out_path: Option<P>, ) -> Result<(), String>
where SD: SummaryData<DI>, P: AsRef<Path>,

remove simple ladder structures (bubbles) caused by 1-base sequencing errors from the graph

graph must contain edge mults and be stranded this function will likely leave tips on the graph, so it is recommended to run DebruijnGraph::remove_tips afterwards

ladder structure refers to bubbles where one side has been compressed into one node but the other has low compression, due to differences in coverage and thus data variance, leading to a ladder-like appearance

Source

pub fn remove_tips<DI, P>( &mut self, min_diff_factor: u32, max_avg_tip_cov: f32, out_path: Option<P>, ) -> Result<(), String>
where SD: SummaryData<DI>, P: AsRef<Path>,

remove tips from the graph, reqires the graoh to have edge mults and be stranded it is recommended to use this function after DebruijnGraph::remove_ladders, since the latter will likely leave tips in the graph

Source

pub fn check_edge_truth<DI>(&self, node_id_1: usize, node_id_2: usize) -> bool
where SD: SummaryData<DI>,

use ids mapped to nodes to check if the nodes of an edge were mapped to the same id returns false if mapped ids are not available

Source

pub fn check_edge_truth_emap<DI>( &self, node_id_1: usize, node_id_2: usize, ) -> bool
where SD: SummaryData<DI>,

use ids mapped to edges to check if the edge is a true edge returns false if mapped ids are not available or if the nodes are not connected

Trait Implementations§

Source§

impl<K: Debug + Hash, D: Debug> Debug for DebruijnGraph<K, D>

Source§

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

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

impl<'de, K, D> Deserialize<'de> for DebruijnGraph<K, D>
where K: Deserialize<'de> + Hash, D: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<'a, K: Kmer + 'a, D: Debug + 'a> IntoIterator for &'a DebruijnGraph<K, D>

Source§

type Item = NodeKmer<'a, K, D>

The type of the elements being iterated over.
Source§

type IntoIter = NodeIntoIter<'a, K, D>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<K, D> Serialize for DebruijnGraph<K, D>
where K: Serialize + Hash, D: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<K, D> Freeze for DebruijnGraph<K, D>

§

impl<K, D> RefUnwindSafe for DebruijnGraph<K, D>

§

impl<K, D> Send for DebruijnGraph<K, D>
where K: Send, D: Send,

§

impl<K, D> Sync for DebruijnGraph<K, D>
where K: Sync, D: Sync,

§

impl<K, D> Unpin for DebruijnGraph<K, D>
where K: Unpin, D: Unpin,

§

impl<K, D> UnsafeUnpin for DebruijnGraph<K, D>

§

impl<K, D> UnwindSafe for DebruijnGraph<K, D>
where K: UnwindSafe, D: UnwindSafe,

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.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,