Skip to content

Commit

Permalink
Additional tests on distance matrix (#56)
Browse files Browse the repository at this point in the history
* 🐛fix the taxodistance function (last taxa self-distance was 0)

* ✅ taxonomicdistance

* ⚡ taxonomicdistance benchmark

* ✅ authority

* 🩹 v0.4.1
  • Loading branch information
tpoisot authored Mar 4, 2023
1 parent 0c277cd commit f5a999a
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "NCBITaxonomy"
uuid = "f88b31d2-eb98-4433-b52d-2dd32bc6efce"
authors = ["Timothée Poisot <[email protected]>"]
version = "0.4.0"
version = "0.4.1"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down
34 changes: 24 additions & 10 deletions benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"])
Expand Down Expand Up @@ -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)
2 changes: 2 additions & 0 deletions src/utility/taxonomicdistance.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 7 additions & 4 deletions test/synonyms.jl
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions test/taxodistance.jl
Original file line number Diff line number Diff line change
@@ -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

2 comments on commit f5a999a

@tpoisot
Copy link
Member Author

@tpoisot tpoisot commented on f5a999a Mar 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/78938

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.1 -m "<description of version>" f5a999af2f191d11d206b377e81bd65d97c1c75c
git push origin v0.4.1

Please sign in to comment.