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

raise error when db is not found #40

Merged
merged 3 commits into from
Jan 29, 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
15 changes: 10 additions & 5 deletions src/database.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ function importnames(names_dmp_path::String; db_size::Int=default_db_size)

f = open(names_dmp_path, "r")
c = 0
@inbounds(for line in eachline(f)
for line in eachline(f)
cols = split(line, "\t", limit=8)
cols[7] != "scientific name" && continue

c+=1
taxids[c] = parse(Int, cols[1])
names[c] = String(cols[3])
end)
@inbounds taxids[c] = parse(Int, cols[1])
@inbounds names[c] = String(cols[3])
end
resize!(taxids, c)
resize!(names, c)
close(f)
Expand All @@ -82,7 +82,12 @@ const _current_db = Ref{Union{Nothing, DB}}(nothing)

Return the current active database or the last database that got created.
"""
current_db() = _current_db[]
function current_db()
if isnothing(_current_db[])
error("Taxonomy.DB is not found. Please run Taxonomy.DB(nodes_dmp::String, names_dmp::String) before proceeding")
end
_current_db[]
end

"""
current_db!(db::Taxonomy.DB)
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ else
end

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

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