feat: add bam::flag module for easy handling of SAM/BAM flags#440
feat: add bam::flag module for easy handling of SAM/BAM flags#440rLannes wants to merge 13 commits intorust-bio:masterfrom
Conversation
src/bam/mod.rs
Outdated
| pub mod index; | ||
| pub mod pileup; | ||
| pub mod record; | ||
| pub mod sam_flag; |
There was a problem hiding this comment.
I think I would prefer this to be called simply flags, and the struct Flag instead of SamFlag.
There was a problem hiding this comment.
Thank you for your return! I changed the name of both the module and the Structure. And ran cargo fmt. (Sorry for that, it is the first time I am contributing to a rust repo).
Romain,
johanneskoester
left a comment
There was a problem hiding this comment.
Isn't the sam_flag module just a repetition of flags now? Did you mean to remove it?
Also, would it make sense to have two separate methods is_in() and is_not_in() for the Flags struct instead of check_flags?
|
Thank you for your return. 1- I am not sure what you are referring to with this: "Isn't the sam_flag module just a repetition of flags now? Did you mean to remove it?". I thought I did by changing the sam_flag module name to flags, as suggested. Is that not the case? As of the latest commit to use this module, one has to import: 2- I often have to test for both the presence and absence of a flag, but now that you mentioned it, it is clearly confusing for an API. I will split this function into two and change the doc string accordingly. Because a Flag is a struct with an associated constant, I can't write methods like Thank you for your time and suggestion! |
|
I added two functions (removed the old one) and updated the docstring accordingly. |
|
See the tab "files changed" at the top. There is still the old sam_flags.rs in this PR. |
|
Thank you for catching that, I was not aware I had to "git rm" old files to get rid of them. It should be good now. |
|
Something is wrong now. |
|
I am confused None of the linting errors have to do with the flag module. They're all about Clippy complaining about format!() in the whole code base. |
|
There are syntax errors in the code now. And further, the doc comments really should be put above the function definitions, with |
Description:
This pull request introduces a new module,
bam::sam_flag, to facilitate easier handling of SAM flags. The module provides a more intuitive and type-safe way to work with SAM flags, improving code readability and reducing potential errors.Key features:
SamFlagstruct: A zero-cost abstraction that contains constants for all standard SAM flags.check_flag()function: A utility function to easily check for the presence or absence of specific flags.Benefits:
Implementation choice:
The main design choice was to use a struct with associated constants rather than an enum to represent the flag values. The benefit is no runtime cost, but it comes at the cost of not being as nice to work with as an enum.
Example usage: