feat: Expose bcf_hdr_remove via remove_header#323
feat: Expose bcf_hdr_remove via remove_header#323fxwiegand wants to merge 2 commits intobrentp:mainfrom
Conversation
Summary of ChangesHello @fxwiegand, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a significant enhancement to the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new remove_header method to the VCF class, exposing the bcf_hdr_remove function from htslib. This is a useful addition for manipulating VCF headers. The implementation looks correct, and it's great that you've included a test for the new functionality. I have one suggestion to make the test more comprehensive by covering all header types that remove_header is designed to handle (INFO, FORMAT, and FILTER). This will increase confidence in the new feature.
| def test_bcf_hdr_remove(): | ||
| """Test that remove_header works to remove INFO and FORMAT fields from header""" | ||
| v = VCF(VCF_PATH) | ||
| v.add_info_to_header({'ID': 'TESTINFO', 'Description': 'Test INFO field', | ||
| 'Type': 'String', 'Number': '1'}) | ||
|
|
||
| assert v.get_header_type("TESTINFO") | ||
|
|
||
| v.remove_header('TESTINFO') | ||
| with pytest.raises(KeyError): | ||
| v.get_header_type('TESTINFO') |
There was a problem hiding this comment.
The added test is a great start and covers the removal of an INFO field. To make the test more robust, I suggest expanding it to also cover the removal of FORMAT and FILTER fields, as remove_header supports these types as well. This will ensure all aspects of the new function are tested.
def test_bcf_hdr_remove():
"""Test that remove_header works to remove INFO, FORMAT and FILTER fields from header"""
# Test INFO
v = VCF(VCF_PATH)
v.add_info_to_header({'ID': 'TESTINFO', 'Description': 'Test INFO field',
'Type': 'String', 'Number': '1'})
assert v.get_header_type("TESTINFO")
v.remove_header('TESTINFO')
with pytest.raises(KeyError):
v.get_header_type('TESTINFO')
v.close()
# Test FORMAT
v = VCF(VCF_PATH)
v.add_format_to_header({'ID': 'TESTFORMAT', 'Description': 'Test FORMAT field',
'Type': 'String', 'Number': '1'})
assert v.get_header_type("TESTFORMAT")
v.remove_header('TESTFORMAT')
with pytest.raises(KeyError):
v.get_header_type('TESTFORMAT')
v.close()
# Test FILTER
v = VCF(VCF_PATH)
v.add_filter_to_header({'ID': 'TESTFILTER', 'Description': 'Test FILTER field'})
def filter_exists(vcf, flt_id):
for h in vcf.header_iter():
if h.type == 'FILTER' and h.info().get('ID') == flt_id:
return True
return False
assert filter_exists(v, 'TESTFILTER')
v.remove_header('TESTFILTER')
assert not filter_exists(v, 'TESTFILTER')
v.close()
We are trying to modify some headers in a project of ours and would love to keep using cyvcf2 for that. I hope this fixes #237 and allows removing and then re-adding a header record.
I have tried to make the new
remove_headerfunction as similar toget_header_typeand the newly added test runs fine on my machine so i can at least say it works. Still, would appreciate a careful look to make sure I didn't screw up somewhere.