Skip to content
This repository has been archived by the owner on Dec 11, 2022. It is now read-only.

Taxon patch #20

Merged
merged 6 commits into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
Changes from 5 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
5 changes: 5 additions & 0 deletions .zenodo.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
"affiliation": "University of Copenhagen",
"name": "Borregaard, Michael",
"orcid": "0000-0002-8146-8435"
},
{
"affiliation": "Ghent University",
"name": "Stock, Michiel",
"orcid": "0000-0003-0903-6061"
}
],
"access_right": "open",
Expand Down
24 changes: 24 additions & 0 deletions src/taxon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,27 @@ function taxon(name::String;
end

end

"""
**Get information about a taxon at any level using taxonID**

taxon(id::Int)

This function will look for a taxon by its taxonID in the GBIF
reference taxonomy.
"""
function taxon(id::Int)
args = Dict{String, Any}("id" => id)

sp_s_url = gbifurl * "species/$id"
sp_s_req = HTTP.get(sp_s_url, query=args)
if sp_s_req.status == 200
body = JSON.parse(String(sp_s_req.body))
return GBIFTaxon(body)
else
throw(ErrorException("Impossible to retrieve information for taxonID $(id) -- HTML error code $(sp_s_req.status)"))
end

end

taxon(t::Pair) = taxon(t.second)
8 changes: 4 additions & 4 deletions src/types/GBIFTaxon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct GBIFTaxon
family::Union{Missing, Pair{String, Int64}}
genus::Union{Missing, Pair{String, Int64}}
species::Union{Missing, Pair{String, Int64}}
confidence::Int64
confidence::Union{Missing, Int64}
synonym::Bool
end

Expand All @@ -59,16 +59,16 @@ function GBIFTaxon(o::Dict{String, Any})
return GBIFTaxon(
o["canonicalName"],
o["scientificName"],
Symbol(o["status"]),
Symbol(o["matchType"]),
Symbol(get(o, "status", "none")), # returns :none as default
MichielStock marked this conversation as resolved.
Show resolved Hide resolved
Symbol(get(o, "matchType", "none")),
r["kingdom"],
r["phylum"],
r["class"],
r["order"],
r["family"],
r["genus"],
r["species"],
o["confidence"],
get(o, "confidence", missing),
o["synonym"]
)
end
5 changes: 5 additions & 0 deletions test/taxon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ module TestSpecies
iver = taxon("Iris versicolor", rank=:SPECIES)
@test iver.species == Pair("Iris versicolor", 5298019)

iver_id = taxon(5298019) # test using taxon id
@test iver_id.species == iver.species

@test iver_id == taxon(Pair("Iris versicolor", 5298019))

i_sp = taxon(iver.genus.first; rank=:GENUS, family=iver.family.first, strict=false)
@test ismissing(i_sp.species)

Expand Down