diff --git a/Project.toml b/Project.toml index afdd2f4..63d4dac 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "NCBITaxonomy" uuid = "f88b31d2-eb98-4433-b52d-2dd32bc6efce" authors = ["Timothée Poisot "] -version = "0.4.0" +version = "0.4.1" [deps] AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c" diff --git a/benchmark/benchmarks.jl b/benchmark/benchmarks.jl index ed554d6..de3be02 100644 --- a/benchmark/benchmarks.jl +++ b/benchmark/benchmarks.jl @@ -2,6 +2,17 @@ using BenchmarkTools using NCBITaxonomy using AbstractTrees +# Setup +tax = [ + ncbi"Lamellodiscus", + ncbi"Dactylogyrus", + ncbi"Paradiplozoon", + ncbi"Diplectanum", + ncbi"Echinoplectanum", +] + +mf = mammalfilter() + const SUITE = BenchmarkGroup() # Construction of name finders @@ -14,9 +25,6 @@ SUITE["name finders"]["mammals (inclusive)"] = @benchmarkable mammalfilter(true) SUITE["name finders"]["phage"] = @benchmarkable phagefilter() -# Prepare a mammal filter next -mf = mammalfilter() - # Ability to locate taxa SUITE["taxon search"] = BenchmarkGroup(["namefinding", "search"]) @@ -49,10 +57,16 @@ SUITE["traversal"]["lineage"] = @benchmarkable lineage(ncbi"Lamellodiscus ignora SUITE["traversal"]["common ancestor (pair)"] = @benchmarkable commonancestor(ncbi"Lamellodiscus", ncbi"Dactylogyrus") -SUITE["traversal"]["common ancestor (array)"] = @benchmarkable commonancestor([ - ncbi"Lamellodiscus", - ncbi"Dactylogyrus", - ncbi"Paradiplozoon", - ncbi"Diplectanum", - ncbi"Echinoplectanum", -]) +SUITE["traversal"]["common ancestor (array)"] = @benchmarkable commonancestor(tax) + +# Utility functions + +SUITE["utilities"] = BenchmarkGroup(["utilities", "quality of life"]) + +SUITE["utilities"]["distance matrix (no allocation)"] = + @benchmarkable taxonomicdistance(tax) + +D = zeros(Float64, (length(tax), length(tax))) + +SUITE["utilities"]["distance matrix (pre-allocation)"] = + @benchmarkable taxonomicdistance!(D, tax) \ No newline at end of file diff --git a/src/utility/taxonomicdistance.jl b/src/utility/taxonomicdistance.jl index b32597d..2967ca4 100644 --- a/src/utility/taxonomicdistance.jl +++ b/src/utility/taxonomicdistance.jl @@ -54,6 +54,8 @@ function taxonomicdistance!( D[i, j] = D[j, i] = minimum([get(d, s, d[:fallback]) for s in shared]) end end + l = length(tax) + D[l, l] = strict ? get(d, rank(tax[l]), d[:fallback]) : 0.0 return D end diff --git a/test/synonyms.jl b/test/synonyms.jl index f3af102..6bf6539 100644 --- a/test/synonyms.jl +++ b/test/synonyms.jl @@ -1,9 +1,12 @@ module TestSynonymsIssues - using Test - using NCBITaxonomy +using Test +using NCBITaxonomy - @test_throws NameHasMultipleMatches taxon("gorilla"; casesensitive=false) - @test isa(taxon("gorilla"; casesensitive=false, preferscientific=true), NCBITaxon) +@test_throws NameHasMultipleMatches taxon("gorilla"; casesensitive = false) +@test isa(taxon("gorilla"; casesensitive = false, preferscientific = true), NCBITaxon) + +@test authority(ncbi"Lamellodiscus kechemirae") == + "Lamellodiscus kechemirae Amine & Euzet, 2005" end \ No newline at end of file diff --git a/test/taxodistance.jl b/test/taxodistance.jl new file mode 100644 index 0000000..20d866c --- /dev/null +++ b/test/taxodistance.jl @@ -0,0 +1,19 @@ +module TestTaxoDistance +using NCBITaxonomy +using Test + +tax = [ + ncbi"Lamellodiscus", + ncbi"Dactylogyrus", + ncbi"Paradiplozoon", + ncbi"Diplectanum", + ncbi"Echinoplectanum", +] + +TD = taxonomicdistance(tax) + +ETD = Float64[1 3 4 2 2; 3 1 4 3 3; 4 4 1 4 4; 2 3 4 1 2; 2 3 4 2 1] + +@test TD == ETD + +end \ No newline at end of file