-
Notifications
You must be signed in to change notification settings - Fork 71
feat: add rfam_searcher #177
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @ChenZiHong-Gavin, 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 new Highlights
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a new RfamSearcher class to interact with the Rfam and RNAcentral APIs. The implementation is well-structured, featuring retry logic, helper methods, and a unified search interface. My review focuses on improving code clarity, addressing a potential performance issue, suggesting a more robust resource management pattern, and removing unused code. Overall, this is a solid addition.
| # RNA molecule type mapping | ||
| RNA_TYPES = { | ||
| "Gene": "gene", | ||
| "snRNA": "snrna", | ||
| "snoRNA": "snorna", | ||
| "rRNA": "rrna", | ||
| "tRNA": "trna", | ||
| "miRNA": "mirna", | ||
| "ribozyme": "ribozyme", | ||
| "riboswitch": "riboswitch", | ||
| } |
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.
| rna_type = ( | ||
| types[-1] | ||
| if types[-1] != "CD-box" | ||
| else types[-2] | ||
| if len(types) > 1 | ||
| else types[0] | ||
| ) |
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 nested ternary expression for determining rna_type is difficult to read and maintain. Refactoring this into a more explicit if/elif/else block would improve readability.
| rna_type = ( | |
| types[-1] | |
| if types[-1] != "CD-box" | |
| else types[-2] | |
| if len(types) > 1 | |
| else types[0] | |
| ) | |
| if types[-1] != "CD-box": | |
| rna_type = types[-1] | |
| elif len(types) > 1: | |
| rna_type = types[-2] | |
| else: | |
| # Fallback to the first type if it's the only one (even if 'CD-box') | |
| rna_type = types[0] | |
| for entry in result["entries"]: | ||
| accession = entry.get("fields", {}).get("accession", [None])[0] | ||
| if accession: | ||
| family = self.get_by_accession(accession) | ||
| if family: | ||
| families.append(family) |
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.
This loop makes a separate API call to get_by_accession for each search result. If the search returns many items (e.g., limit=10), this will result in 11 API calls (1 search + 10 get_by_accession), which can be slow and may lead to hitting API rate limits. This is a form of the N+1 query problem.
Consider returning a summarized version of the families using only the information from the initial EBI search to improve performance. If full details are necessary, this behavior should be documented in the method's docstring to make users aware of the performance implications.
| def __del__(self): | ||
| """Cleanup session.""" | ||
| if hasattr(self, "session"): | ||
| self.session.close() |
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.
Using __del__ for resource cleanup (like closing a requests.Session) is not reliable in Python, as its execution is not guaranteed. A more robust and idiomatic approach is to implement the class as a context manager. This ensures that resources are cleaned up properly when the object is used within a with statement.
You can achieve this by adding __enter__ and __exit__ methods and removing __del__.
Example:
def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self.session.close()This would allow for usage like with RfamSearcher() as searcher: ....
No description provided.