Skip to content

Commit

Permalink
try using a vector of booleans to compute uniq.depth
Browse files Browse the repository at this point in the history
  • Loading branch information
susan-garry committed May 31, 2024
1 parent 0fafe1c commit 16f754f
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions flatgfa/src/cmds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,27 +295,31 @@ pub fn depth(gfa: &flatgfa::FlatGFA) {
// Initialize node depth
let mut depths = vec![0; gfa.segs.len()];
// Initialize uniq_paths
let mut uniq_paths = Vec::<HashSet<&BStr>>::new();
uniq_paths.resize(gfa.segs.len(), HashSet::new());
let mut uniq_depths = vec![0; gfa.segs.len()];

// do not assume that each handle in `gfa.steps()` is unique
for (idx, path) in gfa.paths.all().iter().enumerate() {
let mut seen_path = vec![0; gfa.paths.len()];
for step in &gfa.steps[path.steps] {
let seg_id = step.segment().index();
// Increment depths
depths[seg_id] += 1;
// Update uniq_paths
uniq_paths[seg_id].insert(idx);
if seen_path[idx] == 0 {
uniq_depths[seg_id] += 1;
seen_path[idx] = 1;
}
}
}
// print out depth and depth.uniq
println!("#node.id\tdepth\tdepth.uniq");
for (id, seg) in gfa.segs.items() {
for (idx, seg) in gfa.segs.iter.enumerate() {
let name: u32 = seg.name as u32;
println!(
"{}\t{}\t{}",
name,
depths[id.index()],
uniq_paths[id.index()].len()
depths[idx],
uniq_depths[idx]
);
}
}

0 comments on commit 16f754f

Please sign in to comment.