Skip to content

Commit

Permalink
Merge pull request #26 from EcoJulia/feature/vernacular
Browse files Browse the repository at this point in the history
✨ vernacular names
  • Loading branch information
tpoisot authored Dec 14, 2020
2 parents d4aa1c0 + c0f0037 commit 0859f41
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
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.0.5"
version = "0.0.6"

[deps]
Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45"
Expand Down
8 changes: 8 additions & 0 deletions docs/src/namefinding.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

```@docs
taxid
vernacular
```

The `taxid` function will return a `NCBITaxon` object, which has two fields:
Expand All @@ -28,6 +29,13 @@ the *scientific name* will be returned, no matter what you search
taxid("cow")
```

This may be a good point to note that we can use the `vernacular` function to
get a list of NCBI-known vernacular names:

```@example taxid
taxid("cow") |> vernacular
```

You can pass an additional `fuzzy=true` keyword argument to the `taxid` function
to perform fuzzy name matching using the Levenshtein distance:

Expand Down
3 changes: 3 additions & 0 deletions src/NCBITaxonomy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,7 @@ export children, descendants
include("lineage.jl")
export lineage, parent, rank

include("vernacular.jl")
export vernacular

end
15 changes: 15 additions & 0 deletions src/vernacular.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
vernacular(t::NCBITaxon)
This function will return `nothing` if no vernacular name is known, and an array
of names if found. It searches the "common name" and "genbank common name"
category of the NCBI taxonomy name table.
"""
function vernacular(t::NCBITaxon)
names_from_tax = filter(r -> r.tax_id == t.id, NCBITaxonomy.names_table)
common_names = filter(r -> r.class == NCBITaxonomy.class_common_name, names_from_tax)
genbank_names = filter(r -> r.class == NCBITaxonomy.class_genbank_common_name, names_from_tax)
all_names = vcat(common_names.name, genbank_names.name)
length(all_names) == 0 && return nothing
return unique(all_names)
end
8 changes: 8 additions & 0 deletions test/taxid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,12 @@ module TestTaxid
chicken = taxid("tchiken"; fuzzy=true, verbose=true)
@test typeof(chicken) == NCBITaxon

#Vernacular name
chub = vernacular(ncbi"Leuciscus cephalus")
@test "European chub" in chub
@test "chub" in chub

# Vernacular missing
@test isnothing(vernacular(ncbi"Lamellodiscus elegans"))

end

2 comments on commit 0859f41

@tpoisot
Copy link
Member Author

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/26366

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.0.6 -m "<description of version>" 0859f415ae9ec704e2061fe1c3d7f15928e323dd
git push origin v0.0.6

Please sign in to comment.