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

Precompute name2taxids dictionary #43

Open
anton083 opened this issue Feb 15, 2024 · 1 comment
Open

Precompute name2taxids dictionary #43

anton083 opened this issue Feb 15, 2024 · 1 comment

Comments

@anton083
Copy link

anton083 commented Feb 15, 2024

Howdy!

I want to start by saying that I've found this package to be very convenient and useful!
My only issue is the time complexity of the name2taxids function. It does a linear search through the db.names dictionary (of type Dict{Int, String}), cumulating all IDs that match the name, which will be slow for larger datasets.
I found that you can essentially invert the db.names dictionary to get a name => taxids dictionary (of type Dict{String, Vector{Int}}), but it can take a couple of seconds to create. Although this far outweighs the minutes or even hours that might be spent on doing linear searches for every query one might have.
I reckon something along the lines of a function for creating such a dictionary would be nice to have. It's rather trivial to do manually, but requires accessing stuff that are not user-facing.

This is what I've been doing:

name_to_taxids = Dict{String, Vector{Int}}()
for (taxid, name) in db.names
    push!(get!(name_to_taxids, name, Int[]), taxid)
end

Cheers!

@banhbio
Copy link
Owner

banhbio commented Feb 15, 2024

Thank you for the kind comment and valuable feedback!
I indeed thought that the name2taxids function could be improved, and I think your ideas are very good.
Currently, I am very busy and don't seem to have even a little time to devote to development. However, I definitely want to improve on this point.
Of course, opinions on more detailed implementations or PRs are welcome!

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

No branches or pull requests

2 participants