Skip to content

Cherry-pick bed-depth command from #259 - #263

Merged
sampsyo merged 17 commits into
mainfrom
beddepth-rebase
May 12, 2026
Merged

sampsyo merged 17 commits into
mainfrom
beddepth-rebase

Conversation

@sampsyo

@sampsyo sampsyo commented May 8, 2026

Copy link
Copy Markdown
Collaborator

Here is my attempt to take the parts from @johnpalsberg's #259 that add the new bed-depth command and put them into a self-contained branch we can review, polish, and merge. Here are some loose ends to address before we finalize this:

  • Does the command really need to read back the file that it just wrote to disk? Or can we stream the output to stdout?
  • Should we delete the other version of this currently in examples/ added in All-Rust window depth example #252? That duplicates compute_windows, for example.
  • Are there parts of this (notably format_float) that we should be importing from existing modules?
  • Comments!

johnpalsberg and others added 10 commits May 8, 2026 15:47
`depth` was renamed to `seg_depth`, and we needed to put `bedcmds` in
the right place (under `ops`).
Just avoiding `*` in imports to make things more understandable.
It looks like code was duplicated across `bedcmds.rs` and `beddepth.rs`,
so let's just keep done.
Includes allowing the `mut_range_bound` lint, which is known to have
false positives for nested loops exactly like this one:
rust-lang/rust-clippy#6072
Let's leave this in its own branch.
@sampsyo
sampsyo force-pushed the beddepth-rebase branch from 5abe0b0 to a774485 Compare May 8, 2026 21:17
sampsyo added 7 commits May 12, 2026 10:48
Instead of creating a file with a hard-coded name, we now just print the
BED table to stdout. To put this in a file, use stream redirection, like
`fgfa -I foo.gfa bed-depth 5 > foo.bed`.
Because this seems to be an end-to-end operation, let's avoid taking in
a `Vec` parameter that we don't actually use.
Collapse the `windows` and `beddepth` modules into a single
`window_depth` module, which is where we do everything relevant to this
command. I have also renamed stuff to `window-depth` instead of
`bed-depth` because I think this better describes what we're doing here,
in terms of the end-to-end purpose.

This also removes the "example" program I added in #252 because this
fully supersedes it.
Try to explain how all this works, and simplify some of the Rust in the
process.
You now pass the name of a path on the command line, and we produce that
path's name in the BED output (which I think is how the odgi script
works as well).
Turns out that odgi uses different digit counts for different commands.
So we now can actually match odgi for this window-depth workload.
@sampsyo
sampsyo force-pushed the beddepth-rebase branch from c9de0f0 to c3c1ea4 Compare May 12, 2026 15:51
@sampsyo

sampsyo commented May 12, 2026

Copy link
Copy Markdown
Collaborator Author

I've done some commenting and some light organizations cleanup. The main interesting changes are in 2d7c87c, which @johnpalsberg may want to review.

Here are the results from a little performance experiment (on my M1 Max MBP). I used this shell script for the odgi path:

odgi depth -i chr8.pan.og -r chm13#chr8 | \
    bedtools makewindows -b /dev/stdin -w 5000 > chm13.chr8.w5kbps.bed
odgi depth -i chr8.pan.og -b chm13.chr8.w5kbps.bed --threads 2 | \
    bedtools sort

And ran this hyperfine experiment:

hyperfine -w1 -r3 \
    'sh odgi_wdepth.sh > odgi_result.bed' \
    'fgfa -i chr8.flatgfa window-depth "chm13#chr8" 5000 > fgfa_result.bed'

Here are the results:

Benchmark 1: sh odgi_wdepth.sh > odgi_result.bed
  Time (mean ± σ):     14.859 s ±  0.172 s    [User: 13.936 s, System: 2.910 s]
  Range (min … max):   14.754 s … 15.057 s    3 runs

  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.

Benchmark 2: fgfa -i chr8.flatgfa window-depth "chm13#chr8" 5000 > fgfa_result.bed
  Time (mean ± σ):     997.1 ms ±   4.6 ms    [User: 855.3 ms, System: 138.6 ms]
  Range (min … max):   994.0 ms … 1002.3 ms    3 runs

Summary
  fgfa -i chr8.flatgfa window-depth "chm13#chr8" 5000 > fgfa_result.bed ran
   14.90 ± 0.19 times faster than sh odgi_wdepth.sh > odgi_result.bed

So 15x faster. Not bad!

The outputs are pretty close but don't match precisely, for either FP precision or printing issues:

$ diff fgfa_result.bed odgi_result.bed | head -n20
157c157
< chm13#chr8    780000  785000  118.8092
---
> chm13#chr8    780000  785000  118.809
418,419c418,419
< chm13#chr8    2085000 2090000 162.7084
< chm13#chr8    2090000 2095000 115.2992
---
> chm13#chr8    2085000 2090000 162.708
> chm13#chr8    2090000 2095000 115.299
428c428
< chm13#chr8    2135000 2140000 150.6682
---
> chm13#chr8    2135000 2140000 150.668
1346,1352c1346,1352
< chm13#chr8    6725000 6730000 289.3844
< chm13#chr8    6730000 6735000 314.8238
< chm13#chr8    6735000 6740000 292.9254
< chm13#chr8    6740000 6745000 261.7718
< chm13#chr8    6745000 6750000 308.4298

@sampsyo
sampsyo merged commit 7a52dc0 into main May 12, 2026
14 checks passed
@sampsyo
sampsyo deleted the beddepth-rebase branch May 12, 2026 15:58
This was referenced May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants