Skip to content

Commit

Permalink
Merge pull request #40 from banhbio/dev
Browse files Browse the repository at this point in the history
raise error when db is not found
  • Loading branch information
banhbio committed Jan 29, 2023
2 parents 50db42e + 93c5f10 commit 429e9a5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
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

0 comments on commit 429e9a5

Please sign in to comment.