-
Notifications
You must be signed in to change notification settings - Fork 25
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
Add dunder methods to the Python Record
class
#91
base: master
Are you sure you want to change the base?
Conversation
Record
classRecord
class
@apcamargo thank you very much! I left some comments. Otherwise, these changes look like great additions to the library and we'd be happy to merge them in. |
Thanks for the review, @audy! I just pushed commits that address all your comments. I prefer wrapping since that's how other libraries/tools format FASTAs, and I think users expect it. That said, I’m not too attached to it :) |
@apcamargo thanks for making those changes. Let me know if you're good to merge. |
@audy I’ve added docstrings to all classes, methods, and functions. The only potential change I’d consider is adding a default value to the |
@audy I also updated |
@apcamargo Awesome! Do you mind adding some tests?
I support this change but I'm not sure if it should default to |
Apologies, @audy! I had forgotten about the tests. I've now added tests for all the new functions and methods, and set the default value of |
This PR introduces several dunder methods to the Python
Record
class:__new__
: Constructor that allows the direct creation ofRecord
objects:__hash__
: Returns an integer hash based on the record's ID, sequence, and quality (if available). This overrides the default__hash__
, which generates different hashes for identical objects.__eq__
: Compares twoRecord
objects by checking if their IDs, sequences, and qualities (if available) are identical. While we could check for equality based on hashes, this would involve additional computation.__len__
: Returns the length of the sequence, similar to BioPython's behavior.__str__
: Returns a string formatted in FASTA/FASTQ style to facilitate writing FASTX files. Currently, sequences are wrapped at 60 characters for FASTA records, though the wrapping can be adjusted.__repr__
: Provides a simple string representation that includes the record ID, a sequence snippet, and the quality string (when available):Additionally, is_fasta and is_fastq have been converted to properties.
Test coverage for these methods has not been added yet, but I will implement it if this PR is approved.