-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: bam::Record:new should return a valid record #361
Conversation
@jch-13 would you mind approving running the workfllow? |
CI run approved |
All tests passing! |
Pull Request Test Coverage Report for Build 2520638230
💛 - Coveralls |
I'm not the best to review this, but can a test be added to cover the issue this solves? |
record.set_tid(-1); | ||
record.set_pos(-1); | ||
record.set_mpos(-1); | ||
record.set_mtid(-1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would argue that we should also set the record to be unmapped by default. I mean, how can it be mapped if the tid/pos are -1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable but I'd quickly compare third party implementations (htslib/htsjdk/noodles) and/or spec footnotes (lots of gotchas there).
@dcroote who is a good person to tag for review? |
Happy to help you out Nils! Please fix the no-default-features compile errors and the clippy warnings, the fix looks good. |
}; | ||
// The read/query name needs to be set as empty to properly initialize | ||
// the record | ||
record.set_qname(b""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the writer would not write the record unless the query name is set to something (empty is ok)
@@ -113,12 +113,23 @@ fn extranul_from_qname(qname: &[u8]) -> usize { | |||
impl Record { | |||
/// Create an empty BAM record. | |||
pub fn new() -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The goal in this PR is to that one does not need to call any other methods on Record
to have a valid record. Currently, this requires setting the read name and alignment positions (and unmapped flag if the positions are -1). So this PR has an opinion, that a new record is unmapped with empty name/seq/qual/cigar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for indirectly making me think about Default
trait vs new()
: https://users.rust-lang.org/t/when-to-use-default-trait/11190
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coincidental good read on Default: https://cj.rs/blog/rust-default-values-for-maintainability/
Just ran into this issue and the above work-arounds resolved it. Any chance this makes it into the default anytime soon? |
@brainstorm Took a quick peak this morning to see if I could figure out what was going on. The problem seems to be with the qname getting set and serde tests. When I comment out the
It seems like the qnames are getting 0-padded for some reason, but I'm not entirely sure why. Then those extra zeroes are triggering the mismatch in the tests. I think Nils is correct in that the qname should be set to the empty string, but it's not obvious to me what's going on with this padding or why that extra EDIT: Unrelatedly, I need to go dig into noodles again. I've been meaning to try it on a smaller project when I have time to get familiar with the difference! |
Update: I found a putative patch, but don't seem to have permission to change this PR/branch (I think this is restricted from @nh13). There's a one line addition to
The change resets extranul prior to calling qname, allowing it to get the correct full block with padding and then shrink it back down. |
@holtjma this comes from my fork, do you want to make a PR to my branch or would you recommend something else? |
I was trying to avoid the extra PR since it’s a one-line change, but I can do that tomorrow if it’s preferred. |
@holtjma I think I did the right thing |
See #339.