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

support multithreading #38

Merged
merged 2 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/Manifest.toml
/docs/build/
/db
/test/db
/test/taxdump.tar.gz
/.vscode
3 changes: 3 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ version = "0.4.2"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193"
DataAPI = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
StringDistances = "88034a9c-02f8-509d-84a9-84ec65e18404"
Tar = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"

[compat]
AbstractTrees = "0.4.3"
Expand Down
25 changes: 12 additions & 13 deletions src/database.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,20 @@ function importnodes(nodes_dmp_path::String; db_size::Int=default_db_size)
ranks = Vector{Symbol}(undef, db_size)

c = 0
f = open(nodes_dmp_path, "r")
@inbounds(for line in eachline(f)
cols = split(line, "\t", limit=6)
cols[1] == cols[3] && continue
open(nodes_dmp_path, "r") do f
for line in eachline(f)
cols = split(line, "\t", limit=6)

taxid = parse(Int, cols[1])
parent = parse(Int, cols[3])
rank = Symbol(cols[5])
taxid = parse(Int, cols[1])
parent = parse(Int, cols[3])
rank = Symbol(cols[5])

c += 1
taxids[c] = taxid
parents[c] = parent
ranks[c] = rank
end)
close(f)
c += 1
@inbounds taxids[c] = taxid
@inbounds parents[c] = parent
@inbounds ranks[c] = rank
end
end
resize!(taxids, c)
resize!(parents, c)
resize!(ranks, c)
Expand Down
2 changes: 1 addition & 1 deletion src/taxon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Return the `Taxon` object that is the parent of the given `Taxon` object.
"""
function AbstractTrees.parent(taxon::Taxon)
parent_taxid = get(taxon.db.parents, taxon.taxid, nothing)
if parent_taxid === nothing
if parent_taxid == taxon.taxid
return nothing
end
parent = Taxon(parent_taxid, taxon.db)
Expand Down
55 changes: 0 additions & 55 deletions test/db/names.dmp

This file was deleted.

51 changes: 0 additions & 51 deletions test/db/nodes.dmp

This file was deleted.

48 changes: 0 additions & 48 deletions test/db_1/names.dmp

This file was deleted.

44 changes: 0 additions & 44 deletions test/db_1/nodes.dmp

This file was deleted.

17 changes: 13 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
using Taxonomy
using Taxonomy.AbstractTrees
using Downloads
using Tar
using CodecZlib
using Test

if !isdir("./db")
Downloads.download("ftp://ftp.ncbi.nlm.nih.gov/pub/taxonomy/taxdump.tar.gz", "./taxdump.tar.gz")
tar_gz = open("./taxdump.tar.gz")
tar = GzipDecompressorStream(tar_gz)
Tar.extract(tar, "./db")
close(tar)
else
@warn "Start test with existing database"
end

@testset "dabase.jl" begin
@test isnothing(current_db())

db = Taxonomy.DB("db/nodes.dmp", "db/names.dmp")
@test current_db() == db

db_1 = Taxonomy.DB("db_1/nodes.dmp", "db_1/names.dmp")
current_db!(db_1)
@test current_db() == db_1
end

db = Taxonomy.DB("db/nodes.dmp", "db/names.dmp")
Expand Down