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>
impl<K: Kmer, D: Debug> DebruijnGraph<K, D>
pub fn is_empty(&self) -> bool
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
shrink the storage of the DebruijnGraph to fit its contents
Sourcepub fn get_node_kmer(&self, node_id: usize) -> NodeKmer<'_, K, D>
pub fn get_node_kmer(&self, node_id: usize) -> NodeKmer<'_, K, D>
Get a node given it’s node_id
Sourcepub fn iter_nodes(&self) -> NodeIter<'_, K, D> ⓘ
pub fn iter_nodes(&self) -> NodeIter<'_, K, D> ⓘ
Return an iterator over all nodes in the graph
Sourcepub fn find_link(&self, kmer: K, dir: Dir) -> Option<(usize, Dir, bool)>
pub fn find_link(&self, kmer: K, dir: Dir) -> Option<(usize, Dir, bool)>
Find a link in the graph, possibly handling a RC switch.
Sourcepub fn is_compressed<S: CompressionSpec<D>>(
&self,
spec: &S,
) -> Option<(usize, usize)>
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.
Sourcepub fn fix_exts(&mut self, valid_nodes: Option<&BitSet>)
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
pub fn get_valid_exts( &self, node_id: usize, valid_nodes: Option<&BitSet>, ) -> Exts
Sourcepub fn mut_data(&mut self, node_id: usize) -> &mut D
pub fn mut_data(&mut self, node_id: usize) -> &mut D
mutable reference to the auxiliary data of the node node_id
Sourcepub fn max_path<F, F2>(&self, score: F, solid_path: F2) -> Vec<(usize, Dir)>
pub fn max_path<F, F2>(&self, score: F, solid_path: F2) -> Vec<(usize, Dir)>
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.
Sourcepub fn max_path_comp<F, F2>(
&self,
score: F,
solid_path: F2,
) -> Vec<VecDeque<(usize, Dir)>>
pub fn max_path_comp<F, F2>( &self, score: F, solid_path: F2, ) -> Vec<VecDeque<(usize, Dir)>>
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
pub fn iter_max_path_comp<F, F2>( &self, score: F, solid_path: F2, ) -> PathCompIter<'_, K, D, F, F2> ⓘ
Sourcepub 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>)
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>)
write the paths from iter_max_path_comp to a fasta file
Sourcepub fn sequence_of_path<'a, I: 'a + Iterator<Item = &'a (usize, Dir)>>(
&self,
path: I,
) -> DnaString
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
Sourcepub fn map_transcripts<P>(
&self,
path: P,
translator: &mut Translator,
) -> Result<Vec<Box<[ID]>>, String>
pub fn map_transcripts<P>( &self, path: P, translator: &mut Translator, ) -> Result<Vec<Box<[ID]>>, String>
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
Sourcepub fn map_transcripts_to_edges<P>(
&self,
path: P,
translator: &mut Translator,
) -> Result<Vec<EdgeMap>, String>
pub fn map_transcripts_to_edges<P>( &self, path: P, translator: &mut Translator, ) -> Result<Vec<EdgeMap>, String>
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
Sourcepub fn to_dot<P, FN, FE>(&self, path: P, node_label: &FN, edge_label: &FE)
pub fn to_dot<P, FN, FE>(&self, path: P, node_label: &FN, edge_label: &FE)
Write the graph to a dot file
§Arguments:
path: path to the output filenode_label: closure takingNode<K, D>and returning a string containing commands for dot nodes, e.g.Node::node_dot_defaultedge_label: closure takingNode<K, D>, the base as au8, the incomingDirof the edge, e.g.Node::edge_dot_defaultand if the neighbor is flipped - returns a string containing commands for dot edges,
Sourcepub 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,
)
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, )
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 fileedge_label: closure takingNode<K, D>, the base as au8, the incomingDirof the edge, e.g.Node::edge_dot_defaultand if the neighbor is flipped - returns a string containing commands for dot edges,colors: aColorswith the color settings for the graphtranslator: aTranslatorwhich translates tags or IDs to stringsconfig: aSummaryConfigwhich contains settings for the graph
Sourcepub fn to_dot_parallel<P, FN, FE>(
&self,
path: P,
node_label: &FN,
edge_label: &FE,
)
pub fn to_dot_parallel<P, FN, FE>( &self, path: P, node_label: &FN, edge_label: &FE, )
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 filenode_label: closure takingNode<K, D>and returning a string containing commands for dot nodesedge_label: closure takingNode<K, D>, the base as au8, the incomingDirof the edge and if the neighbor is flipped - returns a string containing commands for dot edges,
Sourcepub fn to_dot_partial<P, FN, FE>(
&self,
path: P,
node_label: &FN,
edge_label: &FE,
nodes: &[usize],
)
pub fn to_dot_partial<P, FN, FE>( &self, path: P, node_label: &FN, edge_label: &FE, nodes: &[usize], )
Write part of the graph to a dot file
§Arguments:
path: path to the output filenode_label: closure takingNode<K, D>and returning a string containing commands for dot nodesedge_label: closure takingNode<K, D>, the base as au8, the incomingDirof 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
Sourcepub fn to_gfa<P: AsRef<Path>>(&self, gfa_out: P) -> Result<(), Error>
pub fn to_gfa<P: AsRef<Path>>(&self, gfa_out: P) -> Result<(), Error>
Write the graph to GFA format
pub fn write_gfa(&self, wtr: &mut impl Write) -> Result<(), Error>
Write the graph to GFA format
Write the graph to GFA format, with multithreading,
pass tag_func=None to write without tags
Sourcepub 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>
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
Sourcepub fn to_tsv<P, F>(
&self,
path: P,
data_format: F,
) -> Result<(), Box<dyn Error>>
pub fn to_tsv<P, F>( &self, path: P, data_format: F, ) -> Result<(), Box<dyn Error>>
save the graph as a tsv file with custom formatting for the node data
Sourcepub 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>>
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>>
write the graph or parts of the graph to a json file to view in 3d
pub fn print_with_data(&self)
pub fn max_path_beam<F, F2>( &self, beam: usize, score: F, _solid_path: F2, ) -> Vec<(usize, Dir)>
pub fn iter_components(&self) -> IterComponents<'_, K, D> ⓘ
Sourcepub fn components_i(&self) -> Vec<Vec<usize>>
pub fn components_i(&self) -> Vec<Vec<usize>>
iteratively returns 2D Vec with node_ids grouped according to the connected components they form
Sourcepub fn components_r(&self) -> Vec<Vec<usize>>
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)
Sourcepub fn iter_edges(&self) -> EdgeIter<'_, K, D> ⓘ
pub fn iter_edges(&self) -> EdgeIter<'_, K, D> ⓘ
iterate over all edges of the graph, item: (node, ext base, ext dir, target node)
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>
impl<K: Kmer, SD: Debug> DebruijnGraph<K, SD>
pub fn create_colors<'a, 'b: 'a, DI>(
&'a self,
config: &SummaryConfig,
color_mode: ColorMode<'b>,
) -> Colors<'b, SD, DI>where
SD: SummaryData<DI>,
Sourcepub fn fix_edge_data<DI>(&mut self)where
SD: SummaryData<DI>,
pub fn fix_edge_data<DI>(&mut self)where
SD: SummaryData<DI>,
crate::EdgeMult and [] will contain hanging edges if the nodes were filtered
Sourcepub fn filter_edges<DI>(&mut self, min: u32) -> Result<(), String>where
SD: SummaryData<DI>,
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
Sourcepub fn remove_lq_splits<DI>(
&mut self,
min_quality: BaseQuality,
) -> Result<(), String>where
SD: SummaryData<DI>,
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
Sourcepub fn remove_lq_paths<DI>(
&mut self,
min_quality: BaseQuality,
max_path_fac: usize,
) -> Result<(), String>where
SD: SummaryData<DI>,
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).
Sourcepub 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>,
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.
Sourcepub fn remove_ladders<DI, P>(
&mut self,
min_diff_factor: u32,
max_avg_low_cov: f32,
out_path: Option<P>,
) -> Result<(), String>
pub fn remove_ladders<DI, P>( &mut self, min_diff_factor: u32, max_avg_low_cov: f32, out_path: Option<P>, ) -> Result<(), String>
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
Sourcepub fn remove_tips<DI, P>(
&mut self,
min_diff_factor: u32,
max_avg_tip_cov: f32,
out_path: Option<P>,
) -> Result<(), String>
pub fn remove_tips<DI, P>( &mut self, min_diff_factor: u32, max_avg_tip_cov: f32, out_path: Option<P>, ) -> Result<(), String>
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
Sourcepub fn check_edge_truth<DI>(&self, node_id_1: usize, node_id_2: usize) -> boolwhere
SD: SummaryData<DI>,
pub fn check_edge_truth<DI>(&self, node_id_1: usize, node_id_2: usize) -> boolwhere
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
Sourcepub fn check_edge_truth_emap<DI>(
&self,
node_id_1: usize,
node_id_2: usize,
) -> boolwhere
SD: SummaryData<DI>,
pub fn check_edge_truth_emap<DI>(
&self,
node_id_1: usize,
node_id_2: usize,
) -> boolwhere
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<'de, K, D> Deserialize<'de> for DebruijnGraph<K, D>
impl<'de, K, D> Deserialize<'de> for DebruijnGraph<K, D>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<'a, K: Kmer + 'a, D: Debug + 'a> IntoIterator for &'a DebruijnGraph<K, D>
impl<'a, K: Kmer + 'a, D: Debug + 'a> IntoIterator for &'a DebruijnGraph<K, D>
Auto Trait Implementations§
impl<K, D> Freeze for DebruijnGraph<K, D>
impl<K, D> RefUnwindSafe for DebruijnGraph<K, D>where
K: RefUnwindSafe,
D: RefUnwindSafe,
impl<K, D> Send for DebruijnGraph<K, D>
impl<K, D> Sync for DebruijnGraph<K, D>
impl<K, D> Unpin for DebruijnGraph<K, D>
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> 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
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§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.