Skip to content

feat: popgen-htslib crate - #216

Merged
molpopgen merged 1 commit into
mainfrom
htslib_adapter
Oct 5, 2026
Merged

molpopgen merged 1 commit into
mainfrom
htslib_adapter

Conversation

@molpopgen

Copy link
Copy Markdown
Member

No description provided.

@molpopgen

Copy link
Copy Markdown
Member Author

@laggycomputer -- it has struck me that we don't need to return a Vec for the "record adapter". We could instead return an opaque type that implements Iterator<Item = Option>. I bet we could get the lifetimes worked out?

@molpopgen
molpopgen marked this pull request as ready for review October 2, 2026 21:38
@laggycomputer

Copy link
Copy Markdown
Collaborator

I'll look at the iterator later today.

@molpopgen

Copy link
Copy Markdown
Member Author

I can take a crack at it on Monday. Getting tests to work via tempfiles to make the htstlib readers happy fried my Friday brain.

@laggycomputer

Copy link
Copy Markdown
Collaborator

misisng_docs is now failing, but no rush.

@molpopgen

Copy link
Copy Markdown
Member Author

yeah -- I want to totally replace the allocating implementation with one based on Iterator.

@molpopgen

Copy link
Copy Markdown
Member Author

oh boy -- existing tests were also passing even though there was a bug in the crate code!

@molpopgen

Copy link
Copy Markdown
Member Author

I hit a road block on the iterator business. There's a lot of borrowing and flattening that would have to happen. Internally, htslib is allocating into Vec at various points but not providing IntoIter impls. It made for a bit of a nightmare.

@molpopgen

Copy link
Copy Markdown
Member Author

hmmm -- there is probably some way to get it to go by holding another internal index and using .skip(i).take(1) to get specific alleles. I'd have to study the htslib internals a bit more closely to see if that would be O(1) or not.

@molpopgen
molpopgen marked this pull request as draft October 4, 2026 14:34
@molpopgen
molpopgen marked this pull request as ready for review October 5, 2026 15:20
@molpopgen

Copy link
Copy Markdown
Member Author

@laggycomputer -- there are a handful of issues here

  1. SAFETY docs are missing/incomplete
  2. We need to convert panic to Err
  3. This code is hairy enough to warrant two functions. One function that returns an iterator over sample genotypes. And some "sample genotype" type that itself creates an iterator over the optional allele IDs. Then the current fn is just a flat mapping over the genotypes iterator. Normally I'd call the second function syntax sugar that shouldn't be in the lib, but I think dealing with unsafe, C, and bit shifts means that sugar functions actually pull their weight here.

@molpopgen

Copy link
Copy Markdown
Member Author

(The reason a genotypes iter is a good thing is that combining it with enumerate gives downstream code a way to break input into sample sets.)

Comment thread popgen-htslib/src/lib.rs Outdated
Comment thread popgen-htslib/src/lib.rs Outdated

@laggycomputer laggycomputer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want a note here for why we're not using safe Rust-level htslib

Comment thread popgen-htslib/src/lib.rs Outdated
@molpopgen
molpopgen merged commit daf9438 into main Oct 5, 2026
8 of 9 checks passed
@molpopgen
molpopgen deleted the htslib_adapter branch October 5, 2026 21:23
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