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

Random access to a sequence file #85

Open
arajkovic opened this issue Mar 13, 2025 · 1 comment
Open

Random access to a sequence file #85

arajkovic opened this issue Mar 13, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@arajkovic
Copy link
Contributor

Hi,
Is it possible to retrieve a random sequence from a sequence file which has been previously indexed?
I'm looking at the SequenceFile class and it seems that is only possible to fetch them into a SequenceBlock sequentially. Am I correct?
Basically I'm looking for any feature of pyhmmer that allows me to fetch sequences like esl-sfetch.
Thanks!

@arajkovic
Copy link
Contributor Author

With a fresh brain I've been able to figure it out. One can utilise the SSIReader class like this

from pyhmmer.easel import SSIReader

with SSIReader(
    "/path/to/hmmpgmd.ssi"
) as ssi, open(
    "/path/to/hmmpgmd", mode="rt"
) as fh:
    sequence_key = "1"
    entry = ssi.find_name(sequence_key.encode())
    fh.seek(entry.data_offset)
    sequence = fh.read(entry.record_length)

A nice thing to have (although no errors are thrown) is to have functions find_name and file_info exposed in easel.pyi.

@althonos althonos added the enhancement New feature or request label Mar 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants