Skip to content

Commit

Permalink
better documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
xosxos committed Nov 7, 2024
1 parent 4d986b7 commit 498579a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
9 changes: 9 additions & 0 deletions haptk/src/subcommands/bhst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,9 @@ pub fn insert_nodes_to_bhst(
let blacklist = hst
.node_indices()
.par_bridge()
// Filter out nodes that were blacklisted (genotyping data ran out or node haplotypes min_size was reached )
.filter(|n| !blacklist_nodes.contains(n))
// Filter in leaf nodes with 2 or more haplotypes
.filter_map(|node_idx| {
let node = hst.node_weight(node_idx).unwrap();

Expand All @@ -277,6 +279,7 @@ pub fn insert_nodes_to_bhst(
false => None,
}
})
// Search for contradictory genotypes by extending the node haplotype
.map(
|(parent_idx, node)| match find_contradictory_gt_bhst(vcf, &node) {
Err(e) => Err(e),
Expand All @@ -301,10 +304,13 @@ pub fn insert_nodes_to_bhst(

drop(tx);

// Receive nodes for the iterator and add them to the tree
// We use a channel because if genotyping data needes to be dynamically extended, we dont want to lose the already computed nodes
while let Ok((parent_idx, insert_node)) = rx.recv() {
let idx = hst.add_node(insert_node.clone());
hst.add_edge(parent_idx, idx, ());
}

blacklist
}

Expand Down Expand Up @@ -360,6 +366,7 @@ pub fn find_contradictory_gt_bhst(
let nodes = create_nodes_from_buckets(vcf, left, right, oo, oz, zo, zz);
Ok(Some(nodes))
}
// Handle if data ran out on the right side
(Some((left, left_vec)), None) => {
if !vcf.is_genome_wide() {
tracing::warn!(
Expand All @@ -378,6 +385,7 @@ pub fn find_contradictory_gt_bhst(
create_nodes_from_buckets(vcf, left, vcf.coords().last().unwrap(), oo, oz, zo, zz);
Ok(Some(nodes))
}
// Handle if data ran out on the left side
(None, Some((right, right_vec))) => {
if !vcf.is_genome_wide() {
tracing::warn!(
Expand All @@ -403,6 +411,7 @@ pub fn find_contradictory_gt_bhst(
);
Ok(Some(nodes))
}
// Handle if data ran out on both sides
(None, None) => Ok(None),
}
}
Expand Down
12 changes: 10 additions & 2 deletions haptk/src/subcommands/uhst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,13 @@ pub fn insert_nodes_to_uhst(
) -> std::result::Result<Vec<Vec<NodeIndex>>, HaptkError> {
let (tx, rx) = sync_channel(2024);

let outres = hst
// Loop all nodes of the HST
let blacklist = hst
.node_indices()
.par_bridge()
// Filter out nodes that were blacklisted (genotyping data ran out or node haplotypes min_size was reached )
.filter(|n| !blacklist_nodes.contains(n))
// Filter in leaf nodes with 2 or more haplotypes
.filter_map(|node_idx| {
let node = hst.node_weight(node_idx).unwrap();

Expand All @@ -205,6 +208,7 @@ pub fn insert_nodes_to_uhst(
false => None,
}
})
// Search for contradictory genotypes by extending the node haplotype
.map(|(parent_idx, node)| {
match find_contradictory_gt_uhst(vcf, start_coord, &node, direction) {
Err(e) => Err(e),
Expand Down Expand Up @@ -240,11 +244,14 @@ pub fn insert_nodes_to_uhst(

drop(tx);

// Receive nodes for the iterator and add them to the tree
// We use a channel because if genotyping data needes to be dynamically extended, we dont want to lose the already computed nodes
while let Ok((parent_idx, insert_node)) = rx.recv() {
let idx = hst.add_node(insert_node.clone());
hst.add_edge(parent_idx, idx, ());
}
outres

blacklist
}

#[doc(hidden)]
Expand Down Expand Up @@ -308,6 +315,7 @@ pub fn find_contradictory_gt_uhst(
);
}

// If data ran out and no contradictory genotypes were found, return none
Ok(None)
}

Expand Down

0 comments on commit 498579a

Please sign in to comment.