Skip to content
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

Make repeated seeks possible #1363

Merged
merged 1 commit into from
Jan 4, 2022
Merged

Make repeated seeks possible #1363

merged 1 commit into from
Jan 4, 2022

Conversation

pd3
Copy link
Member

@pd3 pd3 commented Dec 9, 2021

Repeated seeks with implicitly created region list wouldn't initialize all internal structures to the original clean state, as demonstrated by the issue #1362, resolved by this commit

@pd3 pd3 mentioned this pull request Dec 9, 2021
@daviesrob daviesrob self-assigned this Dec 14, 2021
@daviesrob
Copy link
Member

This fixes the reported seeking bug, but I'm worried that it might have odd interactions with the missed_reg_handler callback should anyone use it. Admittedly it doesn't seem to have been used since bcftools commit 8457b56 , but it would be good to ensure that it behaves correctly. As far as I can tell, it would be best to not call missed_reg_handler at all when using bcf_sr_seek()?

@pd3
Copy link
Member Author

pd3 commented Dec 16, 2021

I just force-pushed a fix to that, now also missed_reg_handler should do its job when bcf_sr_seek() is used

@daviesrob
Copy link
Member

I thought of that as a fix, but I'm not sure if it's enough as while it stops missed_reg_handler getting called on the current chromosome, it also gets called later on on the target of the seek. So I think a seek to a high-ish position could call it, depending on the ranges present?

@pd3
Copy link
Member Author

pd3 commented Dec 17, 2021

You are right. After a seek it will now behave as if this was the first region at the chromosome and will trigger the callback. I don't know what the right behavior should be. Since it is not used anymore, maybe we just let be for now and wait until a real world use case comes?

@daviesrob
Copy link
Member

I'd be inclined to just disable it for the bcf_sr_seek() case. The cleanest way might be to rename bcf_sr_regions_overlap(), make it static and add an extra parameter to disable the callbacks. Then make a new bcf_sr_regions_overlap() which calls the new function with callbacks enabled so the current API is unchanged.

@pd3
Copy link
Member Author

pd3 commented Dec 17, 2021

Or just call assert from bcf_sr_seek() if the callback is set, with appropriate comment added in the code

@daviesrob
Copy link
Member

No, calling assert() would not be appropriate.

@pd3
Copy link
Member Author

pd3 commented Dec 20, 2021

No, calling assert() would not be appropriate.

I don't understand. The current code is broken, therefore keeping the current behavior should not be appropriate. Trying to use the code with missed_reg_handler will likely cause unexpected behavior and this is in the programming space, not user space. In my view assert and/or API documentation is the right place.

@daviesrob
Copy link
Member

Compiling the library with NDEBUG defined will make any assert() calls go away. It should therefore only be used to detect bugs inside HTSlib itself, and is not a reliable mechanism to report API misuse.

Repeated seeks with implicitly created region list wouldn't initialize
all internal structures to the original clean state, as demonstrated by
the issue samtools#1362, resolved by this commit
@pd3
Copy link
Member Author

pd3 commented Jan 4, 2022

Okay, I modified it using a wrapper around a static function.

@daviesrob
Copy link
Member

Looks OK now, thanks.

@daviesrob daviesrob merged commit dc8a631 into samtools:develop Jan 4, 2022
@pd3 pd3 deleted the issue-1362 branch February 28, 2023 13:39
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